]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9-3.3.5-201205091803.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.3.5-201205091803.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 64615e9..64d72ce 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,55 @@ 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 +ifndef CONFIG_UML
232 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
233 +endif
234 +endif
235 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
236 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
237 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
238 +endif
239 +ifdef CONFIG_KALLOCSTAT_PLUGIN
240 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
241 +endif
242 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
243 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
244 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
245 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
246 +endif
247 +ifdef CONFIG_CHECKER_PLUGIN
248 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
249 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
250 +endif
251 +endif
252 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
253 +ifdef CONFIG_PAX_SIZE_OVERFLOW
254 +SIZE_OVERFLOW_PLUGIN := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
255 +endif
256 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
257 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS) $(SIZE_OVERFLOW_PLUGIN)
258 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
259 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN SIZE_OVERFLOW_PLUGIN
260 +ifeq ($(KBUILD_EXTMOD),)
261 +gcc-plugins:
262 + $(Q)$(MAKE) $(build)=tools/gcc
263 +else
264 +gcc-plugins: ;
265 +endif
266 +else
267 +gcc-plugins:
268 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
269 + $(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.))
270 +else
271 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
272 +endif
273 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
274 +endif
275 +endif
276 +
277 include $(srctree)/arch/$(SRCARCH)/Makefile
278
279 ifneq ($(CONFIG_FRAME_WARN),0)
280 @@ -708,7 +758,7 @@ export mod_strip_cmd
281
282
283 ifeq ($(KBUILD_EXTMOD),)
284 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
285 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
286
287 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
288 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
289 @@ -932,6 +982,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
290
291 # The actual objects are generated when descending,
292 # make sure no implicit rule kicks in
293 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
294 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
295 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
296
297 # Handle descending into subdirectories listed in $(vmlinux-dirs)
298 @@ -941,7 +993,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
299 # Error messages still appears in the original language
300
301 PHONY += $(vmlinux-dirs)
302 -$(vmlinux-dirs): prepare scripts
303 +$(vmlinux-dirs): gcc-plugins prepare scripts
304 $(Q)$(MAKE) $(build)=$@
305
306 # Store (new) KERNELRELASE string in include/config/kernel.release
307 @@ -985,6 +1037,7 @@ prepare0: archprepare FORCE
308 $(Q)$(MAKE) $(build)=.
309
310 # All the preparing..
311 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
312 prepare: prepare0
313
314 # Generate some files
315 @@ -1089,6 +1142,8 @@ all: modules
316 # using awk while concatenating to the final file.
317
318 PHONY += modules
319 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
320 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
321 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
322 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
323 @$(kecho) ' Building modules, stage 2.';
324 @@ -1104,7 +1159,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
325
326 # Target to prepare building external modules
327 PHONY += modules_prepare
328 -modules_prepare: prepare scripts
329 +modules_prepare: gcc-plugins prepare scripts
330
331 # Target to install modules
332 PHONY += modules_install
333 @@ -1201,6 +1256,7 @@ distclean: mrproper
334 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
335 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
336 -o -name '.*.rej' \
337 + -o -name '.*.rej' -o -name '*.so' \
338 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
339 -type f -print | xargs rm -f
340
341 @@ -1361,6 +1417,8 @@ PHONY += $(module-dirs) modules
342 $(module-dirs): crmodverdir $(objtree)/Module.symvers
343 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
344
345 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
346 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
347 modules: $(module-dirs)
348 @$(kecho) ' Building modules, stage 2.';
349 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
350 @@ -1487,17 +1545,21 @@ else
351 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
352 endif
353
354 -%.s: %.c prepare scripts FORCE
355 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
356 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
357 +%.s: %.c gcc-plugins prepare scripts FORCE
358 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
359 %.i: %.c prepare scripts FORCE
360 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
361 -%.o: %.c prepare scripts FORCE
362 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
363 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
364 +%.o: %.c gcc-plugins prepare scripts FORCE
365 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
366 %.lst: %.c prepare scripts FORCE
367 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
368 -%.s: %.S prepare scripts FORCE
369 +%.s: %.S gcc-plugins prepare scripts FORCE
370 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
371 -%.o: %.S prepare scripts FORCE
372 +%.o: %.S gcc-plugins prepare scripts FORCE
373 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
374 %.symtypes: %.c prepare scripts FORCE
375 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
376 @@ -1507,11 +1569,15 @@ endif
377 $(cmd_crmodverdir)
378 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
379 $(build)=$(build-dir)
380 -%/: prepare scripts FORCE
381 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
382 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
383 +%/: gcc-plugins prepare scripts FORCE
384 $(cmd_crmodverdir)
385 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
386 $(build)=$(build-dir)
387 -%.ko: prepare scripts FORCE
388 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
389 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
390 +%.ko: gcc-plugins prepare scripts FORCE
391 $(cmd_crmodverdir)
392 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
393 $(build)=$(build-dir) $(@:.ko=.o)
394 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
395 index 640f909..48b6597 100644
396 --- a/arch/alpha/include/asm/atomic.h
397 +++ b/arch/alpha/include/asm/atomic.h
398 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
399 #define atomic_dec(v) atomic_sub(1,(v))
400 #define atomic64_dec(v) atomic64_sub(1,(v))
401
402 +#define atomic64_read_unchecked(v) atomic64_read(v)
403 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
404 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
405 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
406 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
407 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
408 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
409 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
410 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
411 +
412 #define smp_mb__before_atomic_dec() smp_mb()
413 #define smp_mb__after_atomic_dec() smp_mb()
414 #define smp_mb__before_atomic_inc() smp_mb()
415 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
416 index ad368a9..fbe0f25 100644
417 --- a/arch/alpha/include/asm/cache.h
418 +++ b/arch/alpha/include/asm/cache.h
419 @@ -4,19 +4,19 @@
420 #ifndef __ARCH_ALPHA_CACHE_H
421 #define __ARCH_ALPHA_CACHE_H
422
423 +#include <linux/const.h>
424
425 /* Bytes per L1 (data) cache line. */
426 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
427 -# define L1_CACHE_BYTES 64
428 # define L1_CACHE_SHIFT 6
429 #else
430 /* Both EV4 and EV5 are write-through, read-allocate,
431 direct-mapped, physical.
432 */
433 -# define L1_CACHE_BYTES 32
434 # define L1_CACHE_SHIFT 5
435 #endif
436
437 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
438 #define SMP_CACHE_BYTES L1_CACHE_BYTES
439
440 #endif
441 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
442 index da5449e..7418343 100644
443 --- a/arch/alpha/include/asm/elf.h
444 +++ b/arch/alpha/include/asm/elf.h
445 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
446
447 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
448
449 +#ifdef CONFIG_PAX_ASLR
450 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
451 +
452 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
453 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
454 +#endif
455 +
456 /* $0 is set by ld.so to a pointer to a function which might be
457 registered using atexit. This provides a mean for the dynamic
458 linker to call DT_FINI functions for shared libraries that have
459 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
460 index bc2a0da..8ad11ee 100644
461 --- a/arch/alpha/include/asm/pgalloc.h
462 +++ b/arch/alpha/include/asm/pgalloc.h
463 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
464 pgd_set(pgd, pmd);
465 }
466
467 +static inline void
468 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
469 +{
470 + pgd_populate(mm, pgd, pmd);
471 +}
472 +
473 extern pgd_t *pgd_alloc(struct mm_struct *mm);
474
475 static inline void
476 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
477 index de98a73..bd4f1f8 100644
478 --- a/arch/alpha/include/asm/pgtable.h
479 +++ b/arch/alpha/include/asm/pgtable.h
480 @@ -101,6 +101,17 @@ struct vm_area_struct;
481 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
482 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
483 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
484 +
485 +#ifdef CONFIG_PAX_PAGEEXEC
486 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
487 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
488 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
489 +#else
490 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
491 +# define PAGE_COPY_NOEXEC PAGE_COPY
492 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
493 +#endif
494 +
495 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
496
497 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
498 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
499 index 2fd00b7..cfd5069 100644
500 --- a/arch/alpha/kernel/module.c
501 +++ b/arch/alpha/kernel/module.c
502 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
503
504 /* The small sections were sorted to the end of the segment.
505 The following should definitely cover them. */
506 - gp = (u64)me->module_core + me->core_size - 0x8000;
507 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
508 got = sechdrs[me->arch.gotsecindex].sh_addr;
509
510 for (i = 0; i < n; i++) {
511 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
512 index 01e8715..be0e80f 100644
513 --- a/arch/alpha/kernel/osf_sys.c
514 +++ b/arch/alpha/kernel/osf_sys.c
515 @@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
516 /* At this point: (!vma || addr < vma->vm_end). */
517 if (limit - len < addr)
518 return -ENOMEM;
519 - if (!vma || addr + len <= vma->vm_start)
520 + if (check_heap_stack_gap(vma, addr, len))
521 return addr;
522 addr = vma->vm_end;
523 vma = vma->vm_next;
524 @@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
525 merely specific addresses, but regions of memory -- perhaps
526 this feature should be incorporated into all ports? */
527
528 +#ifdef CONFIG_PAX_RANDMMAP
529 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
530 +#endif
531 +
532 if (addr) {
533 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
534 if (addr != (unsigned long) -ENOMEM)
535 @@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
536 }
537
538 /* Next, try allocating at TASK_UNMAPPED_BASE. */
539 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
540 - len, limit);
541 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
542 +
543 if (addr != (unsigned long) -ENOMEM)
544 return addr;
545
546 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
547 index fadd5f8..904e73a 100644
548 --- a/arch/alpha/mm/fault.c
549 +++ b/arch/alpha/mm/fault.c
550 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
551 __reload_thread(pcb);
552 }
553
554 +#ifdef CONFIG_PAX_PAGEEXEC
555 +/*
556 + * PaX: decide what to do with offenders (regs->pc = fault address)
557 + *
558 + * returns 1 when task should be killed
559 + * 2 when patched PLT trampoline was detected
560 + * 3 when unpatched PLT trampoline was detected
561 + */
562 +static int pax_handle_fetch_fault(struct pt_regs *regs)
563 +{
564 +
565 +#ifdef CONFIG_PAX_EMUPLT
566 + int err;
567 +
568 + do { /* PaX: patched PLT emulation #1 */
569 + unsigned int ldah, ldq, jmp;
570 +
571 + err = get_user(ldah, (unsigned int *)regs->pc);
572 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
573 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
574 +
575 + if (err)
576 + break;
577 +
578 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
579 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
580 + jmp == 0x6BFB0000U)
581 + {
582 + unsigned long r27, addr;
583 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
584 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
585 +
586 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
587 + err = get_user(r27, (unsigned long *)addr);
588 + if (err)
589 + break;
590 +
591 + regs->r27 = r27;
592 + regs->pc = r27;
593 + return 2;
594 + }
595 + } while (0);
596 +
597 + do { /* PaX: patched PLT emulation #2 */
598 + unsigned int ldah, lda, br;
599 +
600 + err = get_user(ldah, (unsigned int *)regs->pc);
601 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
602 + err |= get_user(br, (unsigned int *)(regs->pc+8));
603 +
604 + if (err)
605 + break;
606 +
607 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
608 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
609 + (br & 0xFFE00000U) == 0xC3E00000U)
610 + {
611 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
612 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
613 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
614 +
615 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
616 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
617 + return 2;
618 + }
619 + } while (0);
620 +
621 + do { /* PaX: unpatched PLT emulation */
622 + unsigned int br;
623 +
624 + err = get_user(br, (unsigned int *)regs->pc);
625 +
626 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
627 + unsigned int br2, ldq, nop, jmp;
628 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
629 +
630 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
631 + err = get_user(br2, (unsigned int *)addr);
632 + err |= get_user(ldq, (unsigned int *)(addr+4));
633 + err |= get_user(nop, (unsigned int *)(addr+8));
634 + err |= get_user(jmp, (unsigned int *)(addr+12));
635 + err |= get_user(resolver, (unsigned long *)(addr+16));
636 +
637 + if (err)
638 + break;
639 +
640 + if (br2 == 0xC3600000U &&
641 + ldq == 0xA77B000CU &&
642 + nop == 0x47FF041FU &&
643 + jmp == 0x6B7B0000U)
644 + {
645 + regs->r28 = regs->pc+4;
646 + regs->r27 = addr+16;
647 + regs->pc = resolver;
648 + return 3;
649 + }
650 + }
651 + } while (0);
652 +#endif
653 +
654 + return 1;
655 +}
656 +
657 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
658 +{
659 + unsigned long i;
660 +
661 + printk(KERN_ERR "PAX: bytes at PC: ");
662 + for (i = 0; i < 5; i++) {
663 + unsigned int c;
664 + if (get_user(c, (unsigned int *)pc+i))
665 + printk(KERN_CONT "???????? ");
666 + else
667 + printk(KERN_CONT "%08x ", c);
668 + }
669 + printk("\n");
670 +}
671 +#endif
672
673 /*
674 * This routine handles page faults. It determines the address,
675 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
676 good_area:
677 si_code = SEGV_ACCERR;
678 if (cause < 0) {
679 - if (!(vma->vm_flags & VM_EXEC))
680 + if (!(vma->vm_flags & VM_EXEC)) {
681 +
682 +#ifdef CONFIG_PAX_PAGEEXEC
683 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
684 + goto bad_area;
685 +
686 + up_read(&mm->mmap_sem);
687 + switch (pax_handle_fetch_fault(regs)) {
688 +
689 +#ifdef CONFIG_PAX_EMUPLT
690 + case 2:
691 + case 3:
692 + return;
693 +#endif
694 +
695 + }
696 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
697 + do_group_exit(SIGKILL);
698 +#else
699 goto bad_area;
700 +#endif
701 +
702 + }
703 } else if (!cause) {
704 /* Allow reads even for write-only mappings */
705 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
706 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
707 index 86976d0..8e07f84 100644
708 --- a/arch/arm/include/asm/atomic.h
709 +++ b/arch/arm/include/asm/atomic.h
710 @@ -15,6 +15,10 @@
711 #include <linux/types.h>
712 #include <asm/system.h>
713
714 +#ifdef CONFIG_GENERIC_ATOMIC64
715 +#include <asm-generic/atomic64.h>
716 +#endif
717 +
718 #define ATOMIC_INIT(i) { (i) }
719
720 #ifdef __KERNEL__
721 @@ -25,7 +29,15 @@
722 * atomic_set() is the clrex or dummy strex done on every exception return.
723 */
724 #define atomic_read(v) (*(volatile int *)&(v)->counter)
725 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
726 +{
727 + return v->counter;
728 +}
729 #define atomic_set(v,i) (((v)->counter) = (i))
730 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
731 +{
732 + v->counter = i;
733 +}
734
735 #if __LINUX_ARM_ARCH__ >= 6
736
737 @@ -40,6 +52,35 @@ static inline void atomic_add(int i, atomic_t *v)
738 int result;
739
740 __asm__ __volatile__("@ atomic_add\n"
741 +"1: ldrex %1, [%3]\n"
742 +" adds %0, %1, %4\n"
743 +
744 +#ifdef CONFIG_PAX_REFCOUNT
745 +" bvc 3f\n"
746 +"2: bkpt 0xf103\n"
747 +"3:\n"
748 +#endif
749 +
750 +" strex %1, %0, [%3]\n"
751 +" teq %1, #0\n"
752 +" bne 1b"
753 +
754 +#ifdef CONFIG_PAX_REFCOUNT
755 +"\n4:\n"
756 + _ASM_EXTABLE(2b, 4b)
757 +#endif
758 +
759 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
760 + : "r" (&v->counter), "Ir" (i)
761 + : "cc");
762 +}
763 +
764 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
765 +{
766 + unsigned long tmp;
767 + int result;
768 +
769 + __asm__ __volatile__("@ atomic_add_unchecked\n"
770 "1: ldrex %0, [%3]\n"
771 " add %0, %0, %4\n"
772 " strex %1, %0, [%3]\n"
773 @@ -58,6 +99,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
774 smp_mb();
775
776 __asm__ __volatile__("@ atomic_add_return\n"
777 +"1: ldrex %1, [%3]\n"
778 +" adds %0, %1, %4\n"
779 +
780 +#ifdef CONFIG_PAX_REFCOUNT
781 +" bvc 3f\n"
782 +" mov %0, %1\n"
783 +"2: bkpt 0xf103\n"
784 +"3:\n"
785 +#endif
786 +
787 +" strex %1, %0, [%3]\n"
788 +" teq %1, #0\n"
789 +" bne 1b"
790 +
791 +#ifdef CONFIG_PAX_REFCOUNT
792 +"\n4:\n"
793 + _ASM_EXTABLE(2b, 4b)
794 +#endif
795 +
796 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
797 + : "r" (&v->counter), "Ir" (i)
798 + : "cc");
799 +
800 + smp_mb();
801 +
802 + return result;
803 +}
804 +
805 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
806 +{
807 + unsigned long tmp;
808 + int result;
809 +
810 + smp_mb();
811 +
812 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
813 "1: ldrex %0, [%3]\n"
814 " add %0, %0, %4\n"
815 " strex %1, %0, [%3]\n"
816 @@ -78,6 +155,35 @@ static inline void atomic_sub(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_sub\n"
820 +"1: ldrex %1, [%3]\n"
821 +" subs %0, %1, %4\n"
822 +
823 +#ifdef CONFIG_PAX_REFCOUNT
824 +" bvc 3f\n"
825 +"2: bkpt 0xf103\n"
826 +"3:\n"
827 +#endif
828 +
829 +" strex %1, %0, [%3]\n"
830 +" teq %1, #0\n"
831 +" bne 1b"
832 +
833 +#ifdef CONFIG_PAX_REFCOUNT
834 +"\n4:\n"
835 + _ASM_EXTABLE(2b, 4b)
836 +#endif
837 +
838 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
839 + : "r" (&v->counter), "Ir" (i)
840 + : "cc");
841 +}
842 +
843 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
844 +{
845 + unsigned long tmp;
846 + int result;
847 +
848 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " sub %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852 @@ -96,11 +202,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_sub_return\n"
856 -"1: ldrex %0, [%3]\n"
857 -" sub %0, %0, %4\n"
858 +"1: ldrex %1, [%3]\n"
859 +" sub %0, %1, %4\n"
860 +
861 +#ifdef CONFIG_PAX_REFCOUNT
862 +" bvc 3f\n"
863 +" mov %0, %1\n"
864 +"2: bkpt 0xf103\n"
865 +"3:\n"
866 +#endif
867 +
868 " strex %1, %0, [%3]\n"
869 " teq %1, #0\n"
870 " bne 1b"
871 +
872 +#ifdef CONFIG_PAX_REFCOUNT
873 +"\n4:\n"
874 + _ASM_EXTABLE(2b, 4b)
875 +#endif
876 +
877 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
878 : "r" (&v->counter), "Ir" (i)
879 : "cc");
880 @@ -132,6 +252,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
881 return oldval;
882 }
883
884 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
885 +{
886 + unsigned long oldval, res;
887 +
888 + smp_mb();
889 +
890 + do {
891 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
892 + "ldrex %1, [%3]\n"
893 + "mov %0, #0\n"
894 + "teq %1, %4\n"
895 + "strexeq %0, %5, [%3]\n"
896 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
897 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
898 + : "cc");
899 + } while (res);
900 +
901 + smp_mb();
902 +
903 + return oldval;
904 +}
905 +
906 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
907 {
908 unsigned long tmp, tmp2;
909 @@ -165,7 +307,9 @@ static inline int atomic_add_return(int i, atomic_t *v)
910
911 return val;
912 }
913 +#define atomic_add_return_unchecked(i, v) atomic_add_return(i, v)
914 #define atomic_add(i, v) (void) atomic_add_return(i, v)
915 +#define atomic_add_unchecked(i, v) (void) atomic_add_return_unchecked(i, v)
916
917 static inline int atomic_sub_return(int i, atomic_t *v)
918 {
919 @@ -179,7 +323,9 @@ static inline int atomic_sub_return(int i, atomic_t *v)
920
921 return val;
922 }
923 +#define atomic_sub_return_unchecked(i, v) atomic_sub_return(i, v)
924 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
925 +#define atomic_sub_unchecked(i, v) (void) atomic_sub_return_unchecked(i, v)
926
927 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
928 {
929 @@ -194,6 +340,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
930
931 return ret;
932 }
933 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg(v, o, n)
934
935 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
936 {
937 @@ -207,6 +354,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
938 #endif /* __LINUX_ARM_ARCH__ */
939
940 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
941 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
942 +{
943 + return xchg(&v->counter, new);
944 +}
945
946 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
947 {
948 @@ -219,11 +370,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
949 }
950
951 #define atomic_inc(v) atomic_add(1, v)
952 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
953 +{
954 + atomic_add_unchecked(1, v);
955 +}
956 #define atomic_dec(v) atomic_sub(1, v)
957 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
958 +{
959 + atomic_sub_unchecked(1, v);
960 +}
961
962 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
963 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
964 +{
965 + return atomic_add_return_unchecked(1, v) == 0;
966 +}
967 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
968 #define atomic_inc_return(v) (atomic_add_return(1, v))
969 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
970 +{
971 + return atomic_add_return_unchecked(1, v);
972 +}
973 #define atomic_dec_return(v) (atomic_sub_return(1, v))
974 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
975
976 @@ -239,6 +406,14 @@ typedef struct {
977 u64 __aligned(8) counter;
978 } atomic64_t;
979
980 +#ifdef CONFIG_PAX_REFCOUNT
981 +typedef struct {
982 + u64 __aligned(8) counter;
983 +} atomic64_unchecked_t;
984 +#else
985 +typedef atomic64_t atomic64_unchecked_t;
986 +#endif
987 +
988 #define ATOMIC64_INIT(i) { (i) }
989
990 static inline u64 atomic64_read(atomic64_t *v)
991 @@ -254,6 +429,19 @@ static inline u64 atomic64_read(atomic64_t *v)
992 return result;
993 }
994
995 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
996 +{
997 + u64 result;
998 +
999 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1000 +" ldrexd %0, %H0, [%1]"
1001 + : "=&r" (result)
1002 + : "r" (&v->counter), "Qo" (v->counter)
1003 + );
1004 +
1005 + return result;
1006 +}
1007 +
1008 static inline void atomic64_set(atomic64_t *v, u64 i)
1009 {
1010 u64 tmp;
1011 @@ -268,6 +456,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1012 : "cc");
1013 }
1014
1015 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1016 +{
1017 + u64 tmp;
1018 +
1019 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1020 +"1: ldrexd %0, %H0, [%2]\n"
1021 +" strexd %0, %3, %H3, [%2]\n"
1022 +" teq %0, #0\n"
1023 +" bne 1b"
1024 + : "=&r" (tmp), "=Qo" (v->counter)
1025 + : "r" (&v->counter), "r" (i)
1026 + : "cc");
1027 +}
1028 +
1029 static inline void atomic64_add(u64 i, atomic64_t *v)
1030 {
1031 u64 result;
1032 @@ -276,6 +478,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1033 __asm__ __volatile__("@ atomic64_add\n"
1034 "1: ldrexd %0, %H0, [%3]\n"
1035 " adds %0, %0, %4\n"
1036 +" adcs %H0, %H0, %H4\n"
1037 +
1038 +#ifdef CONFIG_PAX_REFCOUNT
1039 +" bvc 3f\n"
1040 +"2: bkpt 0xf103\n"
1041 +"3:\n"
1042 +#endif
1043 +
1044 +" strexd %1, %0, %H0, [%3]\n"
1045 +" teq %1, #0\n"
1046 +" bne 1b"
1047 +
1048 +#ifdef CONFIG_PAX_REFCOUNT
1049 +"\n4:\n"
1050 + _ASM_EXTABLE(2b, 4b)
1051 +#endif
1052 +
1053 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1054 + : "r" (&v->counter), "r" (i)
1055 + : "cc");
1056 +}
1057 +
1058 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1059 +{
1060 + u64 result;
1061 + unsigned long tmp;
1062 +
1063 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1064 +"1: ldrexd %0, %H0, [%3]\n"
1065 +" adds %0, %0, %4\n"
1066 " adc %H0, %H0, %H4\n"
1067 " strexd %1, %0, %H0, [%3]\n"
1068 " teq %1, #0\n"
1069 @@ -287,12 +519,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1070
1071 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1072 {
1073 - u64 result;
1074 - unsigned long tmp;
1075 + u64 result, tmp;
1076
1077 smp_mb();
1078
1079 __asm__ __volatile__("@ atomic64_add_return\n"
1080 +"1: ldrexd %1, %H1, [%3]\n"
1081 +" adds %0, %1, %4\n"
1082 +" adcs %H0, %H1, %H4\n"
1083 +
1084 +#ifdef CONFIG_PAX_REFCOUNT
1085 +" bvc 3f\n"
1086 +" mov %0, %1\n"
1087 +" mov %H0, %H1\n"
1088 +"2: bkpt 0xf103\n"
1089 +"3:\n"
1090 +#endif
1091 +
1092 +" strexd %1, %0, %H0, [%3]\n"
1093 +" teq %1, #0\n"
1094 +" bne 1b"
1095 +
1096 +#ifdef CONFIG_PAX_REFCOUNT
1097 +"\n4:\n"
1098 + _ASM_EXTABLE(2b, 4b)
1099 +#endif
1100 +
1101 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1102 + : "r" (&v->counter), "r" (i)
1103 + : "cc");
1104 +
1105 + smp_mb();
1106 +
1107 + return result;
1108 +}
1109 +
1110 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1111 +{
1112 + u64 result;
1113 + unsigned long tmp;
1114 +
1115 + smp_mb();
1116 +
1117 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1118 "1: ldrexd %0, %H0, [%3]\n"
1119 " adds %0, %0, %4\n"
1120 " adc %H0, %H0, %H4\n"
1121 @@ -316,6 +585,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1122 __asm__ __volatile__("@ atomic64_sub\n"
1123 "1: ldrexd %0, %H0, [%3]\n"
1124 " subs %0, %0, %4\n"
1125 +" sbcs %H0, %H0, %H4\n"
1126 +
1127 +#ifdef CONFIG_PAX_REFCOUNT
1128 +" bvc 3f\n"
1129 +"2: bkpt 0xf103\n"
1130 +"3:\n"
1131 +#endif
1132 +
1133 +" strexd %1, %0, %H0, [%3]\n"
1134 +" teq %1, #0\n"
1135 +" bne 1b"
1136 +
1137 +#ifdef CONFIG_PAX_REFCOUNT
1138 +"\n4:\n"
1139 + _ASM_EXTABLE(2b, 4b)
1140 +#endif
1141 +
1142 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1143 + : "r" (&v->counter), "r" (i)
1144 + : "cc");
1145 +}
1146 +
1147 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1148 +{
1149 + u64 result;
1150 + unsigned long tmp;
1151 +
1152 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1153 +"1: ldrexd %0, %H0, [%3]\n"
1154 +" subs %0, %0, %4\n"
1155 " sbc %H0, %H0, %H4\n"
1156 " strexd %1, %0, %H0, [%3]\n"
1157 " teq %1, #0\n"
1158 @@ -327,18 +626,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1159
1160 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1161 {
1162 - u64 result;
1163 - unsigned long tmp;
1164 + u64 result, tmp;
1165
1166 smp_mb();
1167
1168 __asm__ __volatile__("@ atomic64_sub_return\n"
1169 -"1: ldrexd %0, %H0, [%3]\n"
1170 -" subs %0, %0, %4\n"
1171 -" sbc %H0, %H0, %H4\n"
1172 +"1: ldrexd %1, %H1, [%3]\n"
1173 +" subs %0, %1, %4\n"
1174 +" sbc %H0, %H1, %H4\n"
1175 +
1176 +#ifdef CONFIG_PAX_REFCOUNT
1177 +" bvc 3f\n"
1178 +" mov %0, %1\n"
1179 +" mov %H0, %H1\n"
1180 +"2: bkpt 0xf103\n"
1181 +"3:\n"
1182 +#endif
1183 +
1184 " strexd %1, %0, %H0, [%3]\n"
1185 " teq %1, #0\n"
1186 " bne 1b"
1187 +
1188 +#ifdef CONFIG_PAX_REFCOUNT
1189 +"\n4:\n"
1190 + _ASM_EXTABLE(2b, 4b)
1191 +#endif
1192 +
1193 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1194 : "r" (&v->counter), "r" (i)
1195 : "cc");
1196 @@ -372,6 +685,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1197 return oldval;
1198 }
1199
1200 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1201 +{
1202 + u64 oldval;
1203 + unsigned long res;
1204 +
1205 + smp_mb();
1206 +
1207 + do {
1208 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1209 + "ldrexd %1, %H1, [%3]\n"
1210 + "mov %0, #0\n"
1211 + "teq %1, %4\n"
1212 + "teqeq %H1, %H4\n"
1213 + "strexdeq %0, %5, %H5, [%3]"
1214 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1215 + : "r" (&ptr->counter), "r" (old), "r" (new)
1216 + : "cc");
1217 + } while (res);
1218 +
1219 + smp_mb();
1220 +
1221 + return oldval;
1222 +}
1223 +
1224 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1225 {
1226 u64 result;
1227 @@ -395,21 +732,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1228
1229 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1230 {
1231 - u64 result;
1232 - unsigned long tmp;
1233 + u64 result, tmp;
1234
1235 smp_mb();
1236
1237 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1238 -"1: ldrexd %0, %H0, [%3]\n"
1239 -" subs %0, %0, #1\n"
1240 -" sbc %H0, %H0, #0\n"
1241 +"1: ldrexd %1, %H1, [%3]\n"
1242 +" subs %0, %1, #1\n"
1243 +" sbc %H0, %H1, #0\n"
1244 +
1245 +#ifdef CONFIG_PAX_REFCOUNT
1246 +" bvc 3f\n"
1247 +" mov %0, %1\n"
1248 +" mov %H0, %H1\n"
1249 +"2: bkpt 0xf103\n"
1250 +"3:\n"
1251 +#endif
1252 +
1253 " teq %H0, #0\n"
1254 -" bmi 2f\n"
1255 +" bmi 4f\n"
1256 " strexd %1, %0, %H0, [%3]\n"
1257 " teq %1, #0\n"
1258 " bne 1b\n"
1259 -"2:"
1260 +"4:\n"
1261 +
1262 +#ifdef CONFIG_PAX_REFCOUNT
1263 + _ASM_EXTABLE(2b, 4b)
1264 +#endif
1265 +
1266 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1267 : "r" (&v->counter)
1268 : "cc");
1269 @@ -432,13 +782,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1270 " teq %0, %5\n"
1271 " teqeq %H0, %H5\n"
1272 " moveq %1, #0\n"
1273 -" beq 2f\n"
1274 +" beq 4f\n"
1275 " adds %0, %0, %6\n"
1276 " adc %H0, %H0, %H6\n"
1277 +
1278 +#ifdef CONFIG_PAX_REFCOUNT
1279 +" bvc 3f\n"
1280 +"2: bkpt 0xf103\n"
1281 +"3:\n"
1282 +#endif
1283 +
1284 " strexd %2, %0, %H0, [%4]\n"
1285 " teq %2, #0\n"
1286 " bne 1b\n"
1287 -"2:"
1288 +"4:\n"
1289 +
1290 +#ifdef CONFIG_PAX_REFCOUNT
1291 + _ASM_EXTABLE(2b, 4b)
1292 +#endif
1293 +
1294 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1295 : "r" (&v->counter), "r" (u), "r" (a)
1296 : "cc");
1297 @@ -451,10 +813,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1298
1299 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1300 #define atomic64_inc(v) atomic64_add(1LL, (v))
1301 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1302 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1303 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1304 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1305 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1306 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1307 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1308 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1309 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1310 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1311 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1312 index 75fe66b..2255c86 100644
1313 --- a/arch/arm/include/asm/cache.h
1314 +++ b/arch/arm/include/asm/cache.h
1315 @@ -4,8 +4,10 @@
1316 #ifndef __ASMARM_CACHE_H
1317 #define __ASMARM_CACHE_H
1318
1319 +#include <linux/const.h>
1320 +
1321 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1322 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1323 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1324
1325 /*
1326 * Memory returned by kmalloc() may be used for DMA, so we must make
1327 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1328 index d5d8d5c..ad92c96 100644
1329 --- a/arch/arm/include/asm/cacheflush.h
1330 +++ b/arch/arm/include/asm/cacheflush.h
1331 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1332 void (*dma_unmap_area)(const void *, size_t, int);
1333
1334 void (*dma_flush_range)(const void *, const void *);
1335 -};
1336 +} __no_const;
1337
1338 /*
1339 * Select the calling method
1340 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1341 index 0e9ce8d..6ef1e03 100644
1342 --- a/arch/arm/include/asm/elf.h
1343 +++ b/arch/arm/include/asm/elf.h
1344 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1345 the loader. We need to make sure that it is out of the way of the program
1346 that it will "exec", and that there is sufficient room for the brk. */
1347
1348 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1349 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1350 +
1351 +#ifdef CONFIG_PAX_ASLR
1352 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1353 +
1354 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1355 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1356 +#endif
1357
1358 /* When the program starts, a1 contains a pointer to a function to be
1359 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1360 @@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1361 extern void elf_set_personality(const struct elf32_hdr *);
1362 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1363
1364 -struct mm_struct;
1365 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1366 -#define arch_randomize_brk arch_randomize_brk
1367 -
1368 extern int vectors_user_mapping(void);
1369 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
1370 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
1371 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1372 index e51b1e8..32a3113 100644
1373 --- a/arch/arm/include/asm/kmap_types.h
1374 +++ b/arch/arm/include/asm/kmap_types.h
1375 @@ -21,6 +21,7 @@ enum km_type {
1376 KM_L1_CACHE,
1377 KM_L2_CACHE,
1378 KM_KDB,
1379 + KM_CLEARPAGE,
1380 KM_TYPE_NR
1381 };
1382
1383 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1384 index 53426c6..c7baff3 100644
1385 --- a/arch/arm/include/asm/outercache.h
1386 +++ b/arch/arm/include/asm/outercache.h
1387 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1388 #endif
1389 void (*set_debug)(unsigned long);
1390 void (*resume)(void);
1391 -};
1392 +} __no_const;
1393
1394 #ifdef CONFIG_OUTER_CACHE
1395
1396 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1397 index 97b440c..b7ff179 100644
1398 --- a/arch/arm/include/asm/page.h
1399 +++ b/arch/arm/include/asm/page.h
1400 @@ -123,7 +123,7 @@ struct cpu_user_fns {
1401 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1402 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1403 unsigned long vaddr, struct vm_area_struct *vma);
1404 -};
1405 +} __no_const;
1406
1407 #ifdef MULTI_USER
1408 extern struct cpu_user_fns cpu_user;
1409 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1410 index 943504f..bf8d667 100644
1411 --- a/arch/arm/include/asm/pgalloc.h
1412 +++ b/arch/arm/include/asm/pgalloc.h
1413 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1414 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1415 }
1416
1417 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1418 +{
1419 + pud_populate(mm, pud, pmd);
1420 +}
1421 +
1422 #else /* !CONFIG_ARM_LPAE */
1423
1424 /*
1425 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1426 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1427 #define pmd_free(mm, pmd) do { } while (0)
1428 #define pud_populate(mm,pmd,pte) BUG()
1429 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1430
1431 #endif /* CONFIG_ARM_LPAE */
1432
1433 diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
1434 index e4c96cc..1145653 100644
1435 --- a/arch/arm/include/asm/system.h
1436 +++ b/arch/arm/include/asm/system.h
1437 @@ -98,6 +98,8 @@ void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
1438
1439 #define xchg(ptr,x) \
1440 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1441 +#define xchg_unchecked(ptr,x) \
1442 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1443
1444 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
1445
1446 @@ -534,6 +536,13 @@ static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
1447
1448 #endif /* __LINUX_ARM_ARCH__ >= 6 */
1449
1450 +#define _ASM_EXTABLE(from, to) \
1451 +" .pushsection __ex_table,\"a\"\n"\
1452 +" .align 3\n" \
1453 +" .long " #from ", " #to"\n" \
1454 +" .popsection"
1455 +
1456 +
1457 #endif /* __ASSEMBLY__ */
1458
1459 #define arch_align_stack(x) (x)
1460 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1461 index 2958976..12ccac4 100644
1462 --- a/arch/arm/include/asm/uaccess.h
1463 +++ b/arch/arm/include/asm/uaccess.h
1464 @@ -22,6 +22,8 @@
1465 #define VERIFY_READ 0
1466 #define VERIFY_WRITE 1
1467
1468 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1469 +
1470 /*
1471 * The exception table consists of pairs of addresses: the first is the
1472 * address of an instruction that is allowed to fault, and the second is
1473 @@ -387,8 +389,23 @@ do { \
1474
1475
1476 #ifdef CONFIG_MMU
1477 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1478 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1479 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1480 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1481 +
1482 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1483 +{
1484 + if (!__builtin_constant_p(n))
1485 + check_object_size(to, n, false);
1486 + return ___copy_from_user(to, from, n);
1487 +}
1488 +
1489 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1490 +{
1491 + if (!__builtin_constant_p(n))
1492 + check_object_size(from, n, true);
1493 + return ___copy_to_user(to, from, n);
1494 +}
1495 +
1496 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1497 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1498 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1499 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1500
1501 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1502 {
1503 + if ((long)n < 0)
1504 + return n;
1505 +
1506 if (access_ok(VERIFY_READ, from, n))
1507 n = __copy_from_user(to, from, n);
1508 else /* security hole - plug it */
1509 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1510
1511 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1512 {
1513 + if ((long)n < 0)
1514 + return n;
1515 +
1516 if (access_ok(VERIFY_WRITE, to, n))
1517 n = __copy_to_user(to, from, n);
1518 return n;
1519 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1520 index 5b0bce6..becd81c 100644
1521 --- a/arch/arm/kernel/armksyms.c
1522 +++ b/arch/arm/kernel/armksyms.c
1523 @@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1524 #ifdef CONFIG_MMU
1525 EXPORT_SYMBOL(copy_page);
1526
1527 -EXPORT_SYMBOL(__copy_from_user);
1528 -EXPORT_SYMBOL(__copy_to_user);
1529 +EXPORT_SYMBOL(___copy_from_user);
1530 +EXPORT_SYMBOL(___copy_to_user);
1531 EXPORT_SYMBOL(__clear_user);
1532
1533 EXPORT_SYMBOL(__get_user_1);
1534 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1535 index 971d65c..cc936fb 100644
1536 --- a/arch/arm/kernel/process.c
1537 +++ b/arch/arm/kernel/process.c
1538 @@ -28,7 +28,6 @@
1539 #include <linux/tick.h>
1540 #include <linux/utsname.h>
1541 #include <linux/uaccess.h>
1542 -#include <linux/random.h>
1543 #include <linux/hw_breakpoint.h>
1544 #include <linux/cpuidle.h>
1545
1546 @@ -273,9 +272,10 @@ void machine_power_off(void)
1547 machine_shutdown();
1548 if (pm_power_off)
1549 pm_power_off();
1550 + BUG();
1551 }
1552
1553 -void machine_restart(char *cmd)
1554 +__noreturn void machine_restart(char *cmd)
1555 {
1556 machine_shutdown();
1557
1558 @@ -517,12 +517,6 @@ unsigned long get_wchan(struct task_struct *p)
1559 return 0;
1560 }
1561
1562 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1563 -{
1564 - unsigned long range_end = mm->brk + 0x02000000;
1565 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1566 -}
1567 -
1568 #ifdef CONFIG_MMU
1569 /*
1570 * The vectors page is always readable from user space for the
1571 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1572 index a255c39..4a19b25 100644
1573 --- a/arch/arm/kernel/setup.c
1574 +++ b/arch/arm/kernel/setup.c
1575 @@ -109,13 +109,13 @@ struct processor processor __read_mostly;
1576 struct cpu_tlb_fns cpu_tlb __read_mostly;
1577 #endif
1578 #ifdef MULTI_USER
1579 -struct cpu_user_fns cpu_user __read_mostly;
1580 +struct cpu_user_fns cpu_user __read_only;
1581 #endif
1582 #ifdef MULTI_CACHE
1583 -struct cpu_cache_fns cpu_cache __read_mostly;
1584 +struct cpu_cache_fns cpu_cache __read_only;
1585 #endif
1586 #ifdef CONFIG_OUTER_CACHE
1587 -struct outer_cache_fns outer_cache __read_mostly;
1588 +struct outer_cache_fns outer_cache __read_only;
1589 EXPORT_SYMBOL(outer_cache);
1590 #endif
1591
1592 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1593 index f84dfe6..13e94f7 100644
1594 --- a/arch/arm/kernel/traps.c
1595 +++ b/arch/arm/kernel/traps.c
1596 @@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1597
1598 static DEFINE_RAW_SPINLOCK(die_lock);
1599
1600 +extern void gr_handle_kernel_exploit(void);
1601 +
1602 /*
1603 * This function is protected against re-entrancy.
1604 */
1605 @@ -291,6 +293,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1606 panic("Fatal exception in interrupt");
1607 if (panic_on_oops)
1608 panic("Fatal exception");
1609 +
1610 + gr_handle_kernel_exploit();
1611 +
1612 if (ret != NOTIFY_STOP)
1613 do_exit(SIGSEGV);
1614 }
1615 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1616 index 66a477a..bee61d3 100644
1617 --- a/arch/arm/lib/copy_from_user.S
1618 +++ b/arch/arm/lib/copy_from_user.S
1619 @@ -16,7 +16,7 @@
1620 /*
1621 * Prototype:
1622 *
1623 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1624 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1625 *
1626 * Purpose:
1627 *
1628 @@ -84,11 +84,11 @@
1629
1630 .text
1631
1632 -ENTRY(__copy_from_user)
1633 +ENTRY(___copy_from_user)
1634
1635 #include "copy_template.S"
1636
1637 -ENDPROC(__copy_from_user)
1638 +ENDPROC(___copy_from_user)
1639
1640 .pushsection .fixup,"ax"
1641 .align 0
1642 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1643 index 6ee2f67..d1cce76 100644
1644 --- a/arch/arm/lib/copy_page.S
1645 +++ b/arch/arm/lib/copy_page.S
1646 @@ -10,6 +10,7 @@
1647 * ASM optimised string functions
1648 */
1649 #include <linux/linkage.h>
1650 +#include <linux/const.h>
1651 #include <asm/assembler.h>
1652 #include <asm/asm-offsets.h>
1653 #include <asm/cache.h>
1654 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1655 index d066df6..df28194 100644
1656 --- a/arch/arm/lib/copy_to_user.S
1657 +++ b/arch/arm/lib/copy_to_user.S
1658 @@ -16,7 +16,7 @@
1659 /*
1660 * Prototype:
1661 *
1662 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1663 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1664 *
1665 * Purpose:
1666 *
1667 @@ -88,11 +88,11 @@
1668 .text
1669
1670 ENTRY(__copy_to_user_std)
1671 -WEAK(__copy_to_user)
1672 +WEAK(___copy_to_user)
1673
1674 #include "copy_template.S"
1675
1676 -ENDPROC(__copy_to_user)
1677 +ENDPROC(___copy_to_user)
1678 ENDPROC(__copy_to_user_std)
1679
1680 .pushsection .fixup,"ax"
1681 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1682 index 5c908b1..e712687 100644
1683 --- a/arch/arm/lib/uaccess.S
1684 +++ b/arch/arm/lib/uaccess.S
1685 @@ -20,7 +20,7 @@
1686
1687 #define PAGE_SHIFT 12
1688
1689 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1690 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1691 * Purpose : copy a block to user memory from kernel memory
1692 * Params : to - user memory
1693 * : from - kernel memory
1694 @@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1695 sub r2, r2, ip
1696 b .Lc2u_dest_aligned
1697
1698 -ENTRY(__copy_to_user)
1699 +ENTRY(___copy_to_user)
1700 stmfd sp!, {r2, r4 - r7, lr}
1701 cmp r2, #4
1702 blt .Lc2u_not_enough
1703 @@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1704 ldrgtb r3, [r1], #0
1705 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1706 b .Lc2u_finished
1707 -ENDPROC(__copy_to_user)
1708 +ENDPROC(___copy_to_user)
1709
1710 .pushsection .fixup,"ax"
1711 .align 0
1712 9001: ldmfd sp!, {r0, r4 - r7, pc}
1713 .popsection
1714
1715 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1716 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1717 * Purpose : copy a block from user memory to kernel memory
1718 * Params : to - kernel memory
1719 * : from - user memory
1720 @@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1721 sub r2, r2, ip
1722 b .Lcfu_dest_aligned
1723
1724 -ENTRY(__copy_from_user)
1725 +ENTRY(___copy_from_user)
1726 stmfd sp!, {r0, r2, r4 - r7, lr}
1727 cmp r2, #4
1728 blt .Lcfu_not_enough
1729 @@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1730 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1731 strgtb r3, [r0], #1
1732 b .Lcfu_finished
1733 -ENDPROC(__copy_from_user)
1734 +ENDPROC(___copy_from_user)
1735
1736 .pushsection .fixup,"ax"
1737 .align 0
1738 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1739 index 025f742..8432b08 100644
1740 --- a/arch/arm/lib/uaccess_with_memcpy.c
1741 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1742 @@ -104,7 +104,7 @@ out:
1743 }
1744
1745 unsigned long
1746 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1747 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1748 {
1749 /*
1750 * This test is stubbed out of the main function above to keep
1751 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1752 index 6722627..8f97548c 100644
1753 --- a/arch/arm/mach-omap2/board-n8x0.c
1754 +++ b/arch/arm/mach-omap2/board-n8x0.c
1755 @@ -597,7 +597,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1756 }
1757 #endif
1758
1759 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1760 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1761 .late_init = n8x0_menelaus_late_init,
1762 };
1763
1764 diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
1765 index 2b2d51c..0127490 100644
1766 --- a/arch/arm/mach-ux500/mbox-db5500.c
1767 +++ b/arch/arm/mach-ux500/mbox-db5500.c
1768 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
1769 return sprintf(buf, "0x%X\n", mbox_value);
1770 }
1771
1772 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1773 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1774
1775 static int mbox_show(struct seq_file *s, void *data)
1776 {
1777 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1778 index bb7eac3..3bade16 100644
1779 --- a/arch/arm/mm/fault.c
1780 +++ b/arch/arm/mm/fault.c
1781 @@ -172,6 +172,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1782 }
1783 #endif
1784
1785 +#ifdef CONFIG_PAX_PAGEEXEC
1786 + if (fsr & FSR_LNX_PF) {
1787 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1788 + do_group_exit(SIGKILL);
1789 + }
1790 +#endif
1791 +
1792 tsk->thread.address = addr;
1793 tsk->thread.error_code = fsr;
1794 tsk->thread.trap_no = 14;
1795 @@ -393,6 +400,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1796 }
1797 #endif /* CONFIG_MMU */
1798
1799 +#ifdef CONFIG_PAX_PAGEEXEC
1800 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1801 +{
1802 + long i;
1803 +
1804 + printk(KERN_ERR "PAX: bytes at PC: ");
1805 + for (i = 0; i < 20; i++) {
1806 + unsigned char c;
1807 + if (get_user(c, (__force unsigned char __user *)pc+i))
1808 + printk(KERN_CONT "?? ");
1809 + else
1810 + printk(KERN_CONT "%02x ", c);
1811 + }
1812 + printk("\n");
1813 +
1814 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1815 + for (i = -1; i < 20; i++) {
1816 + unsigned long c;
1817 + if (get_user(c, (__force unsigned long __user *)sp+i))
1818 + printk(KERN_CONT "???????? ");
1819 + else
1820 + printk(KERN_CONT "%08lx ", c);
1821 + }
1822 + printk("\n");
1823 +}
1824 +#endif
1825 +
1826 /*
1827 * First Level Translation Fault Handler
1828 *
1829 @@ -573,6 +607,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1830 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1831 struct siginfo info;
1832
1833 +#ifdef CONFIG_PAX_REFCOUNT
1834 + if (fsr_fs(ifsr) == 2) {
1835 + unsigned int bkpt;
1836 +
1837 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1838 + current->thread.error_code = ifsr;
1839 + current->thread.trap_no = 0;
1840 + pax_report_refcount_overflow(regs);
1841 + fixup_exception(regs);
1842 + return;
1843 + }
1844 + }
1845 +#endif
1846 +
1847 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1848 return;
1849
1850 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1851 index ce8cb19..3ec539d 100644
1852 --- a/arch/arm/mm/mmap.c
1853 +++ b/arch/arm/mm/mmap.c
1854 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1855 if (len > TASK_SIZE)
1856 return -ENOMEM;
1857
1858 +#ifdef CONFIG_PAX_RANDMMAP
1859 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1860 +#endif
1861 +
1862 if (addr) {
1863 if (do_align)
1864 addr = COLOUR_ALIGN(addr, pgoff);
1865 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1866 addr = PAGE_ALIGN(addr);
1867
1868 vma = find_vma(mm, addr);
1869 - if (TASK_SIZE - len >= addr &&
1870 - (!vma || addr + len <= vma->vm_start))
1871 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1872 return addr;
1873 }
1874 if (len > mm->cached_hole_size) {
1875 - start_addr = addr = mm->free_area_cache;
1876 + start_addr = addr = mm->free_area_cache;
1877 } else {
1878 - start_addr = addr = mm->mmap_base;
1879 - mm->cached_hole_size = 0;
1880 + start_addr = addr = mm->mmap_base;
1881 + mm->cached_hole_size = 0;
1882 }
1883
1884 full_search:
1885 @@ -124,14 +127,14 @@ full_search:
1886 * Start a new search - just in case we missed
1887 * some holes.
1888 */
1889 - if (start_addr != TASK_UNMAPPED_BASE) {
1890 - start_addr = addr = TASK_UNMAPPED_BASE;
1891 + if (start_addr != mm->mmap_base) {
1892 + start_addr = addr = mm->mmap_base;
1893 mm->cached_hole_size = 0;
1894 goto full_search;
1895 }
1896 return -ENOMEM;
1897 }
1898 - if (!vma || addr + len <= vma->vm_start) {
1899 + if (check_heap_stack_gap(vma, addr, len)) {
1900 /*
1901 * Remember the place where we stopped the search:
1902 */
1903 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1904
1905 if (mmap_is_legacy()) {
1906 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1907 +
1908 +#ifdef CONFIG_PAX_RANDMMAP
1909 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1910 + mm->mmap_base += mm->delta_mmap;
1911 +#endif
1912 +
1913 mm->get_unmapped_area = arch_get_unmapped_area;
1914 mm->unmap_area = arch_unmap_area;
1915 } else {
1916 mm->mmap_base = mmap_base(random_factor);
1917 +
1918 +#ifdef CONFIG_PAX_RANDMMAP
1919 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1920 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1921 +#endif
1922 +
1923 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1924 mm->unmap_area = arch_unmap_area_topdown;
1925 }
1926 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
1927 index 71a6827..e7fbc23 100644
1928 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
1929 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
1930 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
1931 int (*started)(unsigned ch);
1932 int (*flush)(unsigned ch);
1933 int (*stop)(unsigned ch);
1934 -};
1935 +} __no_const;
1936
1937 extern void *samsung_dmadev_get_ops(void);
1938 extern void *s3c_dma_get_ops(void);
1939 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
1940 index 5f28cae..3d23723 100644
1941 --- a/arch/arm/plat-samsung/include/plat/ehci.h
1942 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
1943 @@ -14,7 +14,7 @@
1944 struct s5p_ehci_platdata {
1945 int (*phy_init)(struct platform_device *pdev, int type);
1946 int (*phy_exit)(struct platform_device *pdev, int type);
1947 -};
1948 +} __no_const;
1949
1950 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
1951
1952 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
1953 index c3a58a1..78fbf54 100644
1954 --- a/arch/avr32/include/asm/cache.h
1955 +++ b/arch/avr32/include/asm/cache.h
1956 @@ -1,8 +1,10 @@
1957 #ifndef __ASM_AVR32_CACHE_H
1958 #define __ASM_AVR32_CACHE_H
1959
1960 +#include <linux/const.h>
1961 +
1962 #define L1_CACHE_SHIFT 5
1963 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1964 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1965
1966 /*
1967 * Memory returned by kmalloc() may be used for DMA, so we must make
1968 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1969 index 3b3159b..425ea94 100644
1970 --- a/arch/avr32/include/asm/elf.h
1971 +++ b/arch/avr32/include/asm/elf.h
1972 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1973 the loader. We need to make sure that it is out of the way of the program
1974 that it will "exec", and that there is sufficient room for the brk. */
1975
1976 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1977 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1978
1979 +#ifdef CONFIG_PAX_ASLR
1980 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1981 +
1982 +#define PAX_DELTA_MMAP_LEN 15
1983 +#define PAX_DELTA_STACK_LEN 15
1984 +#endif
1985
1986 /* This yields a mask that user programs can use to figure out what
1987 instruction set this CPU supports. This could be done in user space,
1988 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1989 index b7f5c68..556135c 100644
1990 --- a/arch/avr32/include/asm/kmap_types.h
1991 +++ b/arch/avr32/include/asm/kmap_types.h
1992 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1993 D(11) KM_IRQ1,
1994 D(12) KM_SOFTIRQ0,
1995 D(13) KM_SOFTIRQ1,
1996 -D(14) KM_TYPE_NR
1997 +D(14) KM_CLEARPAGE,
1998 +D(15) KM_TYPE_NR
1999 };
2000
2001 #undef D
2002 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2003 index f7040a1..db9f300 100644
2004 --- a/arch/avr32/mm/fault.c
2005 +++ b/arch/avr32/mm/fault.c
2006 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2007
2008 int exception_trace = 1;
2009
2010 +#ifdef CONFIG_PAX_PAGEEXEC
2011 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2012 +{
2013 + unsigned long i;
2014 +
2015 + printk(KERN_ERR "PAX: bytes at PC: ");
2016 + for (i = 0; i < 20; i++) {
2017 + unsigned char c;
2018 + if (get_user(c, (unsigned char *)pc+i))
2019 + printk(KERN_CONT "???????? ");
2020 + else
2021 + printk(KERN_CONT "%02x ", c);
2022 + }
2023 + printk("\n");
2024 +}
2025 +#endif
2026 +
2027 /*
2028 * This routine handles page faults. It determines the address and the
2029 * problem, and then passes it off to one of the appropriate routines.
2030 @@ -156,6 +173,16 @@ bad_area:
2031 up_read(&mm->mmap_sem);
2032
2033 if (user_mode(regs)) {
2034 +
2035 +#ifdef CONFIG_PAX_PAGEEXEC
2036 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2037 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2038 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2039 + do_group_exit(SIGKILL);
2040 + }
2041 + }
2042 +#endif
2043 +
2044 if (exception_trace && printk_ratelimit())
2045 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2046 "sp %08lx ecr %lu\n",
2047 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2048 index 568885a..f8008df 100644
2049 --- a/arch/blackfin/include/asm/cache.h
2050 +++ b/arch/blackfin/include/asm/cache.h
2051 @@ -7,6 +7,7 @@
2052 #ifndef __ARCH_BLACKFIN_CACHE_H
2053 #define __ARCH_BLACKFIN_CACHE_H
2054
2055 +#include <linux/const.h>
2056 #include <linux/linkage.h> /* for asmlinkage */
2057
2058 /*
2059 @@ -14,7 +15,7 @@
2060 * Blackfin loads 32 bytes for cache
2061 */
2062 #define L1_CACHE_SHIFT 5
2063 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2064 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2065 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2066
2067 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2068 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2069 index aea2718..3639a60 100644
2070 --- a/arch/cris/include/arch-v10/arch/cache.h
2071 +++ b/arch/cris/include/arch-v10/arch/cache.h
2072 @@ -1,8 +1,9 @@
2073 #ifndef _ASM_ARCH_CACHE_H
2074 #define _ASM_ARCH_CACHE_H
2075
2076 +#include <linux/const.h>
2077 /* Etrax 100LX have 32-byte cache-lines. */
2078 -#define L1_CACHE_BYTES 32
2079 #define L1_CACHE_SHIFT 5
2080 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2081
2082 #endif /* _ASM_ARCH_CACHE_H */
2083 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2084 index 1de779f..336fad3 100644
2085 --- a/arch/cris/include/arch-v32/arch/cache.h
2086 +++ b/arch/cris/include/arch-v32/arch/cache.h
2087 @@ -1,11 +1,12 @@
2088 #ifndef _ASM_CRIS_ARCH_CACHE_H
2089 #define _ASM_CRIS_ARCH_CACHE_H
2090
2091 +#include <linux/const.h>
2092 #include <arch/hwregs/dma.h>
2093
2094 /* A cache-line is 32 bytes. */
2095 -#define L1_CACHE_BYTES 32
2096 #define L1_CACHE_SHIFT 5
2097 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2098
2099 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2100
2101 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2102 index 0d8a7d6..d0c9ff5 100644
2103 --- a/arch/frv/include/asm/atomic.h
2104 +++ b/arch/frv/include/asm/atomic.h
2105 @@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
2106 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2107 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2108
2109 +#define atomic64_read_unchecked(v) atomic64_read(v)
2110 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2111 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2112 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2113 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2114 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2115 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2116 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2117 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2118 +
2119 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2120 {
2121 int c, old;
2122 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2123 index 2797163..c2a401d 100644
2124 --- a/arch/frv/include/asm/cache.h
2125 +++ b/arch/frv/include/asm/cache.h
2126 @@ -12,10 +12,11 @@
2127 #ifndef __ASM_CACHE_H
2128 #define __ASM_CACHE_H
2129
2130 +#include <linux/const.h>
2131
2132 /* bytes per L1 cache line */
2133 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2134 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2135 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2136
2137 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2138 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2139 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2140 index f8e16b2..c73ff79 100644
2141 --- a/arch/frv/include/asm/kmap_types.h
2142 +++ b/arch/frv/include/asm/kmap_types.h
2143 @@ -23,6 +23,7 @@ enum km_type {
2144 KM_IRQ1,
2145 KM_SOFTIRQ0,
2146 KM_SOFTIRQ1,
2147 + KM_CLEARPAGE,
2148 KM_TYPE_NR
2149 };
2150
2151 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2152 index 385fd30..6c3d97e 100644
2153 --- a/arch/frv/mm/elf-fdpic.c
2154 +++ b/arch/frv/mm/elf-fdpic.c
2155 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2156 if (addr) {
2157 addr = PAGE_ALIGN(addr);
2158 vma = find_vma(current->mm, addr);
2159 - if (TASK_SIZE - len >= addr &&
2160 - (!vma || addr + len <= vma->vm_start))
2161 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2162 goto success;
2163 }
2164
2165 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2166 for (; vma; vma = vma->vm_next) {
2167 if (addr > limit)
2168 break;
2169 - if (addr + len <= vma->vm_start)
2170 + if (check_heap_stack_gap(vma, addr, len))
2171 goto success;
2172 addr = vma->vm_end;
2173 }
2174 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2175 for (; vma; vma = vma->vm_next) {
2176 if (addr > limit)
2177 break;
2178 - if (addr + len <= vma->vm_start)
2179 + if (check_heap_stack_gap(vma, addr, len))
2180 goto success;
2181 addr = vma->vm_end;
2182 }
2183 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2184 index c635028..6d9445a 100644
2185 --- a/arch/h8300/include/asm/cache.h
2186 +++ b/arch/h8300/include/asm/cache.h
2187 @@ -1,8 +1,10 @@
2188 #ifndef __ARCH_H8300_CACHE_H
2189 #define __ARCH_H8300_CACHE_H
2190
2191 +#include <linux/const.h>
2192 +
2193 /* bytes per L1 cache line */
2194 -#define L1_CACHE_BYTES 4
2195 +#define L1_CACHE_BYTES _AC(4,UL)
2196
2197 /* m68k-elf-gcc 2.95.2 doesn't like these */
2198
2199 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2200 index 0f01de2..d37d309 100644
2201 --- a/arch/hexagon/include/asm/cache.h
2202 +++ b/arch/hexagon/include/asm/cache.h
2203 @@ -21,9 +21,11 @@
2204 #ifndef __ASM_CACHE_H
2205 #define __ASM_CACHE_H
2206
2207 +#include <linux/const.h>
2208 +
2209 /* Bytes per L1 cache line */
2210 -#define L1_CACHE_SHIFT (5)
2211 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2212 +#define L1_CACHE_SHIFT 5
2213 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2214
2215 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2216 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2217 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2218 index 3fad89e..3047da5 100644
2219 --- a/arch/ia64/include/asm/atomic.h
2220 +++ b/arch/ia64/include/asm/atomic.h
2221 @@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2222 #define atomic64_inc(v) atomic64_add(1, (v))
2223 #define atomic64_dec(v) atomic64_sub(1, (v))
2224
2225 +#define atomic64_read_unchecked(v) atomic64_read(v)
2226 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2227 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2228 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2229 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2230 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2231 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2232 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2233 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2234 +
2235 /* Atomic operations are already serializing */
2236 #define smp_mb__before_atomic_dec() barrier()
2237 #define smp_mb__after_atomic_dec() barrier()
2238 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2239 index 988254a..e1ee885 100644
2240 --- a/arch/ia64/include/asm/cache.h
2241 +++ b/arch/ia64/include/asm/cache.h
2242 @@ -1,6 +1,7 @@
2243 #ifndef _ASM_IA64_CACHE_H
2244 #define _ASM_IA64_CACHE_H
2245
2246 +#include <linux/const.h>
2247
2248 /*
2249 * Copyright (C) 1998-2000 Hewlett-Packard Co
2250 @@ -9,7 +10,7 @@
2251
2252 /* Bytes per L1 (data) cache line. */
2253 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2254 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2255 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2256
2257 #ifdef CONFIG_SMP
2258 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2259 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2260 index b5298eb..67c6e62 100644
2261 --- a/arch/ia64/include/asm/elf.h
2262 +++ b/arch/ia64/include/asm/elf.h
2263 @@ -42,6 +42,13 @@
2264 */
2265 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2266
2267 +#ifdef CONFIG_PAX_ASLR
2268 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2269 +
2270 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2271 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2272 +#endif
2273 +
2274 #define PT_IA_64_UNWIND 0x70000001
2275
2276 /* IA-64 relocations: */
2277 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2278 index 96a8d92..617a1cf 100644
2279 --- a/arch/ia64/include/asm/pgalloc.h
2280 +++ b/arch/ia64/include/asm/pgalloc.h
2281 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2282 pgd_val(*pgd_entry) = __pa(pud);
2283 }
2284
2285 +static inline void
2286 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2287 +{
2288 + pgd_populate(mm, pgd_entry, pud);
2289 +}
2290 +
2291 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2292 {
2293 return quicklist_alloc(0, GFP_KERNEL, NULL);
2294 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2295 pud_val(*pud_entry) = __pa(pmd);
2296 }
2297
2298 +static inline void
2299 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2300 +{
2301 + pud_populate(mm, pud_entry, pmd);
2302 +}
2303 +
2304 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2305 {
2306 return quicklist_alloc(0, GFP_KERNEL, NULL);
2307 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2308 index 1a97af3..7529d31 100644
2309 --- a/arch/ia64/include/asm/pgtable.h
2310 +++ b/arch/ia64/include/asm/pgtable.h
2311 @@ -12,7 +12,7 @@
2312 * David Mosberger-Tang <davidm@hpl.hp.com>
2313 */
2314
2315 -
2316 +#include <linux/const.h>
2317 #include <asm/mman.h>
2318 #include <asm/page.h>
2319 #include <asm/processor.h>
2320 @@ -143,6 +143,17 @@
2321 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2322 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2323 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2324 +
2325 +#ifdef CONFIG_PAX_PAGEEXEC
2326 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2327 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2328 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2329 +#else
2330 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2331 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2332 +# define PAGE_COPY_NOEXEC PAGE_COPY
2333 +#endif
2334 +
2335 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2336 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2337 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2338 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2339 index b77768d..e0795eb 100644
2340 --- a/arch/ia64/include/asm/spinlock.h
2341 +++ b/arch/ia64/include/asm/spinlock.h
2342 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2343 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2344
2345 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2346 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2347 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2348 }
2349
2350 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2351 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2352 index 449c8c0..432a3d2 100644
2353 --- a/arch/ia64/include/asm/uaccess.h
2354 +++ b/arch/ia64/include/asm/uaccess.h
2355 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2356 const void *__cu_from = (from); \
2357 long __cu_len = (n); \
2358 \
2359 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2360 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2361 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2362 __cu_len; \
2363 })
2364 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2365 long __cu_len = (n); \
2366 \
2367 __chk_user_ptr(__cu_from); \
2368 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2369 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2370 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2371 __cu_len; \
2372 })
2373 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2374 index 24603be..948052d 100644
2375 --- a/arch/ia64/kernel/module.c
2376 +++ b/arch/ia64/kernel/module.c
2377 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2378 void
2379 module_free (struct module *mod, void *module_region)
2380 {
2381 - if (mod && mod->arch.init_unw_table &&
2382 - module_region == mod->module_init) {
2383 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2384 unw_remove_unwind_table(mod->arch.init_unw_table);
2385 mod->arch.init_unw_table = NULL;
2386 }
2387 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2388 }
2389
2390 static inline int
2391 +in_init_rx (const struct module *mod, uint64_t addr)
2392 +{
2393 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2394 +}
2395 +
2396 +static inline int
2397 +in_init_rw (const struct module *mod, uint64_t addr)
2398 +{
2399 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2400 +}
2401 +
2402 +static inline int
2403 in_init (const struct module *mod, uint64_t addr)
2404 {
2405 - return addr - (uint64_t) mod->module_init < mod->init_size;
2406 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2407 +}
2408 +
2409 +static inline int
2410 +in_core_rx (const struct module *mod, uint64_t addr)
2411 +{
2412 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2413 +}
2414 +
2415 +static inline int
2416 +in_core_rw (const struct module *mod, uint64_t addr)
2417 +{
2418 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2419 }
2420
2421 static inline int
2422 in_core (const struct module *mod, uint64_t addr)
2423 {
2424 - return addr - (uint64_t) mod->module_core < mod->core_size;
2425 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2426 }
2427
2428 static inline int
2429 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2430 break;
2431
2432 case RV_BDREL:
2433 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2434 + if (in_init_rx(mod, val))
2435 + val -= (uint64_t) mod->module_init_rx;
2436 + else if (in_init_rw(mod, val))
2437 + val -= (uint64_t) mod->module_init_rw;
2438 + else if (in_core_rx(mod, val))
2439 + val -= (uint64_t) mod->module_core_rx;
2440 + else if (in_core_rw(mod, val))
2441 + val -= (uint64_t) mod->module_core_rw;
2442 break;
2443
2444 case RV_LTV:
2445 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2446 * addresses have been selected...
2447 */
2448 uint64_t gp;
2449 - if (mod->core_size > MAX_LTOFF)
2450 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2451 /*
2452 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2453 * at the end of the module.
2454 */
2455 - gp = mod->core_size - MAX_LTOFF / 2;
2456 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2457 else
2458 - gp = mod->core_size / 2;
2459 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2460 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2461 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2462 mod->arch.gp = gp;
2463 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2464 }
2465 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2466 index 609d500..7dde2a8 100644
2467 --- a/arch/ia64/kernel/sys_ia64.c
2468 +++ b/arch/ia64/kernel/sys_ia64.c
2469 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2470 if (REGION_NUMBER(addr) == RGN_HPAGE)
2471 addr = 0;
2472 #endif
2473 +
2474 +#ifdef CONFIG_PAX_RANDMMAP
2475 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2476 + addr = mm->free_area_cache;
2477 + else
2478 +#endif
2479 +
2480 if (!addr)
2481 addr = mm->free_area_cache;
2482
2483 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2484 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2485 /* At this point: (!vma || addr < vma->vm_end). */
2486 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2487 - if (start_addr != TASK_UNMAPPED_BASE) {
2488 + if (start_addr != mm->mmap_base) {
2489 /* Start a new search --- just in case we missed some holes. */
2490 - addr = TASK_UNMAPPED_BASE;
2491 + addr = mm->mmap_base;
2492 goto full_search;
2493 }
2494 return -ENOMEM;
2495 }
2496 - if (!vma || addr + len <= vma->vm_start) {
2497 + if (check_heap_stack_gap(vma, addr, len)) {
2498 /* Remember the address where we stopped this search: */
2499 mm->free_area_cache = addr + len;
2500 return addr;
2501 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2502 index 53c0ba0..2accdde 100644
2503 --- a/arch/ia64/kernel/vmlinux.lds.S
2504 +++ b/arch/ia64/kernel/vmlinux.lds.S
2505 @@ -199,7 +199,7 @@ SECTIONS {
2506 /* Per-cpu data: */
2507 . = ALIGN(PERCPU_PAGE_SIZE);
2508 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2509 - __phys_per_cpu_start = __per_cpu_load;
2510 + __phys_per_cpu_start = per_cpu_load;
2511 /*
2512 * ensure percpu data fits
2513 * into percpu page size
2514 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2515 index 20b3593..1ce77f0 100644
2516 --- a/arch/ia64/mm/fault.c
2517 +++ b/arch/ia64/mm/fault.c
2518 @@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
2519 return pte_present(pte);
2520 }
2521
2522 +#ifdef CONFIG_PAX_PAGEEXEC
2523 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2524 +{
2525 + unsigned long i;
2526 +
2527 + printk(KERN_ERR "PAX: bytes at PC: ");
2528 + for (i = 0; i < 8; i++) {
2529 + unsigned int c;
2530 + if (get_user(c, (unsigned int *)pc+i))
2531 + printk(KERN_CONT "???????? ");
2532 + else
2533 + printk(KERN_CONT "%08x ", c);
2534 + }
2535 + printk("\n");
2536 +}
2537 +#endif
2538 +
2539 void __kprobes
2540 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2541 {
2542 @@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2543 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2544 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2545
2546 - if ((vma->vm_flags & mask) != mask)
2547 + if ((vma->vm_flags & mask) != mask) {
2548 +
2549 +#ifdef CONFIG_PAX_PAGEEXEC
2550 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2551 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2552 + goto bad_area;
2553 +
2554 + up_read(&mm->mmap_sem);
2555 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2556 + do_group_exit(SIGKILL);
2557 + }
2558 +#endif
2559 +
2560 goto bad_area;
2561
2562 + }
2563 +
2564 /*
2565 * If for any reason at all we couldn't handle the fault, make
2566 * sure we exit gracefully rather than endlessly redo the
2567 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2568 index 5ca674b..e0e1b70 100644
2569 --- a/arch/ia64/mm/hugetlbpage.c
2570 +++ b/arch/ia64/mm/hugetlbpage.c
2571 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2572 /* At this point: (!vmm || addr < vmm->vm_end). */
2573 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2574 return -ENOMEM;
2575 - if (!vmm || (addr + len) <= vmm->vm_start)
2576 + if (check_heap_stack_gap(vmm, addr, len))
2577 return addr;
2578 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2579 }
2580 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2581 index 13df239d..cb52116 100644
2582 --- a/arch/ia64/mm/init.c
2583 +++ b/arch/ia64/mm/init.c
2584 @@ -121,6 +121,19 @@ ia64_init_addr_space (void)
2585 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2586 vma->vm_end = vma->vm_start + PAGE_SIZE;
2587 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2588 +
2589 +#ifdef CONFIG_PAX_PAGEEXEC
2590 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2591 + vma->vm_flags &= ~VM_EXEC;
2592 +
2593 +#ifdef CONFIG_PAX_MPROTECT
2594 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2595 + vma->vm_flags &= ~VM_MAYEXEC;
2596 +#endif
2597 +
2598 + }
2599 +#endif
2600 +
2601 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2602 down_write(&current->mm->mmap_sem);
2603 if (insert_vm_struct(current->mm, vma)) {
2604 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2605 index 40b3ee9..8c2c112 100644
2606 --- a/arch/m32r/include/asm/cache.h
2607 +++ b/arch/m32r/include/asm/cache.h
2608 @@ -1,8 +1,10 @@
2609 #ifndef _ASM_M32R_CACHE_H
2610 #define _ASM_M32R_CACHE_H
2611
2612 +#include <linux/const.h>
2613 +
2614 /* L1 cache line size */
2615 #define L1_CACHE_SHIFT 4
2616 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2617 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2618
2619 #endif /* _ASM_M32R_CACHE_H */
2620 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2621 index 82abd15..d95ae5d 100644
2622 --- a/arch/m32r/lib/usercopy.c
2623 +++ b/arch/m32r/lib/usercopy.c
2624 @@ -14,6 +14,9 @@
2625 unsigned long
2626 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2627 {
2628 + if ((long)n < 0)
2629 + return n;
2630 +
2631 prefetch(from);
2632 if (access_ok(VERIFY_WRITE, to, n))
2633 __copy_user(to,from,n);
2634 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2635 unsigned long
2636 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2637 {
2638 + if ((long)n < 0)
2639 + return n;
2640 +
2641 prefetchw(to);
2642 if (access_ok(VERIFY_READ, from, n))
2643 __copy_user_zeroing(to,from,n);
2644 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2645 index 0395c51..5f26031 100644
2646 --- a/arch/m68k/include/asm/cache.h
2647 +++ b/arch/m68k/include/asm/cache.h
2648 @@ -4,9 +4,11 @@
2649 #ifndef __ARCH_M68K_CACHE_H
2650 #define __ARCH_M68K_CACHE_H
2651
2652 +#include <linux/const.h>
2653 +
2654 /* bytes per L1 cache line */
2655 #define L1_CACHE_SHIFT 4
2656 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2657 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2658
2659 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2660
2661 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2662 index 4efe96a..60e8699 100644
2663 --- a/arch/microblaze/include/asm/cache.h
2664 +++ b/arch/microblaze/include/asm/cache.h
2665 @@ -13,11 +13,12 @@
2666 #ifndef _ASM_MICROBLAZE_CACHE_H
2667 #define _ASM_MICROBLAZE_CACHE_H
2668
2669 +#include <linux/const.h>
2670 #include <asm/registers.h>
2671
2672 #define L1_CACHE_SHIFT 5
2673 /* word-granular cache in microblaze */
2674 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2675 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2676
2677 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2678
2679 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2680 index 1d93f81..67794d0 100644
2681 --- a/arch/mips/include/asm/atomic.h
2682 +++ b/arch/mips/include/asm/atomic.h
2683 @@ -21,6 +21,10 @@
2684 #include <asm/war.h>
2685 #include <asm/system.h>
2686
2687 +#ifdef CONFIG_GENERIC_ATOMIC64
2688 +#include <asm-generic/atomic64.h>
2689 +#endif
2690 +
2691 #define ATOMIC_INIT(i) { (i) }
2692
2693 /*
2694 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2695 */
2696 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2697
2698 +#define atomic64_read_unchecked(v) atomic64_read(v)
2699 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2700 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2701 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2702 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2703 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2704 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2705 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2706 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2707 +
2708 #endif /* CONFIG_64BIT */
2709
2710 /*
2711 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2712 index b4db69f..8f3b093 100644
2713 --- a/arch/mips/include/asm/cache.h
2714 +++ b/arch/mips/include/asm/cache.h
2715 @@ -9,10 +9,11 @@
2716 #ifndef _ASM_CACHE_H
2717 #define _ASM_CACHE_H
2718
2719 +#include <linux/const.h>
2720 #include <kmalloc.h>
2721
2722 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2723 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2724 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2725
2726 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2727 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2728 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2729 index 455c0ac..ad65fbe 100644
2730 --- a/arch/mips/include/asm/elf.h
2731 +++ b/arch/mips/include/asm/elf.h
2732 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2733 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2734 #endif
2735
2736 +#ifdef CONFIG_PAX_ASLR
2737 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2738 +
2739 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2740 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2741 +#endif
2742 +
2743 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2744 struct linux_binprm;
2745 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2746 int uses_interp);
2747
2748 -struct mm_struct;
2749 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2750 -#define arch_randomize_brk arch_randomize_brk
2751 -
2752 #endif /* _ASM_ELF_H */
2753 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2754 index da9bd7d..91aa7ab 100644
2755 --- a/arch/mips/include/asm/page.h
2756 +++ b/arch/mips/include/asm/page.h
2757 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2758 #ifdef CONFIG_CPU_MIPS32
2759 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2760 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2761 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2762 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2763 #else
2764 typedef struct { unsigned long long pte; } pte_t;
2765 #define pte_val(x) ((x).pte)
2766 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2767 index 881d18b..cea38bc 100644
2768 --- a/arch/mips/include/asm/pgalloc.h
2769 +++ b/arch/mips/include/asm/pgalloc.h
2770 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2771 {
2772 set_pud(pud, __pud((unsigned long)pmd));
2773 }
2774 +
2775 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2776 +{
2777 + pud_populate(mm, pud, pmd);
2778 +}
2779 #endif
2780
2781 /*
2782 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
2783 index 6018c80..7c37203 100644
2784 --- a/arch/mips/include/asm/system.h
2785 +++ b/arch/mips/include/asm/system.h
2786 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2787 */
2788 #define __ARCH_WANT_UNLOCKED_CTXSW
2789
2790 -extern unsigned long arch_align_stack(unsigned long sp);
2791 +#define arch_align_stack(x) ((x) & ~0xfUL)
2792
2793 #endif /* _ASM_SYSTEM_H */
2794 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2795 index 9fdd8bc..4bd7f1a 100644
2796 --- a/arch/mips/kernel/binfmt_elfn32.c
2797 +++ b/arch/mips/kernel/binfmt_elfn32.c
2798 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2799 #undef ELF_ET_DYN_BASE
2800 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2801
2802 +#ifdef CONFIG_PAX_ASLR
2803 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2804 +
2805 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2806 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2807 +#endif
2808 +
2809 #include <asm/processor.h>
2810 #include <linux/module.h>
2811 #include <linux/elfcore.h>
2812 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2813 index ff44823..97f8906 100644
2814 --- a/arch/mips/kernel/binfmt_elfo32.c
2815 +++ b/arch/mips/kernel/binfmt_elfo32.c
2816 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2817 #undef ELF_ET_DYN_BASE
2818 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2819
2820 +#ifdef CONFIG_PAX_ASLR
2821 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2822 +
2823 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2824 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2825 +#endif
2826 +
2827 #include <asm/processor.h>
2828
2829 /*
2830 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2831 index 7955409..ceaea7c 100644
2832 --- a/arch/mips/kernel/process.c
2833 +++ b/arch/mips/kernel/process.c
2834 @@ -483,15 +483,3 @@ unsigned long get_wchan(struct task_struct *task)
2835 out:
2836 return pc;
2837 }
2838 -
2839 -/*
2840 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2841 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2842 - */
2843 -unsigned long arch_align_stack(unsigned long sp)
2844 -{
2845 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2846 - sp -= get_random_int() & ~PAGE_MASK;
2847 -
2848 - return sp & ALMASK;
2849 -}
2850 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
2851 index 69ebd58..e4bff83 100644
2852 --- a/arch/mips/mm/fault.c
2853 +++ b/arch/mips/mm/fault.c
2854 @@ -28,6 +28,23 @@
2855 #include <asm/highmem.h> /* For VMALLOC_END */
2856 #include <linux/kdebug.h>
2857
2858 +#ifdef CONFIG_PAX_PAGEEXEC
2859 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2860 +{
2861 + unsigned long i;
2862 +
2863 + printk(KERN_ERR "PAX: bytes at PC: ");
2864 + for (i = 0; i < 5; i++) {
2865 + unsigned int c;
2866 + if (get_user(c, (unsigned int *)pc+i))
2867 + printk(KERN_CONT "???????? ");
2868 + else
2869 + printk(KERN_CONT "%08x ", c);
2870 + }
2871 + printk("\n");
2872 +}
2873 +#endif
2874 +
2875 /*
2876 * This routine handles page faults. It determines the address,
2877 * and the problem, and then passes it off to one of the appropriate
2878 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
2879 index 302d779..7d35bf8 100644
2880 --- a/arch/mips/mm/mmap.c
2881 +++ b/arch/mips/mm/mmap.c
2882 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2883 do_color_align = 1;
2884
2885 /* requesting a specific address */
2886 +
2887 +#ifdef CONFIG_PAX_RANDMMAP
2888 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2889 +#endif
2890 +
2891 if (addr) {
2892 if (do_color_align)
2893 addr = COLOUR_ALIGN(addr, pgoff);
2894 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2895 addr = PAGE_ALIGN(addr);
2896
2897 vma = find_vma(mm, addr);
2898 - if (TASK_SIZE - len >= addr &&
2899 - (!vma || addr + len <= vma->vm_start))
2900 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
2901 return addr;
2902 }
2903
2904 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2905 /* At this point: (!vma || addr < vma->vm_end). */
2906 if (TASK_SIZE - len < addr)
2907 return -ENOMEM;
2908 - if (!vma || addr + len <= vma->vm_start)
2909 + if (check_heap_stack_gap(vmm, addr, len))
2910 return addr;
2911 addr = vma->vm_end;
2912 if (do_color_align)
2913 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2914 /* make sure it can fit in the remaining address space */
2915 if (likely(addr > len)) {
2916 vma = find_vma(mm, addr - len);
2917 - if (!vma || addr <= vma->vm_start) {
2918 + if (check_heap_stack_gap(vmm, addr - len, len))
2919 /* cache the address as a hint for next time */
2920 return mm->free_area_cache = addr - len;
2921 }
2922 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2923 * return with success:
2924 */
2925 vma = find_vma(mm, addr);
2926 - if (likely(!vma || addr + len <= vma->vm_start)) {
2927 + if (check_heap_stack_gap(vmm, addr, len)) {
2928 /* cache the address as a hint for next time */
2929 return mm->free_area_cache = addr;
2930 }
2931 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2932 mm->unmap_area = arch_unmap_area_topdown;
2933 }
2934 }
2935 -
2936 -static inline unsigned long brk_rnd(void)
2937 -{
2938 - unsigned long rnd = get_random_int();
2939 -
2940 - rnd = rnd << PAGE_SHIFT;
2941 - /* 8MB for 32bit, 256MB for 64bit */
2942 - if (TASK_IS_32BIT_ADDR)
2943 - rnd = rnd & 0x7ffffful;
2944 - else
2945 - rnd = rnd & 0xffffffful;
2946 -
2947 - return rnd;
2948 -}
2949 -
2950 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2951 -{
2952 - unsigned long base = mm->brk;
2953 - unsigned long ret;
2954 -
2955 - ret = PAGE_ALIGN(base + brk_rnd());
2956 -
2957 - if (ret < mm->brk)
2958 - return mm->brk;
2959 -
2960 - return ret;
2961 -}
2962 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2963 index 967d144..db12197 100644
2964 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
2965 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2966 @@ -11,12 +11,14 @@
2967 #ifndef _ASM_PROC_CACHE_H
2968 #define _ASM_PROC_CACHE_H
2969
2970 +#include <linux/const.h>
2971 +
2972 /* L1 cache */
2973
2974 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2975 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
2976 -#define L1_CACHE_BYTES 16 /* bytes per entry */
2977 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
2978 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2979 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
2980
2981 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2982 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2983 index bcb5df2..84fabd2 100644
2984 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2985 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2986 @@ -16,13 +16,15 @@
2987 #ifndef _ASM_PROC_CACHE_H
2988 #define _ASM_PROC_CACHE_H
2989
2990 +#include <linux/const.h>
2991 +
2992 /*
2993 * L1 cache
2994 */
2995 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2996 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
2997 -#define L1_CACHE_BYTES 32 /* bytes per entry */
2998 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
2999 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3000 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3001
3002 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3003 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3004 index 4ce7a01..449202a 100644
3005 --- a/arch/openrisc/include/asm/cache.h
3006 +++ b/arch/openrisc/include/asm/cache.h
3007 @@ -19,11 +19,13 @@
3008 #ifndef __ASM_OPENRISC_CACHE_H
3009 #define __ASM_OPENRISC_CACHE_H
3010
3011 +#include <linux/const.h>
3012 +
3013 /* FIXME: How can we replace these with values from the CPU...
3014 * they shouldn't be hard-coded!
3015 */
3016
3017 -#define L1_CACHE_BYTES 16
3018 #define L1_CACHE_SHIFT 4
3019 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3020
3021 #endif /* __ASM_OPENRISC_CACHE_H */
3022 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3023 index 4054b31..a10c105 100644
3024 --- a/arch/parisc/include/asm/atomic.h
3025 +++ b/arch/parisc/include/asm/atomic.h
3026 @@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3027
3028 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3029
3030 +#define atomic64_read_unchecked(v) atomic64_read(v)
3031 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3032 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3033 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3034 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3035 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3036 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3037 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3038 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3039 +
3040 #endif /* !CONFIG_64BIT */
3041
3042
3043 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3044 index 47f11c7..3420df2 100644
3045 --- a/arch/parisc/include/asm/cache.h
3046 +++ b/arch/parisc/include/asm/cache.h
3047 @@ -5,6 +5,7 @@
3048 #ifndef __ARCH_PARISC_CACHE_H
3049 #define __ARCH_PARISC_CACHE_H
3050
3051 +#include <linux/const.h>
3052
3053 /*
3054 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3055 @@ -15,13 +16,13 @@
3056 * just ruin performance.
3057 */
3058 #ifdef CONFIG_PA20
3059 -#define L1_CACHE_BYTES 64
3060 #define L1_CACHE_SHIFT 6
3061 #else
3062 -#define L1_CACHE_BYTES 32
3063 #define L1_CACHE_SHIFT 5
3064 #endif
3065
3066 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3067 +
3068 #ifndef __ASSEMBLY__
3069
3070 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3071 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3072 index 19f6cb1..6c78cf2 100644
3073 --- a/arch/parisc/include/asm/elf.h
3074 +++ b/arch/parisc/include/asm/elf.h
3075 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3076
3077 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3078
3079 +#ifdef CONFIG_PAX_ASLR
3080 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3081 +
3082 +#define PAX_DELTA_MMAP_LEN 16
3083 +#define PAX_DELTA_STACK_LEN 16
3084 +#endif
3085 +
3086 /* This yields a mask that user programs can use to figure out what
3087 instruction set this CPU supports. This could be done in user space,
3088 but it's not easy, and we've already done it here. */
3089 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3090 index fc987a1..6e068ef 100644
3091 --- a/arch/parisc/include/asm/pgalloc.h
3092 +++ b/arch/parisc/include/asm/pgalloc.h
3093 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3094 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3095 }
3096
3097 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3098 +{
3099 + pgd_populate(mm, pgd, pmd);
3100 +}
3101 +
3102 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3103 {
3104 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3105 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3106 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3107 #define pmd_free(mm, x) do { } while (0)
3108 #define pgd_populate(mm, pmd, pte) BUG()
3109 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3110
3111 #endif
3112
3113 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3114 index 22dadeb..f6c2be4 100644
3115 --- a/arch/parisc/include/asm/pgtable.h
3116 +++ b/arch/parisc/include/asm/pgtable.h
3117 @@ -210,6 +210,17 @@ struct vm_area_struct;
3118 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3119 #define PAGE_COPY PAGE_EXECREAD
3120 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3121 +
3122 +#ifdef CONFIG_PAX_PAGEEXEC
3123 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3124 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3125 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3126 +#else
3127 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3128 +# define PAGE_COPY_NOEXEC PAGE_COPY
3129 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3130 +#endif
3131 +
3132 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3133 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3134 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3135 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3136 index 5e34ccf..672bc9c 100644
3137 --- a/arch/parisc/kernel/module.c
3138 +++ b/arch/parisc/kernel/module.c
3139 @@ -98,16 +98,38 @@
3140
3141 /* three functions to determine where in the module core
3142 * or init pieces the location is */
3143 +static inline int in_init_rx(struct module *me, void *loc)
3144 +{
3145 + return (loc >= me->module_init_rx &&
3146 + loc < (me->module_init_rx + me->init_size_rx));
3147 +}
3148 +
3149 +static inline int in_init_rw(struct module *me, void *loc)
3150 +{
3151 + return (loc >= me->module_init_rw &&
3152 + loc < (me->module_init_rw + me->init_size_rw));
3153 +}
3154 +
3155 static inline int in_init(struct module *me, void *loc)
3156 {
3157 - return (loc >= me->module_init &&
3158 - loc <= (me->module_init + me->init_size));
3159 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3160 +}
3161 +
3162 +static inline int in_core_rx(struct module *me, void *loc)
3163 +{
3164 + return (loc >= me->module_core_rx &&
3165 + loc < (me->module_core_rx + me->core_size_rx));
3166 +}
3167 +
3168 +static inline int in_core_rw(struct module *me, void *loc)
3169 +{
3170 + return (loc >= me->module_core_rw &&
3171 + loc < (me->module_core_rw + me->core_size_rw));
3172 }
3173
3174 static inline int in_core(struct module *me, void *loc)
3175 {
3176 - return (loc >= me->module_core &&
3177 - loc <= (me->module_core + me->core_size));
3178 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3179 }
3180
3181 static inline int in_local(struct module *me, void *loc)
3182 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3183 }
3184
3185 /* align things a bit */
3186 - me->core_size = ALIGN(me->core_size, 16);
3187 - me->arch.got_offset = me->core_size;
3188 - me->core_size += gots * sizeof(struct got_entry);
3189 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3190 + me->arch.got_offset = me->core_size_rw;
3191 + me->core_size_rw += gots * sizeof(struct got_entry);
3192
3193 - me->core_size = ALIGN(me->core_size, 16);
3194 - me->arch.fdesc_offset = me->core_size;
3195 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3196 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3197 + me->arch.fdesc_offset = me->core_size_rw;
3198 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3199
3200 me->arch.got_max = gots;
3201 me->arch.fdesc_max = fdescs;
3202 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3203
3204 BUG_ON(value == 0);
3205
3206 - got = me->module_core + me->arch.got_offset;
3207 + got = me->module_core_rw + me->arch.got_offset;
3208 for (i = 0; got[i].addr; i++)
3209 if (got[i].addr == value)
3210 goto out;
3211 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3212 #ifdef CONFIG_64BIT
3213 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3214 {
3215 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3216 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3217
3218 if (!value) {
3219 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3220 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3221
3222 /* Create new one */
3223 fdesc->addr = value;
3224 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3225 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3226 return (Elf_Addr)fdesc;
3227 }
3228 #endif /* CONFIG_64BIT */
3229 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3230
3231 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3232 end = table + sechdrs[me->arch.unwind_section].sh_size;
3233 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3234 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3235
3236 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3237 me->arch.unwind_section, table, end, gp);
3238 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3239 index c9b9322..02d8940 100644
3240 --- a/arch/parisc/kernel/sys_parisc.c
3241 +++ b/arch/parisc/kernel/sys_parisc.c
3242 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3243 /* At this point: (!vma || addr < vma->vm_end). */
3244 if (TASK_SIZE - len < addr)
3245 return -ENOMEM;
3246 - if (!vma || addr + len <= vma->vm_start)
3247 + if (check_heap_stack_gap(vma, addr, len))
3248 return addr;
3249 addr = vma->vm_end;
3250 }
3251 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3252 /* At this point: (!vma || addr < vma->vm_end). */
3253 if (TASK_SIZE - len < addr)
3254 return -ENOMEM;
3255 - if (!vma || addr + len <= vma->vm_start)
3256 + if (check_heap_stack_gap(vma, addr, len))
3257 return addr;
3258 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3259 if (addr < vma->vm_end) /* handle wraparound */
3260 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3261 if (flags & MAP_FIXED)
3262 return addr;
3263 if (!addr)
3264 - addr = TASK_UNMAPPED_BASE;
3265 + addr = current->mm->mmap_base;
3266
3267 if (filp) {
3268 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3269 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3270 index f19e660..414fe24 100644
3271 --- a/arch/parisc/kernel/traps.c
3272 +++ b/arch/parisc/kernel/traps.c
3273 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3274
3275 down_read(&current->mm->mmap_sem);
3276 vma = find_vma(current->mm,regs->iaoq[0]);
3277 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3278 - && (vma->vm_flags & VM_EXEC)) {
3279 -
3280 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3281 fault_address = regs->iaoq[0];
3282 fault_space = regs->iasq[0];
3283
3284 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3285 index 18162ce..94de376 100644
3286 --- a/arch/parisc/mm/fault.c
3287 +++ b/arch/parisc/mm/fault.c
3288 @@ -15,6 +15,7 @@
3289 #include <linux/sched.h>
3290 #include <linux/interrupt.h>
3291 #include <linux/module.h>
3292 +#include <linux/unistd.h>
3293
3294 #include <asm/uaccess.h>
3295 #include <asm/traps.h>
3296 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3297 static unsigned long
3298 parisc_acctyp(unsigned long code, unsigned int inst)
3299 {
3300 - if (code == 6 || code == 16)
3301 + if (code == 6 || code == 7 || code == 16)
3302 return VM_EXEC;
3303
3304 switch (inst & 0xf0000000) {
3305 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3306 }
3307 #endif
3308
3309 +#ifdef CONFIG_PAX_PAGEEXEC
3310 +/*
3311 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3312 + *
3313 + * returns 1 when task should be killed
3314 + * 2 when rt_sigreturn trampoline was detected
3315 + * 3 when unpatched PLT trampoline was detected
3316 + */
3317 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3318 +{
3319 +
3320 +#ifdef CONFIG_PAX_EMUPLT
3321 + int err;
3322 +
3323 + do { /* PaX: unpatched PLT emulation */
3324 + unsigned int bl, depwi;
3325 +
3326 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3327 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3328 +
3329 + if (err)
3330 + break;
3331 +
3332 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3333 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3334 +
3335 + err = get_user(ldw, (unsigned int *)addr);
3336 + err |= get_user(bv, (unsigned int *)(addr+4));
3337 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3338 +
3339 + if (err)
3340 + break;
3341 +
3342 + if (ldw == 0x0E801096U &&
3343 + bv == 0xEAC0C000U &&
3344 + ldw2 == 0x0E881095U)
3345 + {
3346 + unsigned int resolver, map;
3347 +
3348 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3349 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3350 + if (err)
3351 + break;
3352 +
3353 + regs->gr[20] = instruction_pointer(regs)+8;
3354 + regs->gr[21] = map;
3355 + regs->gr[22] = resolver;
3356 + regs->iaoq[0] = resolver | 3UL;
3357 + regs->iaoq[1] = regs->iaoq[0] + 4;
3358 + return 3;
3359 + }
3360 + }
3361 + } while (0);
3362 +#endif
3363 +
3364 +#ifdef CONFIG_PAX_EMUTRAMP
3365 +
3366 +#ifndef CONFIG_PAX_EMUSIGRT
3367 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3368 + return 1;
3369 +#endif
3370 +
3371 + do { /* PaX: rt_sigreturn emulation */
3372 + unsigned int ldi1, ldi2, bel, nop;
3373 +
3374 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3375 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3376 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3377 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3378 +
3379 + if (err)
3380 + break;
3381 +
3382 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3383 + ldi2 == 0x3414015AU &&
3384 + bel == 0xE4008200U &&
3385 + nop == 0x08000240U)
3386 + {
3387 + regs->gr[25] = (ldi1 & 2) >> 1;
3388 + regs->gr[20] = __NR_rt_sigreturn;
3389 + regs->gr[31] = regs->iaoq[1] + 16;
3390 + regs->sr[0] = regs->iasq[1];
3391 + regs->iaoq[0] = 0x100UL;
3392 + regs->iaoq[1] = regs->iaoq[0] + 4;
3393 + regs->iasq[0] = regs->sr[2];
3394 + regs->iasq[1] = regs->sr[2];
3395 + return 2;
3396 + }
3397 + } while (0);
3398 +#endif
3399 +
3400 + return 1;
3401 +}
3402 +
3403 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3404 +{
3405 + unsigned long i;
3406 +
3407 + printk(KERN_ERR "PAX: bytes at PC: ");
3408 + for (i = 0; i < 5; i++) {
3409 + unsigned int c;
3410 + if (get_user(c, (unsigned int *)pc+i))
3411 + printk(KERN_CONT "???????? ");
3412 + else
3413 + printk(KERN_CONT "%08x ", c);
3414 + }
3415 + printk("\n");
3416 +}
3417 +#endif
3418 +
3419 int fixup_exception(struct pt_regs *regs)
3420 {
3421 const struct exception_table_entry *fix;
3422 @@ -192,8 +303,33 @@ good_area:
3423
3424 acc_type = parisc_acctyp(code,regs->iir);
3425
3426 - if ((vma->vm_flags & acc_type) != acc_type)
3427 + if ((vma->vm_flags & acc_type) != acc_type) {
3428 +
3429 +#ifdef CONFIG_PAX_PAGEEXEC
3430 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3431 + (address & ~3UL) == instruction_pointer(regs))
3432 + {
3433 + up_read(&mm->mmap_sem);
3434 + switch (pax_handle_fetch_fault(regs)) {
3435 +
3436 +#ifdef CONFIG_PAX_EMUPLT
3437 + case 3:
3438 + return;
3439 +#endif
3440 +
3441 +#ifdef CONFIG_PAX_EMUTRAMP
3442 + case 2:
3443 + return;
3444 +#endif
3445 +
3446 + }
3447 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3448 + do_group_exit(SIGKILL);
3449 + }
3450 +#endif
3451 +
3452 goto bad_area;
3453 + }
3454
3455 /*
3456 * If for any reason at all we couldn't handle the fault, make
3457 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3458 index 02e41b5..ec6e26c 100644
3459 --- a/arch/powerpc/include/asm/atomic.h
3460 +++ b/arch/powerpc/include/asm/atomic.h
3461 @@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3462
3463 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3464
3465 +#define atomic64_read_unchecked(v) atomic64_read(v)
3466 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3467 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3468 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3469 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3470 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3471 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3472 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3473 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3474 +
3475 #endif /* __powerpc64__ */
3476
3477 #endif /* __KERNEL__ */
3478 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3479 index 4b50941..5605819 100644
3480 --- a/arch/powerpc/include/asm/cache.h
3481 +++ b/arch/powerpc/include/asm/cache.h
3482 @@ -3,6 +3,7 @@
3483
3484 #ifdef __KERNEL__
3485
3486 +#include <linux/const.h>
3487
3488 /* bytes per L1 cache line */
3489 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3490 @@ -22,7 +23,7 @@
3491 #define L1_CACHE_SHIFT 7
3492 #endif
3493
3494 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3495 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3496
3497 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3498
3499 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3500 index 3bf9cca..e7457d0 100644
3501 --- a/arch/powerpc/include/asm/elf.h
3502 +++ b/arch/powerpc/include/asm/elf.h
3503 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3504 the loader. We need to make sure that it is out of the way of the program
3505 that it will "exec", and that there is sufficient room for the brk. */
3506
3507 -extern unsigned long randomize_et_dyn(unsigned long base);
3508 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3509 +#define ELF_ET_DYN_BASE (0x20000000)
3510 +
3511 +#ifdef CONFIG_PAX_ASLR
3512 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3513 +
3514 +#ifdef __powerpc64__
3515 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3516 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3517 +#else
3518 +#define PAX_DELTA_MMAP_LEN 15
3519 +#define PAX_DELTA_STACK_LEN 15
3520 +#endif
3521 +#endif
3522
3523 /*
3524 * Our registers are always unsigned longs, whether we're a 32 bit
3525 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3526 (0x7ff >> (PAGE_SHIFT - 12)) : \
3527 (0x3ffff >> (PAGE_SHIFT - 12)))
3528
3529 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3530 -#define arch_randomize_brk arch_randomize_brk
3531 -
3532 #endif /* __KERNEL__ */
3533
3534 /*
3535 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3536 index bca8fdc..61e9580 100644
3537 --- a/arch/powerpc/include/asm/kmap_types.h
3538 +++ b/arch/powerpc/include/asm/kmap_types.h
3539 @@ -27,6 +27,7 @@ enum km_type {
3540 KM_PPC_SYNC_PAGE,
3541 KM_PPC_SYNC_ICACHE,
3542 KM_KDB,
3543 + KM_CLEARPAGE,
3544 KM_TYPE_NR
3545 };
3546
3547 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3548 index d4a7f64..451de1c 100644
3549 --- a/arch/powerpc/include/asm/mman.h
3550 +++ b/arch/powerpc/include/asm/mman.h
3551 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3552 }
3553 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3554
3555 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3556 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3557 {
3558 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3559 }
3560 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3561 index f072e97..b436dee 100644
3562 --- a/arch/powerpc/include/asm/page.h
3563 +++ b/arch/powerpc/include/asm/page.h
3564 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3565 * and needs to be executable. This means the whole heap ends
3566 * up being executable.
3567 */
3568 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3569 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3570 +#define VM_DATA_DEFAULT_FLAGS32 \
3571 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3572 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3573
3574 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3575 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3576 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3577 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3578 #endif
3579
3580 +#define ktla_ktva(addr) (addr)
3581 +#define ktva_ktla(addr) (addr)
3582 +
3583 /*
3584 * Use the top bit of the higher-level page table entries to indicate whether
3585 * the entries we point to contain hugepages. This works because we know that
3586 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3587 index fed85e6..da5c71b 100644
3588 --- a/arch/powerpc/include/asm/page_64.h
3589 +++ b/arch/powerpc/include/asm/page_64.h
3590 @@ -146,15 +146,18 @@ do { \
3591 * stack by default, so in the absence of a PT_GNU_STACK program header
3592 * we turn execute permission off.
3593 */
3594 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3595 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3596 +#define VM_STACK_DEFAULT_FLAGS32 \
3597 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3598 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3599
3600 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3601 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3602
3603 +#ifndef CONFIG_PAX_PAGEEXEC
3604 #define VM_STACK_DEFAULT_FLAGS \
3605 (is_32bit_task() ? \
3606 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3607 +#endif
3608
3609 #include <asm-generic/getorder.h>
3610
3611 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3612 index 292725c..f87ae14 100644
3613 --- a/arch/powerpc/include/asm/pgalloc-64.h
3614 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3615 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3616 #ifndef CONFIG_PPC_64K_PAGES
3617
3618 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3619 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3620
3621 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3622 {
3623 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3624 pud_set(pud, (unsigned long)pmd);
3625 }
3626
3627 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3628 +{
3629 + pud_populate(mm, pud, pmd);
3630 +}
3631 +
3632 #define pmd_populate(mm, pmd, pte_page) \
3633 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3634 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3635 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3636 #else /* CONFIG_PPC_64K_PAGES */
3637
3638 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3639 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3640
3641 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3642 pte_t *pte)
3643 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3644 index 2e0e411..7899c68 100644
3645 --- a/arch/powerpc/include/asm/pgtable.h
3646 +++ b/arch/powerpc/include/asm/pgtable.h
3647 @@ -2,6 +2,7 @@
3648 #define _ASM_POWERPC_PGTABLE_H
3649 #ifdef __KERNEL__
3650
3651 +#include <linux/const.h>
3652 #ifndef __ASSEMBLY__
3653 #include <asm/processor.h> /* For TASK_SIZE */
3654 #include <asm/mmu.h>
3655 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3656 index 4aad413..85d86bf 100644
3657 --- a/arch/powerpc/include/asm/pte-hash32.h
3658 +++ b/arch/powerpc/include/asm/pte-hash32.h
3659 @@ -21,6 +21,7 @@
3660 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3661 #define _PAGE_USER 0x004 /* usermode access allowed */
3662 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3663 +#define _PAGE_EXEC _PAGE_GUARDED
3664 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3665 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3666 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3667 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3668 index 7fdc2c0..e47a9b02d3 100644
3669 --- a/arch/powerpc/include/asm/reg.h
3670 +++ b/arch/powerpc/include/asm/reg.h
3671 @@ -212,6 +212,7 @@
3672 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3673 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3674 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3675 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3676 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3677 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3678 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3679 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
3680 index c377457..3c69fbc 100644
3681 --- a/arch/powerpc/include/asm/system.h
3682 +++ b/arch/powerpc/include/asm/system.h
3683 @@ -539,7 +539,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
3684 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3685 #endif
3686
3687 -extern unsigned long arch_align_stack(unsigned long sp);
3688 +#define arch_align_stack(x) ((x) & ~0xfUL)
3689
3690 /* Used in very early kernel initialization. */
3691 extern unsigned long reloc_offset(void);
3692 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3693 index bd0fb84..a42a14b 100644
3694 --- a/arch/powerpc/include/asm/uaccess.h
3695 +++ b/arch/powerpc/include/asm/uaccess.h
3696 @@ -13,6 +13,8 @@
3697 #define VERIFY_READ 0
3698 #define VERIFY_WRITE 1
3699
3700 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3701 +
3702 /*
3703 * The fs value determines whether argument validity checking should be
3704 * performed or not. If get_fs() == USER_DS, checking is performed, with
3705 @@ -327,52 +329,6 @@ do { \
3706 extern unsigned long __copy_tofrom_user(void __user *to,
3707 const void __user *from, unsigned long size);
3708
3709 -#ifndef __powerpc64__
3710 -
3711 -static inline unsigned long copy_from_user(void *to,
3712 - const void __user *from, unsigned long n)
3713 -{
3714 - unsigned long over;
3715 -
3716 - if (access_ok(VERIFY_READ, from, n))
3717 - return __copy_tofrom_user((__force void __user *)to, from, n);
3718 - if ((unsigned long)from < TASK_SIZE) {
3719 - over = (unsigned long)from + n - TASK_SIZE;
3720 - return __copy_tofrom_user((__force void __user *)to, from,
3721 - n - over) + over;
3722 - }
3723 - return n;
3724 -}
3725 -
3726 -static inline unsigned long copy_to_user(void __user *to,
3727 - const void *from, unsigned long n)
3728 -{
3729 - unsigned long over;
3730 -
3731 - if (access_ok(VERIFY_WRITE, to, n))
3732 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3733 - if ((unsigned long)to < TASK_SIZE) {
3734 - over = (unsigned long)to + n - TASK_SIZE;
3735 - return __copy_tofrom_user(to, (__force void __user *)from,
3736 - n - over) + over;
3737 - }
3738 - return n;
3739 -}
3740 -
3741 -#else /* __powerpc64__ */
3742 -
3743 -#define __copy_in_user(to, from, size) \
3744 - __copy_tofrom_user((to), (from), (size))
3745 -
3746 -extern unsigned long copy_from_user(void *to, const void __user *from,
3747 - unsigned long n);
3748 -extern unsigned long copy_to_user(void __user *to, const void *from,
3749 - unsigned long n);
3750 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3751 - unsigned long n);
3752 -
3753 -#endif /* __powerpc64__ */
3754 -
3755 static inline unsigned long __copy_from_user_inatomic(void *to,
3756 const void __user *from, unsigned long n)
3757 {
3758 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
3759 if (ret == 0)
3760 return 0;
3761 }
3762 +
3763 + if (!__builtin_constant_p(n))
3764 + check_object_size(to, n, false);
3765 +
3766 return __copy_tofrom_user((__force void __user *)to, from, n);
3767 }
3768
3769 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
3770 if (ret == 0)
3771 return 0;
3772 }
3773 +
3774 + if (!__builtin_constant_p(n))
3775 + check_object_size(from, n, true);
3776 +
3777 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3778 }
3779
3780 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
3781 return __copy_to_user_inatomic(to, from, size);
3782 }
3783
3784 +#ifndef __powerpc64__
3785 +
3786 +static inline unsigned long __must_check copy_from_user(void *to,
3787 + const void __user *from, unsigned long n)
3788 +{
3789 + unsigned long over;
3790 +
3791 + if ((long)n < 0)
3792 + return n;
3793 +
3794 + if (access_ok(VERIFY_READ, from, n)) {
3795 + if (!__builtin_constant_p(n))
3796 + check_object_size(to, n, false);
3797 + return __copy_tofrom_user((__force void __user *)to, from, n);
3798 + }
3799 + if ((unsigned long)from < TASK_SIZE) {
3800 + over = (unsigned long)from + n - TASK_SIZE;
3801 + if (!__builtin_constant_p(n - over))
3802 + check_object_size(to, n - over, false);
3803 + return __copy_tofrom_user((__force void __user *)to, from,
3804 + n - over) + over;
3805 + }
3806 + return n;
3807 +}
3808 +
3809 +static inline unsigned long __must_check copy_to_user(void __user *to,
3810 + const void *from, unsigned long n)
3811 +{
3812 + unsigned long over;
3813 +
3814 + if ((long)n < 0)
3815 + return n;
3816 +
3817 + if (access_ok(VERIFY_WRITE, to, n)) {
3818 + if (!__builtin_constant_p(n))
3819 + check_object_size(from, n, true);
3820 + return __copy_tofrom_user(to, (__force void __user *)from, n);
3821 + }
3822 + if ((unsigned long)to < TASK_SIZE) {
3823 + over = (unsigned long)to + n - TASK_SIZE;
3824 + if (!__builtin_constant_p(n))
3825 + check_object_size(from, n - over, true);
3826 + return __copy_tofrom_user(to, (__force void __user *)from,
3827 + n - over) + over;
3828 + }
3829 + return n;
3830 +}
3831 +
3832 +#else /* __powerpc64__ */
3833 +
3834 +#define __copy_in_user(to, from, size) \
3835 + __copy_tofrom_user((to), (from), (size))
3836 +
3837 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
3838 +{
3839 + if ((long)n < 0 || n > INT_MAX)
3840 + return n;
3841 +
3842 + if (!__builtin_constant_p(n))
3843 + check_object_size(to, n, false);
3844 +
3845 + if (likely(access_ok(VERIFY_READ, from, n)))
3846 + n = __copy_from_user(to, from, n);
3847 + else
3848 + memset(to, 0, n);
3849 + return n;
3850 +}
3851 +
3852 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
3853 +{
3854 + if ((long)n < 0 || n > INT_MAX)
3855 + return n;
3856 +
3857 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
3858 + if (!__builtin_constant_p(n))
3859 + check_object_size(from, n, true);
3860 + n = __copy_to_user(to, from, n);
3861 + }
3862 + return n;
3863 +}
3864 +
3865 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
3866 + unsigned long n);
3867 +
3868 +#endif /* __powerpc64__ */
3869 +
3870 extern unsigned long __clear_user(void __user *addr, unsigned long size);
3871
3872 static inline unsigned long clear_user(void __user *addr, unsigned long size)
3873 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
3874 index 429983c..7af363b 100644
3875 --- a/arch/powerpc/kernel/exceptions-64e.S
3876 +++ b/arch/powerpc/kernel/exceptions-64e.S
3877 @@ -587,6 +587,7 @@ storage_fault_common:
3878 std r14,_DAR(r1)
3879 std r15,_DSISR(r1)
3880 addi r3,r1,STACK_FRAME_OVERHEAD
3881 + bl .save_nvgprs
3882 mr r4,r14
3883 mr r5,r15
3884 ld r14,PACA_EXGEN+EX_R14(r13)
3885 @@ -596,8 +597,7 @@ storage_fault_common:
3886 cmpdi r3,0
3887 bne- 1f
3888 b .ret_from_except_lite
3889 -1: bl .save_nvgprs
3890 - mr r5,r3
3891 +1: mr r5,r3
3892 addi r3,r1,STACK_FRAME_OVERHEAD
3893 ld r4,_DAR(r1)
3894 bl .bad_page_fault
3895 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
3896 index 15c5a4f..22a4000 100644
3897 --- a/arch/powerpc/kernel/exceptions-64s.S
3898 +++ b/arch/powerpc/kernel/exceptions-64s.S
3899 @@ -1004,10 +1004,10 @@ handle_page_fault:
3900 11: ld r4,_DAR(r1)
3901 ld r5,_DSISR(r1)
3902 addi r3,r1,STACK_FRAME_OVERHEAD
3903 + bl .save_nvgprs
3904 bl .do_page_fault
3905 cmpdi r3,0
3906 beq+ 13f
3907 - bl .save_nvgprs
3908 mr r5,r3
3909 addi r3,r1,STACK_FRAME_OVERHEAD
3910 lwz r4,_DAR(r1)
3911 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
3912 index 01e2877..a1ba360 100644
3913 --- a/arch/powerpc/kernel/irq.c
3914 +++ b/arch/powerpc/kernel/irq.c
3915 @@ -560,9 +560,6 @@ struct irq_host *irq_alloc_host(struct device_node *of_node,
3916 host->ops = ops;
3917 host->of_node = of_node_get(of_node);
3918
3919 - if (host->ops->match == NULL)
3920 - host->ops->match = default_irq_host_match;
3921 -
3922 raw_spin_lock_irqsave(&irq_big_lock, flags);
3923
3924 /* If it's a legacy controller, check for duplicates and
3925 @@ -635,7 +632,12 @@ struct irq_host *irq_find_host(struct device_node *node)
3926 */
3927 raw_spin_lock_irqsave(&irq_big_lock, flags);
3928 list_for_each_entry(h, &irq_hosts, link)
3929 - if (h->ops->match(h, node)) {
3930 + if (h->ops->match) {
3931 + if (h->ops->match(h, node)) {
3932 + found = h;
3933 + break;
3934 + }
3935 + } else if (default_irq_host_match(h, node)) {
3936 found = h;
3937 break;
3938 }
3939 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
3940 index 0b6d796..d760ddb 100644
3941 --- a/arch/powerpc/kernel/module_32.c
3942 +++ b/arch/powerpc/kernel/module_32.c
3943 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
3944 me->arch.core_plt_section = i;
3945 }
3946 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3947 - printk("Module doesn't contain .plt or .init.plt sections.\n");
3948 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3949 return -ENOEXEC;
3950 }
3951
3952 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
3953
3954 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3955 /* Init, or core PLT? */
3956 - if (location >= mod->module_core
3957 - && location < mod->module_core + mod->core_size)
3958 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3959 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3960 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3961 - else
3962 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3963 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3964 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3965 + else {
3966 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3967 + return ~0UL;
3968 + }
3969
3970 /* Find this entry, or if that fails, the next avail. entry */
3971 while (entry->jump[0]) {
3972 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
3973 index d817ab0..b23b18e 100644
3974 --- a/arch/powerpc/kernel/process.c
3975 +++ b/arch/powerpc/kernel/process.c
3976 @@ -676,8 +676,8 @@ void show_regs(struct pt_regs * regs)
3977 * Lookup NIP late so we have the best change of getting the
3978 * above info out without failing
3979 */
3980 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3981 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3982 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3983 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3984 #endif
3985 show_stack(current, (unsigned long *) regs->gpr[1]);
3986 if (!user_mode(regs))
3987 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3988 newsp = stack[0];
3989 ip = stack[STACK_FRAME_LR_SAVE];
3990 if (!firstframe || ip != lr) {
3991 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3992 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3993 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3994 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3995 - printk(" (%pS)",
3996 + printk(" (%pA)",
3997 (void *)current->ret_stack[curr_frame].ret);
3998 curr_frame--;
3999 }
4000 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4001 struct pt_regs *regs = (struct pt_regs *)
4002 (sp + STACK_FRAME_OVERHEAD);
4003 lr = regs->link;
4004 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4005 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4006 regs->trap, (void *)regs->nip, (void *)lr);
4007 firstframe = 1;
4008 }
4009 @@ -1279,58 +1279,3 @@ void thread_info_cache_init(void)
4010 }
4011
4012 #endif /* THREAD_SHIFT < PAGE_SHIFT */
4013 -
4014 -unsigned long arch_align_stack(unsigned long sp)
4015 -{
4016 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4017 - sp -= get_random_int() & ~PAGE_MASK;
4018 - return sp & ~0xf;
4019 -}
4020 -
4021 -static inline unsigned long brk_rnd(void)
4022 -{
4023 - unsigned long rnd = 0;
4024 -
4025 - /* 8MB for 32bit, 1GB for 64bit */
4026 - if (is_32bit_task())
4027 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4028 - else
4029 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4030 -
4031 - return rnd << PAGE_SHIFT;
4032 -}
4033 -
4034 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4035 -{
4036 - unsigned long base = mm->brk;
4037 - unsigned long ret;
4038 -
4039 -#ifdef CONFIG_PPC_STD_MMU_64
4040 - /*
4041 - * If we are using 1TB segments and we are allowed to randomise
4042 - * the heap, we can put it above 1TB so it is backed by a 1TB
4043 - * segment. Otherwise the heap will be in the bottom 1TB
4044 - * which always uses 256MB segments and this may result in a
4045 - * performance penalty.
4046 - */
4047 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4048 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4049 -#endif
4050 -
4051 - ret = PAGE_ALIGN(base + brk_rnd());
4052 -
4053 - if (ret < mm->brk)
4054 - return mm->brk;
4055 -
4056 - return ret;
4057 -}
4058 -
4059 -unsigned long randomize_et_dyn(unsigned long base)
4060 -{
4061 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4062 -
4063 - if (ret < base)
4064 - return base;
4065 -
4066 - return ret;
4067 -}
4068 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4069 index 836a5a1..27289a3 100644
4070 --- a/arch/powerpc/kernel/signal_32.c
4071 +++ b/arch/powerpc/kernel/signal_32.c
4072 @@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4073 /* Save user registers on the stack */
4074 frame = &rt_sf->uc.uc_mcontext;
4075 addr = frame;
4076 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4077 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4078 if (save_user_regs(regs, frame, 0, 1))
4079 goto badframe;
4080 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4081 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4082 index a50b5ec..547078a 100644
4083 --- a/arch/powerpc/kernel/signal_64.c
4084 +++ b/arch/powerpc/kernel/signal_64.c
4085 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4086 current->thread.fpscr.val = 0;
4087
4088 /* Set up to return from userspace. */
4089 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4090 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4091 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4092 } else {
4093 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4094 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4095 index c091527..5592625 100644
4096 --- a/arch/powerpc/kernel/traps.c
4097 +++ b/arch/powerpc/kernel/traps.c
4098 @@ -131,6 +131,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4099 return flags;
4100 }
4101
4102 +extern void gr_handle_kernel_exploit(void);
4103 +
4104 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4105 int signr)
4106 {
4107 @@ -178,6 +180,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4108 panic("Fatal exception in interrupt");
4109 if (panic_on_oops)
4110 panic("Fatal exception");
4111 +
4112 + gr_handle_kernel_exploit();
4113 +
4114 do_exit(signr);
4115 }
4116
4117 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4118 index 7d14bb6..1305601 100644
4119 --- a/arch/powerpc/kernel/vdso.c
4120 +++ b/arch/powerpc/kernel/vdso.c
4121 @@ -35,6 +35,7 @@
4122 #include <asm/firmware.h>
4123 #include <asm/vdso.h>
4124 #include <asm/vdso_datapage.h>
4125 +#include <asm/mman.h>
4126
4127 #include "setup.h"
4128
4129 @@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4130 vdso_base = VDSO32_MBASE;
4131 #endif
4132
4133 - current->mm->context.vdso_base = 0;
4134 + current->mm->context.vdso_base = ~0UL;
4135
4136 /* vDSO has a problem and was disabled, just don't "enable" it for the
4137 * process
4138 @@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4139 vdso_base = get_unmapped_area(NULL, vdso_base,
4140 (vdso_pages << PAGE_SHIFT) +
4141 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4142 - 0, 0);
4143 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4144 if (IS_ERR_VALUE(vdso_base)) {
4145 rc = vdso_base;
4146 goto fail_mmapsem;
4147 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4148 index 5eea6f3..5d10396 100644
4149 --- a/arch/powerpc/lib/usercopy_64.c
4150 +++ b/arch/powerpc/lib/usercopy_64.c
4151 @@ -9,22 +9,6 @@
4152 #include <linux/module.h>
4153 #include <asm/uaccess.h>
4154
4155 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4156 -{
4157 - if (likely(access_ok(VERIFY_READ, from, n)))
4158 - n = __copy_from_user(to, from, n);
4159 - else
4160 - memset(to, 0, n);
4161 - return n;
4162 -}
4163 -
4164 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4165 -{
4166 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4167 - n = __copy_to_user(to, from, n);
4168 - return n;
4169 -}
4170 -
4171 unsigned long copy_in_user(void __user *to, const void __user *from,
4172 unsigned long n)
4173 {
4174 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4175 return n;
4176 }
4177
4178 -EXPORT_SYMBOL(copy_from_user);
4179 -EXPORT_SYMBOL(copy_to_user);
4180 EXPORT_SYMBOL(copy_in_user);
4181
4182 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4183 index 2f0d1b0..36fb5cc 100644
4184 --- a/arch/powerpc/mm/fault.c
4185 +++ b/arch/powerpc/mm/fault.c
4186 @@ -32,6 +32,10 @@
4187 #include <linux/perf_event.h>
4188 #include <linux/magic.h>
4189 #include <linux/ratelimit.h>
4190 +#include <linux/slab.h>
4191 +#include <linux/pagemap.h>
4192 +#include <linux/compiler.h>
4193 +#include <linux/unistd.h>
4194
4195 #include <asm/firmware.h>
4196 #include <asm/page.h>
4197 @@ -43,6 +47,7 @@
4198 #include <asm/tlbflush.h>
4199 #include <asm/siginfo.h>
4200 #include <mm/mmu_decl.h>
4201 +#include <asm/ptrace.h>
4202
4203 #include "icswx.h"
4204
4205 @@ -68,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4206 }
4207 #endif
4208
4209 +#ifdef CONFIG_PAX_PAGEEXEC
4210 +/*
4211 + * PaX: decide what to do with offenders (regs->nip = fault address)
4212 + *
4213 + * returns 1 when task should be killed
4214 + */
4215 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4216 +{
4217 + return 1;
4218 +}
4219 +
4220 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4221 +{
4222 + unsigned long i;
4223 +
4224 + printk(KERN_ERR "PAX: bytes at PC: ");
4225 + for (i = 0; i < 5; i++) {
4226 + unsigned int c;
4227 + if (get_user(c, (unsigned int __user *)pc+i))
4228 + printk(KERN_CONT "???????? ");
4229 + else
4230 + printk(KERN_CONT "%08x ", c);
4231 + }
4232 + printk("\n");
4233 +}
4234 +#endif
4235 +
4236 /*
4237 * Check whether the instruction at regs->nip is a store using
4238 * an update addressing form which will update r1.
4239 @@ -138,7 +170,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4240 * indicate errors in DSISR but can validly be set in SRR1.
4241 */
4242 if (trap == 0x400)
4243 - error_code &= 0x48200000;
4244 + error_code &= 0x58200000;
4245 else
4246 is_write = error_code & DSISR_ISSTORE;
4247 #else
4248 @@ -276,7 +308,7 @@ good_area:
4249 * "undefined". Of those that can be set, this is the only
4250 * one which seems bad.
4251 */
4252 - if (error_code & 0x10000000)
4253 + if (error_code & DSISR_GUARDED)
4254 /* Guarded storage error. */
4255 goto bad_area;
4256 #endif /* CONFIG_8xx */
4257 @@ -291,7 +323,7 @@ good_area:
4258 * processors use the same I/D cache coherency mechanism
4259 * as embedded.
4260 */
4261 - if (error_code & DSISR_PROTFAULT)
4262 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4263 goto bad_area;
4264 #endif /* CONFIG_PPC_STD_MMU */
4265
4266 @@ -360,6 +392,23 @@ bad_area:
4267 bad_area_nosemaphore:
4268 /* User mode accesses cause a SIGSEGV */
4269 if (user_mode(regs)) {
4270 +
4271 +#ifdef CONFIG_PAX_PAGEEXEC
4272 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4273 +#ifdef CONFIG_PPC_STD_MMU
4274 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4275 +#else
4276 + if (is_exec && regs->nip == address) {
4277 +#endif
4278 + switch (pax_handle_fetch_fault(regs)) {
4279 + }
4280 +
4281 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4282 + do_group_exit(SIGKILL);
4283 + }
4284 + }
4285 +#endif
4286 +
4287 _exception(SIGSEGV, regs, code, address);
4288 return 0;
4289 }
4290 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4291 index 67a42ed..1c7210c 100644
4292 --- a/arch/powerpc/mm/mmap_64.c
4293 +++ b/arch/powerpc/mm/mmap_64.c
4294 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4295 */
4296 if (mmap_is_legacy()) {
4297 mm->mmap_base = TASK_UNMAPPED_BASE;
4298 +
4299 +#ifdef CONFIG_PAX_RANDMMAP
4300 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4301 + mm->mmap_base += mm->delta_mmap;
4302 +#endif
4303 +
4304 mm->get_unmapped_area = arch_get_unmapped_area;
4305 mm->unmap_area = arch_unmap_area;
4306 } else {
4307 mm->mmap_base = mmap_base();
4308 +
4309 +#ifdef CONFIG_PAX_RANDMMAP
4310 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4311 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4312 +#endif
4313 +
4314 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4315 mm->unmap_area = arch_unmap_area_topdown;
4316 }
4317 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4318 index 73709f7..6b90313 100644
4319 --- a/arch/powerpc/mm/slice.c
4320 +++ b/arch/powerpc/mm/slice.c
4321 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4322 if ((mm->task_size - len) < addr)
4323 return 0;
4324 vma = find_vma(mm, addr);
4325 - return (!vma || (addr + len) <= vma->vm_start);
4326 + return check_heap_stack_gap(vma, addr, len);
4327 }
4328
4329 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4330 @@ -256,7 +256,7 @@ full_search:
4331 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4332 continue;
4333 }
4334 - if (!vma || addr + len <= vma->vm_start) {
4335 + if (check_heap_stack_gap(vma, addr, len)) {
4336 /*
4337 * Remember the place where we stopped the search:
4338 */
4339 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4340 }
4341 }
4342
4343 - addr = mm->mmap_base;
4344 - while (addr > len) {
4345 + if (mm->mmap_base < len)
4346 + addr = -ENOMEM;
4347 + else
4348 + addr = mm->mmap_base - len;
4349 +
4350 + while (!IS_ERR_VALUE(addr)) {
4351 /* Go down by chunk size */
4352 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4353 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4354
4355 /* Check for hit with different page size */
4356 mask = slice_range_to_mask(addr, len);
4357 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4358 * return with success:
4359 */
4360 vma = find_vma(mm, addr);
4361 - if (!vma || (addr + len) <= vma->vm_start) {
4362 + if (check_heap_stack_gap(vma, addr, len)) {
4363 /* remember the address as a hint for next time */
4364 if (use_cache)
4365 mm->free_area_cache = addr;
4366 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4367 mm->cached_hole_size = vma->vm_start - addr;
4368
4369 /* try just below the current vma->vm_start */
4370 - addr = vma->vm_start;
4371 + addr = skip_heap_stack_gap(vma, len);
4372 }
4373
4374 /*
4375 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4376 if (fixed && addr > (mm->task_size - len))
4377 return -EINVAL;
4378
4379 +#ifdef CONFIG_PAX_RANDMMAP
4380 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4381 + addr = 0;
4382 +#endif
4383 +
4384 /* If hint, make sure it matches our alignment restrictions */
4385 if (!fixed && addr) {
4386 addr = _ALIGN_UP(addr, 1ul << pshift);
4387 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4388 index 8517d2a..d2738d4 100644
4389 --- a/arch/s390/include/asm/atomic.h
4390 +++ b/arch/s390/include/asm/atomic.h
4391 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4392 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4393 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4394
4395 +#define atomic64_read_unchecked(v) atomic64_read(v)
4396 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4397 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4398 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4399 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4400 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4401 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4402 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4403 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4404 +
4405 #define smp_mb__before_atomic_dec() smp_mb()
4406 #define smp_mb__after_atomic_dec() smp_mb()
4407 #define smp_mb__before_atomic_inc() smp_mb()
4408 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4409 index 2a30d5a..5e5586f 100644
4410 --- a/arch/s390/include/asm/cache.h
4411 +++ b/arch/s390/include/asm/cache.h
4412 @@ -11,8 +11,10 @@
4413 #ifndef __ARCH_S390_CACHE_H
4414 #define __ARCH_S390_CACHE_H
4415
4416 -#define L1_CACHE_BYTES 256
4417 +#include <linux/const.h>
4418 +
4419 #define L1_CACHE_SHIFT 8
4420 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4421 #define NET_SKB_PAD 32
4422
4423 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4424 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4425 index 547f1a6..0b22b53 100644
4426 --- a/arch/s390/include/asm/elf.h
4427 +++ b/arch/s390/include/asm/elf.h
4428 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4429 the loader. We need to make sure that it is out of the way of the program
4430 that it will "exec", and that there is sufficient room for the brk. */
4431
4432 -extern unsigned long randomize_et_dyn(unsigned long base);
4433 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4434 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4435 +
4436 +#ifdef CONFIG_PAX_ASLR
4437 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4438 +
4439 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4440 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4441 +#endif
4442
4443 /* This yields a mask that user programs can use to figure out what
4444 instruction set this CPU supports. */
4445 @@ -211,7 +217,4 @@ struct linux_binprm;
4446 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4447 int arch_setup_additional_pages(struct linux_binprm *, int);
4448
4449 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4450 -#define arch_randomize_brk arch_randomize_brk
4451 -
4452 #endif
4453 diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
4454 index d73cc6b..1a296ad 100644
4455 --- a/arch/s390/include/asm/system.h
4456 +++ b/arch/s390/include/asm/system.h
4457 @@ -260,7 +260,7 @@ extern void (*_machine_restart)(char *command);
4458 extern void (*_machine_halt)(void);
4459 extern void (*_machine_power_off)(void);
4460
4461 -extern unsigned long arch_align_stack(unsigned long sp);
4462 +#define arch_align_stack(x) ((x) & ~0xfUL)
4463
4464 static inline int tprot(unsigned long addr)
4465 {
4466 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4467 index 2b23885..e136e31 100644
4468 --- a/arch/s390/include/asm/uaccess.h
4469 +++ b/arch/s390/include/asm/uaccess.h
4470 @@ -235,6 +235,10 @@ static inline unsigned long __must_check
4471 copy_to_user(void __user *to, const void *from, unsigned long n)
4472 {
4473 might_fault();
4474 +
4475 + if ((long)n < 0)
4476 + return n;
4477 +
4478 if (access_ok(VERIFY_WRITE, to, n))
4479 n = __copy_to_user(to, from, n);
4480 return n;
4481 @@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4482 static inline unsigned long __must_check
4483 __copy_from_user(void *to, const void __user *from, unsigned long n)
4484 {
4485 + if ((long)n < 0)
4486 + return n;
4487 +
4488 if (__builtin_constant_p(n) && (n <= 256))
4489 return uaccess.copy_from_user_small(n, from, to);
4490 else
4491 @@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
4492 unsigned int sz = __compiletime_object_size(to);
4493
4494 might_fault();
4495 +
4496 + if ((long)n < 0)
4497 + return n;
4498 +
4499 if (unlikely(sz != -1 && sz < n)) {
4500 copy_from_user_overflow();
4501 return n;
4502 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4503 index dfcb343..eda788a 100644
4504 --- a/arch/s390/kernel/module.c
4505 +++ b/arch/s390/kernel/module.c
4506 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4507
4508 /* Increase core size by size of got & plt and set start
4509 offsets for got and plt. */
4510 - me->core_size = ALIGN(me->core_size, 4);
4511 - me->arch.got_offset = me->core_size;
4512 - me->core_size += me->arch.got_size;
4513 - me->arch.plt_offset = me->core_size;
4514 - me->core_size += me->arch.plt_size;
4515 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4516 + me->arch.got_offset = me->core_size_rw;
4517 + me->core_size_rw += me->arch.got_size;
4518 + me->arch.plt_offset = me->core_size_rx;
4519 + me->core_size_rx += me->arch.plt_size;
4520 return 0;
4521 }
4522
4523 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4524 if (info->got_initialized == 0) {
4525 Elf_Addr *gotent;
4526
4527 - gotent = me->module_core + me->arch.got_offset +
4528 + gotent = me->module_core_rw + me->arch.got_offset +
4529 info->got_offset;
4530 *gotent = val;
4531 info->got_initialized = 1;
4532 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4533 else if (r_type == R_390_GOTENT ||
4534 r_type == R_390_GOTPLTENT)
4535 *(unsigned int *) loc =
4536 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4537 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4538 else if (r_type == R_390_GOT64 ||
4539 r_type == R_390_GOTPLT64)
4540 *(unsigned long *) loc = val;
4541 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4542 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4543 if (info->plt_initialized == 0) {
4544 unsigned int *ip;
4545 - ip = me->module_core + me->arch.plt_offset +
4546 + ip = me->module_core_rx + me->arch.plt_offset +
4547 info->plt_offset;
4548 #ifndef CONFIG_64BIT
4549 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4550 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4551 val - loc + 0xffffUL < 0x1ffffeUL) ||
4552 (r_type == R_390_PLT32DBL &&
4553 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4554 - val = (Elf_Addr) me->module_core +
4555 + val = (Elf_Addr) me->module_core_rx +
4556 me->arch.plt_offset +
4557 info->plt_offset;
4558 val += rela->r_addend - loc;
4559 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4560 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4561 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4562 val = val + rela->r_addend -
4563 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4564 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4565 if (r_type == R_390_GOTOFF16)
4566 *(unsigned short *) loc = val;
4567 else if (r_type == R_390_GOTOFF32)
4568 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4569 break;
4570 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4571 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4572 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4573 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4574 rela->r_addend - loc;
4575 if (r_type == R_390_GOTPC)
4576 *(unsigned int *) loc = val;
4577 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4578 index e795933..b32563c 100644
4579 --- a/arch/s390/kernel/process.c
4580 +++ b/arch/s390/kernel/process.c
4581 @@ -323,39 +323,3 @@ unsigned long get_wchan(struct task_struct *p)
4582 }
4583 return 0;
4584 }
4585 -
4586 -unsigned long arch_align_stack(unsigned long sp)
4587 -{
4588 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4589 - sp -= get_random_int() & ~PAGE_MASK;
4590 - return sp & ~0xf;
4591 -}
4592 -
4593 -static inline unsigned long brk_rnd(void)
4594 -{
4595 - /* 8MB for 32bit, 1GB for 64bit */
4596 - if (is_32bit_task())
4597 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4598 - else
4599 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4600 -}
4601 -
4602 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4603 -{
4604 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4605 -
4606 - if (ret < mm->brk)
4607 - return mm->brk;
4608 - return ret;
4609 -}
4610 -
4611 -unsigned long randomize_et_dyn(unsigned long base)
4612 -{
4613 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4614 -
4615 - if (!(current->flags & PF_RANDOMIZE))
4616 - return base;
4617 - if (ret < base)
4618 - return base;
4619 - return ret;
4620 -}
4621 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4622 index a0155c0..34cc491 100644
4623 --- a/arch/s390/mm/mmap.c
4624 +++ b/arch/s390/mm/mmap.c
4625 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4626 */
4627 if (mmap_is_legacy()) {
4628 mm->mmap_base = TASK_UNMAPPED_BASE;
4629 +
4630 +#ifdef CONFIG_PAX_RANDMMAP
4631 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4632 + mm->mmap_base += mm->delta_mmap;
4633 +#endif
4634 +
4635 mm->get_unmapped_area = arch_get_unmapped_area;
4636 mm->unmap_area = arch_unmap_area;
4637 } else {
4638 mm->mmap_base = mmap_base();
4639 +
4640 +#ifdef CONFIG_PAX_RANDMMAP
4641 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4642 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4643 +#endif
4644 +
4645 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4646 mm->unmap_area = arch_unmap_area_topdown;
4647 }
4648 @@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4649 */
4650 if (mmap_is_legacy()) {
4651 mm->mmap_base = TASK_UNMAPPED_BASE;
4652 +
4653 +#ifdef CONFIG_PAX_RANDMMAP
4654 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4655 + mm->mmap_base += mm->delta_mmap;
4656 +#endif
4657 +
4658 mm->get_unmapped_area = s390_get_unmapped_area;
4659 mm->unmap_area = arch_unmap_area;
4660 } else {
4661 mm->mmap_base = mmap_base();
4662 +
4663 +#ifdef CONFIG_PAX_RANDMMAP
4664 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4665 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4666 +#endif
4667 +
4668 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4669 mm->unmap_area = arch_unmap_area_topdown;
4670 }
4671 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4672 index ae3d59f..f65f075 100644
4673 --- a/arch/score/include/asm/cache.h
4674 +++ b/arch/score/include/asm/cache.h
4675 @@ -1,7 +1,9 @@
4676 #ifndef _ASM_SCORE_CACHE_H
4677 #define _ASM_SCORE_CACHE_H
4678
4679 +#include <linux/const.h>
4680 +
4681 #define L1_CACHE_SHIFT 4
4682 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4683 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4684
4685 #endif /* _ASM_SCORE_CACHE_H */
4686 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4687 index 589d5c7..669e274 100644
4688 --- a/arch/score/include/asm/system.h
4689 +++ b/arch/score/include/asm/system.h
4690 @@ -17,7 +17,7 @@ do { \
4691 #define finish_arch_switch(prev) do {} while (0)
4692
4693 typedef void (*vi_handler_t)(void);
4694 -extern unsigned long arch_align_stack(unsigned long sp);
4695 +#define arch_align_stack(x) (x)
4696
4697 #define mb() barrier()
4698 #define rmb() barrier()
4699 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4700 index 25d0803..d6c8e36 100644
4701 --- a/arch/score/kernel/process.c
4702 +++ b/arch/score/kernel/process.c
4703 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4704
4705 return task_pt_regs(task)->cp0_epc;
4706 }
4707 -
4708 -unsigned long arch_align_stack(unsigned long sp)
4709 -{
4710 - return sp;
4711 -}
4712 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4713 index ef9e555..331bd29 100644
4714 --- a/arch/sh/include/asm/cache.h
4715 +++ b/arch/sh/include/asm/cache.h
4716 @@ -9,10 +9,11 @@
4717 #define __ASM_SH_CACHE_H
4718 #ifdef __KERNEL__
4719
4720 +#include <linux/const.h>
4721 #include <linux/init.h>
4722 #include <cpu/cache.h>
4723
4724 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4725 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4726
4727 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4728
4729 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4730 index afeb710..d1d1289 100644
4731 --- a/arch/sh/mm/mmap.c
4732 +++ b/arch/sh/mm/mmap.c
4733 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4734 addr = PAGE_ALIGN(addr);
4735
4736 vma = find_vma(mm, addr);
4737 - if (TASK_SIZE - len >= addr &&
4738 - (!vma || addr + len <= vma->vm_start))
4739 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4740 return addr;
4741 }
4742
4743 @@ -106,7 +105,7 @@ full_search:
4744 }
4745 return -ENOMEM;
4746 }
4747 - if (likely(!vma || addr + len <= vma->vm_start)) {
4748 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4749 /*
4750 * Remember the place where we stopped the search:
4751 */
4752 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4753 addr = PAGE_ALIGN(addr);
4754
4755 vma = find_vma(mm, addr);
4756 - if (TASK_SIZE - len >= addr &&
4757 - (!vma || addr + len <= vma->vm_start))
4758 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4759 return addr;
4760 }
4761
4762 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4763 /* make sure it can fit in the remaining address space */
4764 if (likely(addr > len)) {
4765 vma = find_vma(mm, addr-len);
4766 - if (!vma || addr <= vma->vm_start) {
4767 + if (check_heap_stack_gap(vma, addr - len, len)) {
4768 /* remember the address as a hint for next time */
4769 return (mm->free_area_cache = addr-len);
4770 }
4771 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4772 if (unlikely(mm->mmap_base < len))
4773 goto bottomup;
4774
4775 - addr = mm->mmap_base-len;
4776 - if (do_colour_align)
4777 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4778 + addr = mm->mmap_base - len;
4779
4780 do {
4781 + if (do_colour_align)
4782 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4783 /*
4784 * Lookup failure means no vma is above this address,
4785 * else if new region fits below vma->vm_start,
4786 * return with success:
4787 */
4788 vma = find_vma(mm, addr);
4789 - if (likely(!vma || addr+len <= vma->vm_start)) {
4790 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4791 /* remember the address as a hint for next time */
4792 return (mm->free_area_cache = addr);
4793 }
4794 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4795 mm->cached_hole_size = vma->vm_start - addr;
4796
4797 /* try just below the current vma->vm_start */
4798 - addr = vma->vm_start-len;
4799 - if (do_colour_align)
4800 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4801 - } while (likely(len < vma->vm_start));
4802 + addr = skip_heap_stack_gap(vma, len);
4803 + } while (!IS_ERR_VALUE(addr));
4804
4805 bottomup:
4806 /*
4807 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
4808 index eddcfb3..b117d90 100644
4809 --- a/arch/sparc/Makefile
4810 +++ b/arch/sparc/Makefile
4811 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
4812 # Export what is needed by arch/sparc/boot/Makefile
4813 export VMLINUX_INIT VMLINUX_MAIN
4814 VMLINUX_INIT := $(head-y) $(init-y)
4815 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4816 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4817 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4818 VMLINUX_MAIN += $(drivers-y) $(net-y)
4819
4820 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
4821 index 9f421df..b81fc12 100644
4822 --- a/arch/sparc/include/asm/atomic_64.h
4823 +++ b/arch/sparc/include/asm/atomic_64.h
4824 @@ -14,18 +14,40 @@
4825 #define ATOMIC64_INIT(i) { (i) }
4826
4827 #define atomic_read(v) (*(volatile int *)&(v)->counter)
4828 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
4829 +{
4830 + return v->counter;
4831 +}
4832 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
4833 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
4834 +{
4835 + return v->counter;
4836 +}
4837
4838 #define atomic_set(v, i) (((v)->counter) = i)
4839 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
4840 +{
4841 + v->counter = i;
4842 +}
4843 #define atomic64_set(v, i) (((v)->counter) = i)
4844 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
4845 +{
4846 + v->counter = i;
4847 +}
4848
4849 extern void atomic_add(int, atomic_t *);
4850 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
4851 extern void atomic64_add(long, atomic64_t *);
4852 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
4853 extern void atomic_sub(int, atomic_t *);
4854 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
4855 extern void atomic64_sub(long, atomic64_t *);
4856 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
4857
4858 extern int atomic_add_ret(int, atomic_t *);
4859 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
4860 extern long atomic64_add_ret(long, atomic64_t *);
4861 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
4862 extern int atomic_sub_ret(int, atomic_t *);
4863 extern long atomic64_sub_ret(long, atomic64_t *);
4864
4865 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4866 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
4867
4868 #define atomic_inc_return(v) atomic_add_ret(1, v)
4869 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
4870 +{
4871 + return atomic_add_ret_unchecked(1, v);
4872 +}
4873 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
4874 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
4875 +{
4876 + return atomic64_add_ret_unchecked(1, v);
4877 +}
4878
4879 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
4880 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
4881
4882 #define atomic_add_return(i, v) atomic_add_ret(i, v)
4883 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
4884 +{
4885 + return atomic_add_ret_unchecked(i, v);
4886 +}
4887 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
4888 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
4889 +{
4890 + return atomic64_add_ret_unchecked(i, v);
4891 +}
4892
4893 /*
4894 * atomic_inc_and_test - increment and test
4895 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4896 * other cases.
4897 */
4898 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
4899 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
4900 +{
4901 + return atomic_inc_return_unchecked(v) == 0;
4902 +}
4903 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
4904
4905 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
4906 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4907 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
4908
4909 #define atomic_inc(v) atomic_add(1, v)
4910 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
4911 +{
4912 + atomic_add_unchecked(1, v);
4913 +}
4914 #define atomic64_inc(v) atomic64_add(1, v)
4915 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
4916 +{
4917 + atomic64_add_unchecked(1, v);
4918 +}
4919
4920 #define atomic_dec(v) atomic_sub(1, v)
4921 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
4922 +{
4923 + atomic_sub_unchecked(1, v);
4924 +}
4925 #define atomic64_dec(v) atomic64_sub(1, v)
4926 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
4927 +{
4928 + atomic64_sub_unchecked(1, v);
4929 +}
4930
4931 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
4932 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
4933
4934 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
4935 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
4936 +{
4937 + return cmpxchg(&v->counter, old, new);
4938 +}
4939 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
4940 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
4941 +{
4942 + return xchg(&v->counter, new);
4943 +}
4944
4945 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4946 {
4947 - int c, old;
4948 + int c, old, new;
4949 c = atomic_read(v);
4950 for (;;) {
4951 - if (unlikely(c == (u)))
4952 + if (unlikely(c == u))
4953 break;
4954 - old = atomic_cmpxchg((v), c, c + (a));
4955 +
4956 + asm volatile("addcc %2, %0, %0\n"
4957 +
4958 +#ifdef CONFIG_PAX_REFCOUNT
4959 + "tvs %%icc, 6\n"
4960 +#endif
4961 +
4962 + : "=r" (new)
4963 + : "0" (c), "ir" (a)
4964 + : "cc");
4965 +
4966 + old = atomic_cmpxchg(v, c, new);
4967 if (likely(old == c))
4968 break;
4969 c = old;
4970 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4971 #define atomic64_cmpxchg(v, o, n) \
4972 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
4973 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
4974 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
4975 +{
4976 + return xchg(&v->counter, new);
4977 +}
4978
4979 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
4980 {
4981 - long c, old;
4982 + long c, old, new;
4983 c = atomic64_read(v);
4984 for (;;) {
4985 - if (unlikely(c == (u)))
4986 + if (unlikely(c == u))
4987 break;
4988 - old = atomic64_cmpxchg((v), c, c + (a));
4989 +
4990 + asm volatile("addcc %2, %0, %0\n"
4991 +
4992 +#ifdef CONFIG_PAX_REFCOUNT
4993 + "tvs %%xcc, 6\n"
4994 +#endif
4995 +
4996 + : "=r" (new)
4997 + : "0" (c), "ir" (a)
4998 + : "cc");
4999 +
5000 + old = atomic64_cmpxchg(v, c, new);
5001 if (likely(old == c))
5002 break;
5003 c = old;
5004 }
5005 - return c != (u);
5006 + return c != u;
5007 }
5008
5009 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5010 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5011 index 69358b5..9d0d492 100644
5012 --- a/arch/sparc/include/asm/cache.h
5013 +++ b/arch/sparc/include/asm/cache.h
5014 @@ -7,10 +7,12 @@
5015 #ifndef _SPARC_CACHE_H
5016 #define _SPARC_CACHE_H
5017
5018 +#include <linux/const.h>
5019 +
5020 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5021
5022 #define L1_CACHE_SHIFT 5
5023 -#define L1_CACHE_BYTES 32
5024 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5025
5026 #ifdef CONFIG_SPARC32
5027 #define SMP_CACHE_BYTES_SHIFT 5
5028 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5029 index 4269ca6..e3da77f 100644
5030 --- a/arch/sparc/include/asm/elf_32.h
5031 +++ b/arch/sparc/include/asm/elf_32.h
5032 @@ -114,6 +114,13 @@ typedef struct {
5033
5034 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5035
5036 +#ifdef CONFIG_PAX_ASLR
5037 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5038 +
5039 +#define PAX_DELTA_MMAP_LEN 16
5040 +#define PAX_DELTA_STACK_LEN 16
5041 +#endif
5042 +
5043 /* This yields a mask that user programs can use to figure out what
5044 instruction set this cpu supports. This can NOT be done in userspace
5045 on Sparc. */
5046 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5047 index 7df8b7f..4946269 100644
5048 --- a/arch/sparc/include/asm/elf_64.h
5049 +++ b/arch/sparc/include/asm/elf_64.h
5050 @@ -180,6 +180,13 @@ typedef struct {
5051 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5052 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5053
5054 +#ifdef CONFIG_PAX_ASLR
5055 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5056 +
5057 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5058 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5059 +#endif
5060 +
5061 extern unsigned long sparc64_elf_hwcap;
5062 #define ELF_HWCAP sparc64_elf_hwcap
5063
5064 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5065 index ca2b344..c6084f89 100644
5066 --- a/arch/sparc/include/asm/pgalloc_32.h
5067 +++ b/arch/sparc/include/asm/pgalloc_32.h
5068 @@ -37,6 +37,7 @@ BTFIXUPDEF_CALL(void, free_pgd_fast, pgd_t *)
5069 BTFIXUPDEF_CALL(void, pgd_set, pgd_t *, pmd_t *)
5070 #define pgd_set(pgdp,pmdp) BTFIXUP_CALL(pgd_set)(pgdp,pmdp)
5071 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5072 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5073
5074 BTFIXUPDEF_CALL(pmd_t *, pmd_alloc_one, struct mm_struct *, unsigned long)
5075 #define pmd_alloc_one(mm, address) BTFIXUP_CALL(pmd_alloc_one)(mm, address)
5076 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5077 index 40b2d7a..22a665b 100644
5078 --- a/arch/sparc/include/asm/pgalloc_64.h
5079 +++ b/arch/sparc/include/asm/pgalloc_64.h
5080 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5081 }
5082
5083 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5084 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5085
5086 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5087 {
5088 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5089 index a790cc6..091ed94 100644
5090 --- a/arch/sparc/include/asm/pgtable_32.h
5091 +++ b/arch/sparc/include/asm/pgtable_32.h
5092 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5093 BTFIXUPDEF_INT(page_none)
5094 BTFIXUPDEF_INT(page_copy)
5095 BTFIXUPDEF_INT(page_readonly)
5096 +
5097 +#ifdef CONFIG_PAX_PAGEEXEC
5098 +BTFIXUPDEF_INT(page_shared_noexec)
5099 +BTFIXUPDEF_INT(page_copy_noexec)
5100 +BTFIXUPDEF_INT(page_readonly_noexec)
5101 +#endif
5102 +
5103 BTFIXUPDEF_INT(page_kernel)
5104
5105 #define PMD_SHIFT SUN4C_PMD_SHIFT
5106 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
5107 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5108 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5109
5110 +#ifdef CONFIG_PAX_PAGEEXEC
5111 +extern pgprot_t PAGE_SHARED_NOEXEC;
5112 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5113 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5114 +#else
5115 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5116 +# define PAGE_COPY_NOEXEC PAGE_COPY
5117 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5118 +#endif
5119 +
5120 extern unsigned long page_kernel;
5121
5122 #ifdef MODULE
5123 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5124 index f6ae2b2..b03ffc7 100644
5125 --- a/arch/sparc/include/asm/pgtsrmmu.h
5126 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5127 @@ -115,6 +115,13 @@
5128 SRMMU_EXEC | SRMMU_REF)
5129 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5130 SRMMU_EXEC | SRMMU_REF)
5131 +
5132 +#ifdef CONFIG_PAX_PAGEEXEC
5133 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5134 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5135 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5136 +#endif
5137 +
5138 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5139 SRMMU_DIRTY | SRMMU_REF)
5140
5141 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5142 index 9689176..63c18ea 100644
5143 --- a/arch/sparc/include/asm/spinlock_64.h
5144 +++ b/arch/sparc/include/asm/spinlock_64.h
5145 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5146
5147 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5148
5149 -static void inline arch_read_lock(arch_rwlock_t *lock)
5150 +static inline void arch_read_lock(arch_rwlock_t *lock)
5151 {
5152 unsigned long tmp1, tmp2;
5153
5154 __asm__ __volatile__ (
5155 "1: ldsw [%2], %0\n"
5156 " brlz,pn %0, 2f\n"
5157 -"4: add %0, 1, %1\n"
5158 +"4: addcc %0, 1, %1\n"
5159 +
5160 +#ifdef CONFIG_PAX_REFCOUNT
5161 +" tvs %%icc, 6\n"
5162 +#endif
5163 +
5164 " cas [%2], %0, %1\n"
5165 " cmp %0, %1\n"
5166 " bne,pn %%icc, 1b\n"
5167 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5168 " .previous"
5169 : "=&r" (tmp1), "=&r" (tmp2)
5170 : "r" (lock)
5171 - : "memory");
5172 + : "memory", "cc");
5173 }
5174
5175 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5176 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5177 {
5178 int tmp1, tmp2;
5179
5180 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5181 "1: ldsw [%2], %0\n"
5182 " brlz,a,pn %0, 2f\n"
5183 " mov 0, %0\n"
5184 -" add %0, 1, %1\n"
5185 +" addcc %0, 1, %1\n"
5186 +
5187 +#ifdef CONFIG_PAX_REFCOUNT
5188 +" tvs %%icc, 6\n"
5189 +#endif
5190 +
5191 " cas [%2], %0, %1\n"
5192 " cmp %0, %1\n"
5193 " bne,pn %%icc, 1b\n"
5194 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5195 return tmp1;
5196 }
5197
5198 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5199 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5200 {
5201 unsigned long tmp1, tmp2;
5202
5203 __asm__ __volatile__(
5204 "1: lduw [%2], %0\n"
5205 -" sub %0, 1, %1\n"
5206 +" subcc %0, 1, %1\n"
5207 +
5208 +#ifdef CONFIG_PAX_REFCOUNT
5209 +" tvs %%icc, 6\n"
5210 +#endif
5211 +
5212 " cas [%2], %0, %1\n"
5213 " cmp %0, %1\n"
5214 " bne,pn %%xcc, 1b\n"
5215 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5216 : "memory");
5217 }
5218
5219 -static void inline arch_write_lock(arch_rwlock_t *lock)
5220 +static inline void arch_write_lock(arch_rwlock_t *lock)
5221 {
5222 unsigned long mask, tmp1, tmp2;
5223
5224 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5225 : "memory");
5226 }
5227
5228 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5229 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5230 {
5231 __asm__ __volatile__(
5232 " stw %%g0, [%0]"
5233 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5234 : "memory");
5235 }
5236
5237 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5238 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5239 {
5240 unsigned long mask, tmp1, tmp2, result;
5241
5242 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5243 index c2a1080..21ed218 100644
5244 --- a/arch/sparc/include/asm/thread_info_32.h
5245 +++ b/arch/sparc/include/asm/thread_info_32.h
5246 @@ -50,6 +50,8 @@ struct thread_info {
5247 unsigned long w_saved;
5248
5249 struct restart_block restart_block;
5250 +
5251 + unsigned long lowest_stack;
5252 };
5253
5254 /*
5255 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5256 index 01d057f..0a02f7e 100644
5257 --- a/arch/sparc/include/asm/thread_info_64.h
5258 +++ b/arch/sparc/include/asm/thread_info_64.h
5259 @@ -63,6 +63,8 @@ struct thread_info {
5260 struct pt_regs *kern_una_regs;
5261 unsigned int kern_una_insn;
5262
5263 + unsigned long lowest_stack;
5264 +
5265 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5266 };
5267
5268 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5269 index e88fbe5..96b0ce5 100644
5270 --- a/arch/sparc/include/asm/uaccess.h
5271 +++ b/arch/sparc/include/asm/uaccess.h
5272 @@ -1,5 +1,13 @@
5273 #ifndef ___ASM_SPARC_UACCESS_H
5274 #define ___ASM_SPARC_UACCESS_H
5275 +
5276 +#ifdef __KERNEL__
5277 +#ifndef __ASSEMBLY__
5278 +#include <linux/types.h>
5279 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5280 +#endif
5281 +#endif
5282 +
5283 #if defined(__sparc__) && defined(__arch64__)
5284 #include <asm/uaccess_64.h>
5285 #else
5286 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5287 index 8303ac4..07f333d 100644
5288 --- a/arch/sparc/include/asm/uaccess_32.h
5289 +++ b/arch/sparc/include/asm/uaccess_32.h
5290 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5291
5292 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5293 {
5294 - if (n && __access_ok((unsigned long) to, n))
5295 + if ((long)n < 0)
5296 + return n;
5297 +
5298 + if (n && __access_ok((unsigned long) to, n)) {
5299 + if (!__builtin_constant_p(n))
5300 + check_object_size(from, n, true);
5301 return __copy_user(to, (__force void __user *) from, n);
5302 - else
5303 + } else
5304 return n;
5305 }
5306
5307 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5308 {
5309 + if ((long)n < 0)
5310 + return n;
5311 +
5312 + if (!__builtin_constant_p(n))
5313 + check_object_size(from, n, true);
5314 +
5315 return __copy_user(to, (__force void __user *) from, n);
5316 }
5317
5318 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5319 {
5320 - if (n && __access_ok((unsigned long) from, n))
5321 + if ((long)n < 0)
5322 + return n;
5323 +
5324 + if (n && __access_ok((unsigned long) from, n)) {
5325 + if (!__builtin_constant_p(n))
5326 + check_object_size(to, n, false);
5327 return __copy_user((__force void __user *) to, from, n);
5328 - else
5329 + } else
5330 return n;
5331 }
5332
5333 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5334 {
5335 + if ((long)n < 0)
5336 + return n;
5337 +
5338 return __copy_user((__force void __user *) to, from, n);
5339 }
5340
5341 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5342 index 3e1449f..5293a0e 100644
5343 --- a/arch/sparc/include/asm/uaccess_64.h
5344 +++ b/arch/sparc/include/asm/uaccess_64.h
5345 @@ -10,6 +10,7 @@
5346 #include <linux/compiler.h>
5347 #include <linux/string.h>
5348 #include <linux/thread_info.h>
5349 +#include <linux/kernel.h>
5350 #include <asm/asi.h>
5351 #include <asm/system.h>
5352 #include <asm/spitfire.h>
5353 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5354 static inline unsigned long __must_check
5355 copy_from_user(void *to, const void __user *from, unsigned long size)
5356 {
5357 - unsigned long ret = ___copy_from_user(to, from, size);
5358 + unsigned long ret;
5359
5360 + if ((long)size < 0 || size > INT_MAX)
5361 + return size;
5362 +
5363 + if (!__builtin_constant_p(size))
5364 + check_object_size(to, size, false);
5365 +
5366 + ret = ___copy_from_user(to, from, size);
5367 if (unlikely(ret))
5368 ret = copy_from_user_fixup(to, from, size);
5369
5370 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5371 static inline unsigned long __must_check
5372 copy_to_user(void __user *to, const void *from, unsigned long size)
5373 {
5374 - unsigned long ret = ___copy_to_user(to, from, size);
5375 + unsigned long ret;
5376
5377 + if ((long)size < 0 || size > INT_MAX)
5378 + return size;
5379 +
5380 + if (!__builtin_constant_p(size))
5381 + check_object_size(from, size, true);
5382 +
5383 + ret = ___copy_to_user(to, from, size);
5384 if (unlikely(ret))
5385 ret = copy_to_user_fixup(to, from, size);
5386 return ret;
5387 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5388 index cb85458..e063f17 100644
5389 --- a/arch/sparc/kernel/Makefile
5390 +++ b/arch/sparc/kernel/Makefile
5391 @@ -3,7 +3,7 @@
5392 #
5393
5394 asflags-y := -ansi
5395 -ccflags-y := -Werror
5396 +#ccflags-y := -Werror
5397
5398 extra-y := head_$(BITS).o
5399 extra-y += init_task.o
5400 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5401 index f793742..4d880af 100644
5402 --- a/arch/sparc/kernel/process_32.c
5403 +++ b/arch/sparc/kernel/process_32.c
5404 @@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
5405 rw->ins[4], rw->ins[5],
5406 rw->ins[6],
5407 rw->ins[7]);
5408 - printk("%pS\n", (void *) rw->ins[7]);
5409 + printk("%pA\n", (void *) rw->ins[7]);
5410 rw = (struct reg_window32 *) rw->ins[6];
5411 }
5412 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5413 @@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
5414
5415 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5416 r->psr, r->pc, r->npc, r->y, print_tainted());
5417 - printk("PC: <%pS>\n", (void *) r->pc);
5418 + printk("PC: <%pA>\n", (void *) r->pc);
5419 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5420 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5421 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5422 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5423 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5424 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5425 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5426 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5427
5428 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5429 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5430 @@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5431 rw = (struct reg_window32 *) fp;
5432 pc = rw->ins[7];
5433 printk("[%08lx : ", pc);
5434 - printk("%pS ] ", (void *) pc);
5435 + printk("%pA ] ", (void *) pc);
5436 fp = rw->ins[6];
5437 } while (++count < 16);
5438 printk("\n");
5439 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5440 index 39d8b05..d1a7d90 100644
5441 --- a/arch/sparc/kernel/process_64.c
5442 +++ b/arch/sparc/kernel/process_64.c
5443 @@ -182,14 +182,14 @@ static void show_regwindow(struct pt_regs *regs)
5444 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5445 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5446 if (regs->tstate & TSTATE_PRIV)
5447 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5448 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5449 }
5450
5451 void show_regs(struct pt_regs *regs)
5452 {
5453 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5454 regs->tpc, regs->tnpc, regs->y, print_tainted());
5455 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5456 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5457 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5458 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5459 regs->u_regs[3]);
5460 @@ -202,7 +202,7 @@ void show_regs(struct pt_regs *regs)
5461 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5462 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5463 regs->u_regs[15]);
5464 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5465 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5466 show_regwindow(regs);
5467 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5468 }
5469 @@ -287,7 +287,7 @@ void arch_trigger_all_cpu_backtrace(void)
5470 ((tp && tp->task) ? tp->task->pid : -1));
5471
5472 if (gp->tstate & TSTATE_PRIV) {
5473 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5474 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5475 (void *) gp->tpc,
5476 (void *) gp->o7,
5477 (void *) gp->i7,
5478 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5479 index 42b282f..28ce9f2 100644
5480 --- a/arch/sparc/kernel/sys_sparc_32.c
5481 +++ b/arch/sparc/kernel/sys_sparc_32.c
5482 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5483 if (ARCH_SUN4C && len > 0x20000000)
5484 return -ENOMEM;
5485 if (!addr)
5486 - addr = TASK_UNMAPPED_BASE;
5487 + addr = current->mm->mmap_base;
5488
5489 if (flags & MAP_SHARED)
5490 addr = COLOUR_ALIGN(addr);
5491 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5492 }
5493 if (TASK_SIZE - PAGE_SIZE - len < addr)
5494 return -ENOMEM;
5495 - if (!vmm || addr + len <= vmm->vm_start)
5496 + if (check_heap_stack_gap(vmm, addr, len))
5497 return addr;
5498 addr = vmm->vm_end;
5499 if (flags & MAP_SHARED)
5500 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5501 index 232df99..cee1f9c 100644
5502 --- a/arch/sparc/kernel/sys_sparc_64.c
5503 +++ b/arch/sparc/kernel/sys_sparc_64.c
5504 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5505 /* We do not accept a shared mapping if it would violate
5506 * cache aliasing constraints.
5507 */
5508 - if ((flags & MAP_SHARED) &&
5509 + if ((filp || (flags & MAP_SHARED)) &&
5510 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5511 return -EINVAL;
5512 return addr;
5513 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5514 if (filp || (flags & MAP_SHARED))
5515 do_color_align = 1;
5516
5517 +#ifdef CONFIG_PAX_RANDMMAP
5518 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5519 +#endif
5520 +
5521 if (addr) {
5522 if (do_color_align)
5523 addr = COLOUR_ALIGN(addr, pgoff);
5524 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5525 addr = PAGE_ALIGN(addr);
5526
5527 vma = find_vma(mm, addr);
5528 - if (task_size - len >= addr &&
5529 - (!vma || addr + len <= vma->vm_start))
5530 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5531 return addr;
5532 }
5533
5534 if (len > mm->cached_hole_size) {
5535 - start_addr = addr = mm->free_area_cache;
5536 + start_addr = addr = mm->free_area_cache;
5537 } else {
5538 - start_addr = addr = TASK_UNMAPPED_BASE;
5539 + start_addr = addr = mm->mmap_base;
5540 mm->cached_hole_size = 0;
5541 }
5542
5543 @@ -174,14 +177,14 @@ full_search:
5544 vma = find_vma(mm, VA_EXCLUDE_END);
5545 }
5546 if (unlikely(task_size < addr)) {
5547 - if (start_addr != TASK_UNMAPPED_BASE) {
5548 - start_addr = addr = TASK_UNMAPPED_BASE;
5549 + if (start_addr != mm->mmap_base) {
5550 + start_addr = addr = mm->mmap_base;
5551 mm->cached_hole_size = 0;
5552 goto full_search;
5553 }
5554 return -ENOMEM;
5555 }
5556 - if (likely(!vma || addr + len <= vma->vm_start)) {
5557 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5558 /*
5559 * Remember the place where we stopped the search:
5560 */
5561 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5562 /* We do not accept a shared mapping if it would violate
5563 * cache aliasing constraints.
5564 */
5565 - if ((flags & MAP_SHARED) &&
5566 + if ((filp || (flags & MAP_SHARED)) &&
5567 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5568 return -EINVAL;
5569 return addr;
5570 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5571 addr = PAGE_ALIGN(addr);
5572
5573 vma = find_vma(mm, addr);
5574 - if (task_size - len >= addr &&
5575 - (!vma || addr + len <= vma->vm_start))
5576 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5577 return addr;
5578 }
5579
5580 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5581 /* make sure it can fit in the remaining address space */
5582 if (likely(addr > len)) {
5583 vma = find_vma(mm, addr-len);
5584 - if (!vma || addr <= vma->vm_start) {
5585 + if (check_heap_stack_gap(vma, addr - len, len)) {
5586 /* remember the address as a hint for next time */
5587 return (mm->free_area_cache = addr-len);
5588 }
5589 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5590 if (unlikely(mm->mmap_base < len))
5591 goto bottomup;
5592
5593 - addr = mm->mmap_base-len;
5594 - if (do_color_align)
5595 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5596 + addr = mm->mmap_base - len;
5597
5598 do {
5599 + if (do_color_align)
5600 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5601 /*
5602 * Lookup failure means no vma is above this address,
5603 * else if new region fits below vma->vm_start,
5604 * return with success:
5605 */
5606 vma = find_vma(mm, addr);
5607 - if (likely(!vma || addr+len <= vma->vm_start)) {
5608 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5609 /* remember the address as a hint for next time */
5610 return (mm->free_area_cache = addr);
5611 }
5612 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5613 mm->cached_hole_size = vma->vm_start - addr;
5614
5615 /* try just below the current vma->vm_start */
5616 - addr = vma->vm_start-len;
5617 - if (do_color_align)
5618 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5619 - } while (likely(len < vma->vm_start));
5620 + addr = skip_heap_stack_gap(vma, len);
5621 + } while (!IS_ERR_VALUE(addr));
5622
5623 bottomup:
5624 /*
5625 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5626 gap == RLIM_INFINITY ||
5627 sysctl_legacy_va_layout) {
5628 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5629 +
5630 +#ifdef CONFIG_PAX_RANDMMAP
5631 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5632 + mm->mmap_base += mm->delta_mmap;
5633 +#endif
5634 +
5635 mm->get_unmapped_area = arch_get_unmapped_area;
5636 mm->unmap_area = arch_unmap_area;
5637 } else {
5638 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5639 gap = (task_size / 6 * 5);
5640
5641 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5642 +
5643 +#ifdef CONFIG_PAX_RANDMMAP
5644 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5645 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5646 +#endif
5647 +
5648 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5649 mm->unmap_area = arch_unmap_area_topdown;
5650 }
5651 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
5652 index 591f20c..0f1b925 100644
5653 --- a/arch/sparc/kernel/traps_32.c
5654 +++ b/arch/sparc/kernel/traps_32.c
5655 @@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
5656 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
5657 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
5658
5659 +extern void gr_handle_kernel_exploit(void);
5660 +
5661 void die_if_kernel(char *str, struct pt_regs *regs)
5662 {
5663 static int die_counter;
5664 @@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5665 count++ < 30 &&
5666 (((unsigned long) rw) >= PAGE_OFFSET) &&
5667 !(((unsigned long) rw) & 0x7)) {
5668 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
5669 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
5670 (void *) rw->ins[7]);
5671 rw = (struct reg_window32 *)rw->ins[6];
5672 }
5673 }
5674 printk("Instruction DUMP:");
5675 instruction_dump ((unsigned long *) regs->pc);
5676 - if(regs->psr & PSR_PS)
5677 + if(regs->psr & PSR_PS) {
5678 + gr_handle_kernel_exploit();
5679 do_exit(SIGKILL);
5680 + }
5681 do_exit(SIGSEGV);
5682 }
5683
5684 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
5685 index 0cbdaa4..438e4c9 100644
5686 --- a/arch/sparc/kernel/traps_64.c
5687 +++ b/arch/sparc/kernel/traps_64.c
5688 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
5689 i + 1,
5690 p->trapstack[i].tstate, p->trapstack[i].tpc,
5691 p->trapstack[i].tnpc, p->trapstack[i].tt);
5692 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
5693 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
5694 }
5695 }
5696
5697 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
5698
5699 lvl -= 0x100;
5700 if (regs->tstate & TSTATE_PRIV) {
5701 +
5702 +#ifdef CONFIG_PAX_REFCOUNT
5703 + if (lvl == 6)
5704 + pax_report_refcount_overflow(regs);
5705 +#endif
5706 +
5707 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
5708 die_if_kernel(buffer, regs);
5709 }
5710 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
5711 void bad_trap_tl1(struct pt_regs *regs, long lvl)
5712 {
5713 char buffer[32];
5714 -
5715 +
5716 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
5717 0, lvl, SIGTRAP) == NOTIFY_STOP)
5718 return;
5719
5720 +#ifdef CONFIG_PAX_REFCOUNT
5721 + if (lvl == 6)
5722 + pax_report_refcount_overflow(regs);
5723 +#endif
5724 +
5725 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
5726
5727 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
5728 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
5729 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
5730 printk("%s" "ERROR(%d): ",
5731 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
5732 - printk("TPC<%pS>\n", (void *) regs->tpc);
5733 + printk("TPC<%pA>\n", (void *) regs->tpc);
5734 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
5735 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
5736 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
5737 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5738 smp_processor_id(),
5739 (type & 0x1) ? 'I' : 'D',
5740 regs->tpc);
5741 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
5742 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
5743 panic("Irrecoverable Cheetah+ parity error.");
5744 }
5745
5746 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5747 smp_processor_id(),
5748 (type & 0x1) ? 'I' : 'D',
5749 regs->tpc);
5750 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
5751 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
5752 }
5753
5754 struct sun4v_error_entry {
5755 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
5756
5757 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
5758 regs->tpc, tl);
5759 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
5760 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
5761 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5762 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
5763 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
5764 (void *) regs->u_regs[UREG_I7]);
5765 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
5766 "pte[%lx] error[%lx]\n",
5767 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
5768
5769 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
5770 regs->tpc, tl);
5771 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
5772 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
5773 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5774 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
5775 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
5776 (void *) regs->u_regs[UREG_I7]);
5777 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
5778 "pte[%lx] error[%lx]\n",
5779 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5780 fp = (unsigned long)sf->fp + STACK_BIAS;
5781 }
5782
5783 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5784 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5785 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5786 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
5787 int index = tsk->curr_ret_stack;
5788 if (tsk->ret_stack && index >= graph) {
5789 pc = tsk->ret_stack[index - graph].ret;
5790 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5791 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5792 graph++;
5793 }
5794 }
5795 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
5796 return (struct reg_window *) (fp + STACK_BIAS);
5797 }
5798
5799 +extern void gr_handle_kernel_exploit(void);
5800 +
5801 void die_if_kernel(char *str, struct pt_regs *regs)
5802 {
5803 static int die_counter;
5804 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5805 while (rw &&
5806 count++ < 30 &&
5807 kstack_valid(tp, (unsigned long) rw)) {
5808 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
5809 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
5810 (void *) rw->ins[7]);
5811
5812 rw = kernel_stack_up(rw);
5813 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5814 }
5815 user_instruction_dump ((unsigned int __user *) regs->tpc);
5816 }
5817 - if (regs->tstate & TSTATE_PRIV)
5818 + if (regs->tstate & TSTATE_PRIV) {
5819 + gr_handle_kernel_exploit();
5820 do_exit(SIGKILL);
5821 + }
5822 do_exit(SIGSEGV);
5823 }
5824 EXPORT_SYMBOL(die_if_kernel);
5825 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
5826 index 76e4ac1..78f8bb1 100644
5827 --- a/arch/sparc/kernel/unaligned_64.c
5828 +++ b/arch/sparc/kernel/unaligned_64.c
5829 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
5830 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
5831
5832 if (__ratelimit(&ratelimit)) {
5833 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
5834 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
5835 regs->tpc, (void *) regs->tpc);
5836 }
5837 }
5838 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
5839 index a3fc437..fea9957 100644
5840 --- a/arch/sparc/lib/Makefile
5841 +++ b/arch/sparc/lib/Makefile
5842 @@ -2,7 +2,7 @@
5843 #
5844
5845 asflags-y := -ansi -DST_DIV0=0x02
5846 -ccflags-y := -Werror
5847 +#ccflags-y := -Werror
5848
5849 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
5850 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
5851 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
5852 index 59186e0..f747d7a 100644
5853 --- a/arch/sparc/lib/atomic_64.S
5854 +++ b/arch/sparc/lib/atomic_64.S
5855 @@ -18,7 +18,12 @@
5856 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5857 BACKOFF_SETUP(%o2)
5858 1: lduw [%o1], %g1
5859 - add %g1, %o0, %g7
5860 + addcc %g1, %o0, %g7
5861 +
5862 +#ifdef CONFIG_PAX_REFCOUNT
5863 + tvs %icc, 6
5864 +#endif
5865 +
5866 cas [%o1], %g1, %g7
5867 cmp %g1, %g7
5868 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5869 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5870 2: BACKOFF_SPIN(%o2, %o3, 1b)
5871 .size atomic_add, .-atomic_add
5872
5873 + .globl atomic_add_unchecked
5874 + .type atomic_add_unchecked,#function
5875 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5876 + BACKOFF_SETUP(%o2)
5877 +1: lduw [%o1], %g1
5878 + add %g1, %o0, %g7
5879 + cas [%o1], %g1, %g7
5880 + cmp %g1, %g7
5881 + bne,pn %icc, 2f
5882 + nop
5883 + retl
5884 + nop
5885 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5886 + .size atomic_add_unchecked, .-atomic_add_unchecked
5887 +
5888 .globl atomic_sub
5889 .type atomic_sub,#function
5890 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5891 BACKOFF_SETUP(%o2)
5892 1: lduw [%o1], %g1
5893 - sub %g1, %o0, %g7
5894 + subcc %g1, %o0, %g7
5895 +
5896 +#ifdef CONFIG_PAX_REFCOUNT
5897 + tvs %icc, 6
5898 +#endif
5899 +
5900 cas [%o1], %g1, %g7
5901 cmp %g1, %g7
5902 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5903 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5904 2: BACKOFF_SPIN(%o2, %o3, 1b)
5905 .size atomic_sub, .-atomic_sub
5906
5907 + .globl atomic_sub_unchecked
5908 + .type atomic_sub_unchecked,#function
5909 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5910 + BACKOFF_SETUP(%o2)
5911 +1: lduw [%o1], %g1
5912 + sub %g1, %o0, %g7
5913 + cas [%o1], %g1, %g7
5914 + cmp %g1, %g7
5915 + bne,pn %icc, 2f
5916 + nop
5917 + retl
5918 + nop
5919 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5920 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
5921 +
5922 .globl atomic_add_ret
5923 .type atomic_add_ret,#function
5924 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5925 BACKOFF_SETUP(%o2)
5926 1: lduw [%o1], %g1
5927 - add %g1, %o0, %g7
5928 + addcc %g1, %o0, %g7
5929 +
5930 +#ifdef CONFIG_PAX_REFCOUNT
5931 + tvs %icc, 6
5932 +#endif
5933 +
5934 cas [%o1], %g1, %g7
5935 cmp %g1, %g7
5936 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5937 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5938 2: BACKOFF_SPIN(%o2, %o3, 1b)
5939 .size atomic_add_ret, .-atomic_add_ret
5940
5941 + .globl atomic_add_ret_unchecked
5942 + .type atomic_add_ret_unchecked,#function
5943 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5944 + BACKOFF_SETUP(%o2)
5945 +1: lduw [%o1], %g1
5946 + addcc %g1, %o0, %g7
5947 + cas [%o1], %g1, %g7
5948 + cmp %g1, %g7
5949 + bne,pn %icc, 2f
5950 + add %g7, %o0, %g7
5951 + sra %g7, 0, %o0
5952 + retl
5953 + nop
5954 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5955 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
5956 +
5957 .globl atomic_sub_ret
5958 .type atomic_sub_ret,#function
5959 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5960 BACKOFF_SETUP(%o2)
5961 1: lduw [%o1], %g1
5962 - sub %g1, %o0, %g7
5963 + subcc %g1, %o0, %g7
5964 +
5965 +#ifdef CONFIG_PAX_REFCOUNT
5966 + tvs %icc, 6
5967 +#endif
5968 +
5969 cas [%o1], %g1, %g7
5970 cmp %g1, %g7
5971 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5972 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5973 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5974 BACKOFF_SETUP(%o2)
5975 1: ldx [%o1], %g1
5976 - add %g1, %o0, %g7
5977 + addcc %g1, %o0, %g7
5978 +
5979 +#ifdef CONFIG_PAX_REFCOUNT
5980 + tvs %xcc, 6
5981 +#endif
5982 +
5983 casx [%o1], %g1, %g7
5984 cmp %g1, %g7
5985 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5986 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5987 2: BACKOFF_SPIN(%o2, %o3, 1b)
5988 .size atomic64_add, .-atomic64_add
5989
5990 + .globl atomic64_add_unchecked
5991 + .type atomic64_add_unchecked,#function
5992 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5993 + BACKOFF_SETUP(%o2)
5994 +1: ldx [%o1], %g1
5995 + addcc %g1, %o0, %g7
5996 + casx [%o1], %g1, %g7
5997 + cmp %g1, %g7
5998 + bne,pn %xcc, 2f
5999 + nop
6000 + retl
6001 + nop
6002 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6003 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
6004 +
6005 .globl atomic64_sub
6006 .type atomic64_sub,#function
6007 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6008 BACKOFF_SETUP(%o2)
6009 1: ldx [%o1], %g1
6010 - sub %g1, %o0, %g7
6011 + subcc %g1, %o0, %g7
6012 +
6013 +#ifdef CONFIG_PAX_REFCOUNT
6014 + tvs %xcc, 6
6015 +#endif
6016 +
6017 casx [%o1], %g1, %g7
6018 cmp %g1, %g7
6019 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6020 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6021 2: BACKOFF_SPIN(%o2, %o3, 1b)
6022 .size atomic64_sub, .-atomic64_sub
6023
6024 + .globl atomic64_sub_unchecked
6025 + .type atomic64_sub_unchecked,#function
6026 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6027 + BACKOFF_SETUP(%o2)
6028 +1: ldx [%o1], %g1
6029 + subcc %g1, %o0, %g7
6030 + casx [%o1], %g1, %g7
6031 + cmp %g1, %g7
6032 + bne,pn %xcc, 2f
6033 + nop
6034 + retl
6035 + nop
6036 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6037 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6038 +
6039 .globl atomic64_add_ret
6040 .type atomic64_add_ret,#function
6041 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6042 BACKOFF_SETUP(%o2)
6043 1: ldx [%o1], %g1
6044 - add %g1, %o0, %g7
6045 + addcc %g1, %o0, %g7
6046 +
6047 +#ifdef CONFIG_PAX_REFCOUNT
6048 + tvs %xcc, 6
6049 +#endif
6050 +
6051 casx [%o1], %g1, %g7
6052 cmp %g1, %g7
6053 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6054 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6055 2: BACKOFF_SPIN(%o2, %o3, 1b)
6056 .size atomic64_add_ret, .-atomic64_add_ret
6057
6058 + .globl atomic64_add_ret_unchecked
6059 + .type atomic64_add_ret_unchecked,#function
6060 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6061 + BACKOFF_SETUP(%o2)
6062 +1: ldx [%o1], %g1
6063 + addcc %g1, %o0, %g7
6064 + casx [%o1], %g1, %g7
6065 + cmp %g1, %g7
6066 + bne,pn %xcc, 2f
6067 + add %g7, %o0, %g7
6068 + mov %g7, %o0
6069 + retl
6070 + nop
6071 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6072 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6073 +
6074 .globl atomic64_sub_ret
6075 .type atomic64_sub_ret,#function
6076 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6077 BACKOFF_SETUP(%o2)
6078 1: ldx [%o1], %g1
6079 - sub %g1, %o0, %g7
6080 + subcc %g1, %o0, %g7
6081 +
6082 +#ifdef CONFIG_PAX_REFCOUNT
6083 + tvs %xcc, 6
6084 +#endif
6085 +
6086 casx [%o1], %g1, %g7
6087 cmp %g1, %g7
6088 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6089 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6090 index f73c224..662af10 100644
6091 --- a/arch/sparc/lib/ksyms.c
6092 +++ b/arch/sparc/lib/ksyms.c
6093 @@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
6094
6095 /* Atomic counter implementation. */
6096 EXPORT_SYMBOL(atomic_add);
6097 +EXPORT_SYMBOL(atomic_add_unchecked);
6098 EXPORT_SYMBOL(atomic_add_ret);
6099 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6100 EXPORT_SYMBOL(atomic_sub);
6101 +EXPORT_SYMBOL(atomic_sub_unchecked);
6102 EXPORT_SYMBOL(atomic_sub_ret);
6103 EXPORT_SYMBOL(atomic64_add);
6104 +EXPORT_SYMBOL(atomic64_add_unchecked);
6105 EXPORT_SYMBOL(atomic64_add_ret);
6106 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6107 EXPORT_SYMBOL(atomic64_sub);
6108 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6109 EXPORT_SYMBOL(atomic64_sub_ret);
6110
6111 /* Atomic bit operations. */
6112 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6113 index 301421c..e2535d1 100644
6114 --- a/arch/sparc/mm/Makefile
6115 +++ b/arch/sparc/mm/Makefile
6116 @@ -2,7 +2,7 @@
6117 #
6118
6119 asflags-y := -ansi
6120 -ccflags-y := -Werror
6121 +#ccflags-y := -Werror
6122
6123 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6124 obj-y += fault_$(BITS).o
6125 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6126 index 8023fd7..c8e89e9 100644
6127 --- a/arch/sparc/mm/fault_32.c
6128 +++ b/arch/sparc/mm/fault_32.c
6129 @@ -21,6 +21,9 @@
6130 #include <linux/perf_event.h>
6131 #include <linux/interrupt.h>
6132 #include <linux/kdebug.h>
6133 +#include <linux/slab.h>
6134 +#include <linux/pagemap.h>
6135 +#include <linux/compiler.h>
6136
6137 #include <asm/system.h>
6138 #include <asm/page.h>
6139 @@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6140 return safe_compute_effective_address(regs, insn);
6141 }
6142
6143 +#ifdef CONFIG_PAX_PAGEEXEC
6144 +#ifdef CONFIG_PAX_DLRESOLVE
6145 +static void pax_emuplt_close(struct vm_area_struct *vma)
6146 +{
6147 + vma->vm_mm->call_dl_resolve = 0UL;
6148 +}
6149 +
6150 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6151 +{
6152 + unsigned int *kaddr;
6153 +
6154 + vmf->page = alloc_page(GFP_HIGHUSER);
6155 + if (!vmf->page)
6156 + return VM_FAULT_OOM;
6157 +
6158 + kaddr = kmap(vmf->page);
6159 + memset(kaddr, 0, PAGE_SIZE);
6160 + kaddr[0] = 0x9DE3BFA8U; /* save */
6161 + flush_dcache_page(vmf->page);
6162 + kunmap(vmf->page);
6163 + return VM_FAULT_MAJOR;
6164 +}
6165 +
6166 +static const struct vm_operations_struct pax_vm_ops = {
6167 + .close = pax_emuplt_close,
6168 + .fault = pax_emuplt_fault
6169 +};
6170 +
6171 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6172 +{
6173 + int ret;
6174 +
6175 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6176 + vma->vm_mm = current->mm;
6177 + vma->vm_start = addr;
6178 + vma->vm_end = addr + PAGE_SIZE;
6179 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6180 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6181 + vma->vm_ops = &pax_vm_ops;
6182 +
6183 + ret = insert_vm_struct(current->mm, vma);
6184 + if (ret)
6185 + return ret;
6186 +
6187 + ++current->mm->total_vm;
6188 + return 0;
6189 +}
6190 +#endif
6191 +
6192 +/*
6193 + * PaX: decide what to do with offenders (regs->pc = fault address)
6194 + *
6195 + * returns 1 when task should be killed
6196 + * 2 when patched PLT trampoline was detected
6197 + * 3 when unpatched PLT trampoline was detected
6198 + */
6199 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6200 +{
6201 +
6202 +#ifdef CONFIG_PAX_EMUPLT
6203 + int err;
6204 +
6205 + do { /* PaX: patched PLT emulation #1 */
6206 + unsigned int sethi1, sethi2, jmpl;
6207 +
6208 + err = get_user(sethi1, (unsigned int *)regs->pc);
6209 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6210 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6211 +
6212 + if (err)
6213 + break;
6214 +
6215 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6216 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6217 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6218 + {
6219 + unsigned int addr;
6220 +
6221 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6222 + addr = regs->u_regs[UREG_G1];
6223 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6224 + regs->pc = addr;
6225 + regs->npc = addr+4;
6226 + return 2;
6227 + }
6228 + } while (0);
6229 +
6230 + { /* PaX: patched PLT emulation #2 */
6231 + unsigned int ba;
6232 +
6233 + err = get_user(ba, (unsigned int *)regs->pc);
6234 +
6235 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6236 + unsigned int addr;
6237 +
6238 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6239 + regs->pc = addr;
6240 + regs->npc = addr+4;
6241 + return 2;
6242 + }
6243 + }
6244 +
6245 + do { /* PaX: patched PLT emulation #3 */
6246 + unsigned int sethi, jmpl, nop;
6247 +
6248 + err = get_user(sethi, (unsigned int *)regs->pc);
6249 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6250 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6251 +
6252 + if (err)
6253 + break;
6254 +
6255 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6256 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6257 + nop == 0x01000000U)
6258 + {
6259 + unsigned int addr;
6260 +
6261 + addr = (sethi & 0x003FFFFFU) << 10;
6262 + regs->u_regs[UREG_G1] = addr;
6263 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6264 + regs->pc = addr;
6265 + regs->npc = addr+4;
6266 + return 2;
6267 + }
6268 + } while (0);
6269 +
6270 + do { /* PaX: unpatched PLT emulation step 1 */
6271 + unsigned int sethi, ba, nop;
6272 +
6273 + err = get_user(sethi, (unsigned int *)regs->pc);
6274 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6275 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6276 +
6277 + if (err)
6278 + break;
6279 +
6280 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6281 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6282 + nop == 0x01000000U)
6283 + {
6284 + unsigned int addr, save, call;
6285 +
6286 + if ((ba & 0xFFC00000U) == 0x30800000U)
6287 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6288 + else
6289 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6290 +
6291 + err = get_user(save, (unsigned int *)addr);
6292 + err |= get_user(call, (unsigned int *)(addr+4));
6293 + err |= get_user(nop, (unsigned int *)(addr+8));
6294 + if (err)
6295 + break;
6296 +
6297 +#ifdef CONFIG_PAX_DLRESOLVE
6298 + if (save == 0x9DE3BFA8U &&
6299 + (call & 0xC0000000U) == 0x40000000U &&
6300 + nop == 0x01000000U)
6301 + {
6302 + struct vm_area_struct *vma;
6303 + unsigned long call_dl_resolve;
6304 +
6305 + down_read(&current->mm->mmap_sem);
6306 + call_dl_resolve = current->mm->call_dl_resolve;
6307 + up_read(&current->mm->mmap_sem);
6308 + if (likely(call_dl_resolve))
6309 + goto emulate;
6310 +
6311 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6312 +
6313 + down_write(&current->mm->mmap_sem);
6314 + if (current->mm->call_dl_resolve) {
6315 + call_dl_resolve = current->mm->call_dl_resolve;
6316 + up_write(&current->mm->mmap_sem);
6317 + if (vma)
6318 + kmem_cache_free(vm_area_cachep, vma);
6319 + goto emulate;
6320 + }
6321 +
6322 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6323 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6324 + up_write(&current->mm->mmap_sem);
6325 + if (vma)
6326 + kmem_cache_free(vm_area_cachep, vma);
6327 + return 1;
6328 + }
6329 +
6330 + if (pax_insert_vma(vma, call_dl_resolve)) {
6331 + up_write(&current->mm->mmap_sem);
6332 + kmem_cache_free(vm_area_cachep, vma);
6333 + return 1;
6334 + }
6335 +
6336 + current->mm->call_dl_resolve = call_dl_resolve;
6337 + up_write(&current->mm->mmap_sem);
6338 +
6339 +emulate:
6340 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6341 + regs->pc = call_dl_resolve;
6342 + regs->npc = addr+4;
6343 + return 3;
6344 + }
6345 +#endif
6346 +
6347 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6348 + if ((save & 0xFFC00000U) == 0x05000000U &&
6349 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6350 + nop == 0x01000000U)
6351 + {
6352 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6353 + regs->u_regs[UREG_G2] = addr + 4;
6354 + addr = (save & 0x003FFFFFU) << 10;
6355 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6356 + regs->pc = addr;
6357 + regs->npc = addr+4;
6358 + return 3;
6359 + }
6360 + }
6361 + } while (0);
6362 +
6363 + do { /* PaX: unpatched PLT emulation step 2 */
6364 + unsigned int save, call, nop;
6365 +
6366 + err = get_user(save, (unsigned int *)(regs->pc-4));
6367 + err |= get_user(call, (unsigned int *)regs->pc);
6368 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6369 + if (err)
6370 + break;
6371 +
6372 + if (save == 0x9DE3BFA8U &&
6373 + (call & 0xC0000000U) == 0x40000000U &&
6374 + nop == 0x01000000U)
6375 + {
6376 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6377 +
6378 + regs->u_regs[UREG_RETPC] = regs->pc;
6379 + regs->pc = dl_resolve;
6380 + regs->npc = dl_resolve+4;
6381 + return 3;
6382 + }
6383 + } while (0);
6384 +#endif
6385 +
6386 + return 1;
6387 +}
6388 +
6389 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6390 +{
6391 + unsigned long i;
6392 +
6393 + printk(KERN_ERR "PAX: bytes at PC: ");
6394 + for (i = 0; i < 8; i++) {
6395 + unsigned int c;
6396 + if (get_user(c, (unsigned int *)pc+i))
6397 + printk(KERN_CONT "???????? ");
6398 + else
6399 + printk(KERN_CONT "%08x ", c);
6400 + }
6401 + printk("\n");
6402 +}
6403 +#endif
6404 +
6405 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6406 int text_fault)
6407 {
6408 @@ -280,6 +545,24 @@ good_area:
6409 if(!(vma->vm_flags & VM_WRITE))
6410 goto bad_area;
6411 } else {
6412 +
6413 +#ifdef CONFIG_PAX_PAGEEXEC
6414 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6415 + up_read(&mm->mmap_sem);
6416 + switch (pax_handle_fetch_fault(regs)) {
6417 +
6418 +#ifdef CONFIG_PAX_EMUPLT
6419 + case 2:
6420 + case 3:
6421 + return;
6422 +#endif
6423 +
6424 + }
6425 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6426 + do_group_exit(SIGKILL);
6427 + }
6428 +#endif
6429 +
6430 /* Allow reads even for write-only mappings */
6431 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6432 goto bad_area;
6433 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6434 index 504c062..6fcb9c6 100644
6435 --- a/arch/sparc/mm/fault_64.c
6436 +++ b/arch/sparc/mm/fault_64.c
6437 @@ -21,6 +21,9 @@
6438 #include <linux/kprobes.h>
6439 #include <linux/kdebug.h>
6440 #include <linux/percpu.h>
6441 +#include <linux/slab.h>
6442 +#include <linux/pagemap.h>
6443 +#include <linux/compiler.h>
6444
6445 #include <asm/page.h>
6446 #include <asm/pgtable.h>
6447 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6448 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6449 regs->tpc);
6450 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6451 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6452 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6453 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6454 dump_stack();
6455 unhandled_fault(regs->tpc, current, regs);
6456 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6457 show_regs(regs);
6458 }
6459
6460 +#ifdef CONFIG_PAX_PAGEEXEC
6461 +#ifdef CONFIG_PAX_DLRESOLVE
6462 +static void pax_emuplt_close(struct vm_area_struct *vma)
6463 +{
6464 + vma->vm_mm->call_dl_resolve = 0UL;
6465 +}
6466 +
6467 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6468 +{
6469 + unsigned int *kaddr;
6470 +
6471 + vmf->page = alloc_page(GFP_HIGHUSER);
6472 + if (!vmf->page)
6473 + return VM_FAULT_OOM;
6474 +
6475 + kaddr = kmap(vmf->page);
6476 + memset(kaddr, 0, PAGE_SIZE);
6477 + kaddr[0] = 0x9DE3BFA8U; /* save */
6478 + flush_dcache_page(vmf->page);
6479 + kunmap(vmf->page);
6480 + return VM_FAULT_MAJOR;
6481 +}
6482 +
6483 +static const struct vm_operations_struct pax_vm_ops = {
6484 + .close = pax_emuplt_close,
6485 + .fault = pax_emuplt_fault
6486 +};
6487 +
6488 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6489 +{
6490 + int ret;
6491 +
6492 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6493 + vma->vm_mm = current->mm;
6494 + vma->vm_start = addr;
6495 + vma->vm_end = addr + PAGE_SIZE;
6496 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6497 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6498 + vma->vm_ops = &pax_vm_ops;
6499 +
6500 + ret = insert_vm_struct(current->mm, vma);
6501 + if (ret)
6502 + return ret;
6503 +
6504 + ++current->mm->total_vm;
6505 + return 0;
6506 +}
6507 +#endif
6508 +
6509 +/*
6510 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6511 + *
6512 + * returns 1 when task should be killed
6513 + * 2 when patched PLT trampoline was detected
6514 + * 3 when unpatched PLT trampoline was detected
6515 + */
6516 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6517 +{
6518 +
6519 +#ifdef CONFIG_PAX_EMUPLT
6520 + int err;
6521 +
6522 + do { /* PaX: patched PLT emulation #1 */
6523 + unsigned int sethi1, sethi2, jmpl;
6524 +
6525 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6526 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6527 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6528 +
6529 + if (err)
6530 + break;
6531 +
6532 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6533 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6534 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6535 + {
6536 + unsigned long addr;
6537 +
6538 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6539 + addr = regs->u_regs[UREG_G1];
6540 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6541 +
6542 + if (test_thread_flag(TIF_32BIT))
6543 + addr &= 0xFFFFFFFFUL;
6544 +
6545 + regs->tpc = addr;
6546 + regs->tnpc = addr+4;
6547 + return 2;
6548 + }
6549 + } while (0);
6550 +
6551 + { /* PaX: patched PLT emulation #2 */
6552 + unsigned int ba;
6553 +
6554 + err = get_user(ba, (unsigned int *)regs->tpc);
6555 +
6556 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6557 + unsigned long addr;
6558 +
6559 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6560 +
6561 + if (test_thread_flag(TIF_32BIT))
6562 + addr &= 0xFFFFFFFFUL;
6563 +
6564 + regs->tpc = addr;
6565 + regs->tnpc = addr+4;
6566 + return 2;
6567 + }
6568 + }
6569 +
6570 + do { /* PaX: patched PLT emulation #3 */
6571 + unsigned int sethi, jmpl, nop;
6572 +
6573 + err = get_user(sethi, (unsigned int *)regs->tpc);
6574 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6575 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6576 +
6577 + if (err)
6578 + break;
6579 +
6580 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6581 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6582 + nop == 0x01000000U)
6583 + {
6584 + unsigned long addr;
6585 +
6586 + addr = (sethi & 0x003FFFFFU) << 10;
6587 + regs->u_regs[UREG_G1] = addr;
6588 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6589 +
6590 + if (test_thread_flag(TIF_32BIT))
6591 + addr &= 0xFFFFFFFFUL;
6592 +
6593 + regs->tpc = addr;
6594 + regs->tnpc = addr+4;
6595 + return 2;
6596 + }
6597 + } while (0);
6598 +
6599 + do { /* PaX: patched PLT emulation #4 */
6600 + unsigned int sethi, mov1, call, mov2;
6601 +
6602 + err = get_user(sethi, (unsigned int *)regs->tpc);
6603 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6604 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6605 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6606 +
6607 + if (err)
6608 + break;
6609 +
6610 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6611 + mov1 == 0x8210000FU &&
6612 + (call & 0xC0000000U) == 0x40000000U &&
6613 + mov2 == 0x9E100001U)
6614 + {
6615 + unsigned long addr;
6616 +
6617 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6618 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6619 +
6620 + if (test_thread_flag(TIF_32BIT))
6621 + addr &= 0xFFFFFFFFUL;
6622 +
6623 + regs->tpc = addr;
6624 + regs->tnpc = addr+4;
6625 + return 2;
6626 + }
6627 + } while (0);
6628 +
6629 + do { /* PaX: patched PLT emulation #5 */
6630 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6631 +
6632 + err = get_user(sethi, (unsigned int *)regs->tpc);
6633 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6634 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6635 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6636 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6637 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6638 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6639 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6640 +
6641 + if (err)
6642 + break;
6643 +
6644 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6645 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6646 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6647 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6648 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6649 + sllx == 0x83287020U &&
6650 + jmpl == 0x81C04005U &&
6651 + nop == 0x01000000U)
6652 + {
6653 + unsigned long addr;
6654 +
6655 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6656 + regs->u_regs[UREG_G1] <<= 32;
6657 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6658 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6659 + regs->tpc = addr;
6660 + regs->tnpc = addr+4;
6661 + return 2;
6662 + }
6663 + } while (0);
6664 +
6665 + do { /* PaX: patched PLT emulation #6 */
6666 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6667 +
6668 + err = get_user(sethi, (unsigned int *)regs->tpc);
6669 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6670 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6671 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6672 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
6673 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6674 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6675 +
6676 + if (err)
6677 + break;
6678 +
6679 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6680 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6681 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6682 + sllx == 0x83287020U &&
6683 + (or & 0xFFFFE000U) == 0x8A116000U &&
6684 + jmpl == 0x81C04005U &&
6685 + nop == 0x01000000U)
6686 + {
6687 + unsigned long addr;
6688 +
6689 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6690 + regs->u_regs[UREG_G1] <<= 32;
6691 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6692 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6693 + regs->tpc = addr;
6694 + regs->tnpc = addr+4;
6695 + return 2;
6696 + }
6697 + } while (0);
6698 +
6699 + do { /* PaX: unpatched PLT emulation step 1 */
6700 + unsigned int sethi, ba, nop;
6701 +
6702 + err = get_user(sethi, (unsigned int *)regs->tpc);
6703 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6704 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6705 +
6706 + if (err)
6707 + break;
6708 +
6709 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6710 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6711 + nop == 0x01000000U)
6712 + {
6713 + unsigned long addr;
6714 + unsigned int save, call;
6715 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
6716 +
6717 + if ((ba & 0xFFC00000U) == 0x30800000U)
6718 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6719 + else
6720 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6721 +
6722 + if (test_thread_flag(TIF_32BIT))
6723 + addr &= 0xFFFFFFFFUL;
6724 +
6725 + err = get_user(save, (unsigned int *)addr);
6726 + err |= get_user(call, (unsigned int *)(addr+4));
6727 + err |= get_user(nop, (unsigned int *)(addr+8));
6728 + if (err)
6729 + break;
6730 +
6731 +#ifdef CONFIG_PAX_DLRESOLVE
6732 + if (save == 0x9DE3BFA8U &&
6733 + (call & 0xC0000000U) == 0x40000000U &&
6734 + nop == 0x01000000U)
6735 + {
6736 + struct vm_area_struct *vma;
6737 + unsigned long call_dl_resolve;
6738 +
6739 + down_read(&current->mm->mmap_sem);
6740 + call_dl_resolve = current->mm->call_dl_resolve;
6741 + up_read(&current->mm->mmap_sem);
6742 + if (likely(call_dl_resolve))
6743 + goto emulate;
6744 +
6745 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6746 +
6747 + down_write(&current->mm->mmap_sem);
6748 + if (current->mm->call_dl_resolve) {
6749 + call_dl_resolve = current->mm->call_dl_resolve;
6750 + up_write(&current->mm->mmap_sem);
6751 + if (vma)
6752 + kmem_cache_free(vm_area_cachep, vma);
6753 + goto emulate;
6754 + }
6755 +
6756 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6757 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6758 + up_write(&current->mm->mmap_sem);
6759 + if (vma)
6760 + kmem_cache_free(vm_area_cachep, vma);
6761 + return 1;
6762 + }
6763 +
6764 + if (pax_insert_vma(vma, call_dl_resolve)) {
6765 + up_write(&current->mm->mmap_sem);
6766 + kmem_cache_free(vm_area_cachep, vma);
6767 + return 1;
6768 + }
6769 +
6770 + current->mm->call_dl_resolve = call_dl_resolve;
6771 + up_write(&current->mm->mmap_sem);
6772 +
6773 +emulate:
6774 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6775 + regs->tpc = call_dl_resolve;
6776 + regs->tnpc = addr+4;
6777 + return 3;
6778 + }
6779 +#endif
6780 +
6781 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6782 + if ((save & 0xFFC00000U) == 0x05000000U &&
6783 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6784 + nop == 0x01000000U)
6785 + {
6786 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6787 + regs->u_regs[UREG_G2] = addr + 4;
6788 + addr = (save & 0x003FFFFFU) << 10;
6789 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6790 +
6791 + if (test_thread_flag(TIF_32BIT))
6792 + addr &= 0xFFFFFFFFUL;
6793 +
6794 + regs->tpc = addr;
6795 + regs->tnpc = addr+4;
6796 + return 3;
6797 + }
6798 +
6799 + /* PaX: 64-bit PLT stub */
6800 + err = get_user(sethi1, (unsigned int *)addr);
6801 + err |= get_user(sethi2, (unsigned int *)(addr+4));
6802 + err |= get_user(or1, (unsigned int *)(addr+8));
6803 + err |= get_user(or2, (unsigned int *)(addr+12));
6804 + err |= get_user(sllx, (unsigned int *)(addr+16));
6805 + err |= get_user(add, (unsigned int *)(addr+20));
6806 + err |= get_user(jmpl, (unsigned int *)(addr+24));
6807 + err |= get_user(nop, (unsigned int *)(addr+28));
6808 + if (err)
6809 + break;
6810 +
6811 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
6812 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6813 + (or1 & 0xFFFFE000U) == 0x88112000U &&
6814 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6815 + sllx == 0x89293020U &&
6816 + add == 0x8A010005U &&
6817 + jmpl == 0x89C14000U &&
6818 + nop == 0x01000000U)
6819 + {
6820 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6821 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6822 + regs->u_regs[UREG_G4] <<= 32;
6823 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6824 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
6825 + regs->u_regs[UREG_G4] = addr + 24;
6826 + addr = regs->u_regs[UREG_G5];
6827 + regs->tpc = addr;
6828 + regs->tnpc = addr+4;
6829 + return 3;
6830 + }
6831 + }
6832 + } while (0);
6833 +
6834 +#ifdef CONFIG_PAX_DLRESOLVE
6835 + do { /* PaX: unpatched PLT emulation step 2 */
6836 + unsigned int save, call, nop;
6837 +
6838 + err = get_user(save, (unsigned int *)(regs->tpc-4));
6839 + err |= get_user(call, (unsigned int *)regs->tpc);
6840 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
6841 + if (err)
6842 + break;
6843 +
6844 + if (save == 0x9DE3BFA8U &&
6845 + (call & 0xC0000000U) == 0x40000000U &&
6846 + nop == 0x01000000U)
6847 + {
6848 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6849 +
6850 + if (test_thread_flag(TIF_32BIT))
6851 + dl_resolve &= 0xFFFFFFFFUL;
6852 +
6853 + regs->u_regs[UREG_RETPC] = regs->tpc;
6854 + regs->tpc = dl_resolve;
6855 + regs->tnpc = dl_resolve+4;
6856 + return 3;
6857 + }
6858 + } while (0);
6859 +#endif
6860 +
6861 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
6862 + unsigned int sethi, ba, nop;
6863 +
6864 + err = get_user(sethi, (unsigned int *)regs->tpc);
6865 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6866 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6867 +
6868 + if (err)
6869 + break;
6870 +
6871 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6872 + (ba & 0xFFF00000U) == 0x30600000U &&
6873 + nop == 0x01000000U)
6874 + {
6875 + unsigned long addr;
6876 +
6877 + addr = (sethi & 0x003FFFFFU) << 10;
6878 + regs->u_regs[UREG_G1] = addr;
6879 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6880 +
6881 + if (test_thread_flag(TIF_32BIT))
6882 + addr &= 0xFFFFFFFFUL;
6883 +
6884 + regs->tpc = addr;
6885 + regs->tnpc = addr+4;
6886 + return 2;
6887 + }
6888 + } while (0);
6889 +
6890 +#endif
6891 +
6892 + return 1;
6893 +}
6894 +
6895 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6896 +{
6897 + unsigned long i;
6898 +
6899 + printk(KERN_ERR "PAX: bytes at PC: ");
6900 + for (i = 0; i < 8; i++) {
6901 + unsigned int c;
6902 + if (get_user(c, (unsigned int *)pc+i))
6903 + printk(KERN_CONT "???????? ");
6904 + else
6905 + printk(KERN_CONT "%08x ", c);
6906 + }
6907 + printk("\n");
6908 +}
6909 +#endif
6910 +
6911 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6912 {
6913 struct mm_struct *mm = current->mm;
6914 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6915 if (!vma)
6916 goto bad_area;
6917
6918 +#ifdef CONFIG_PAX_PAGEEXEC
6919 + /* PaX: detect ITLB misses on non-exec pages */
6920 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
6921 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
6922 + {
6923 + if (address != regs->tpc)
6924 + goto good_area;
6925 +
6926 + up_read(&mm->mmap_sem);
6927 + switch (pax_handle_fetch_fault(regs)) {
6928 +
6929 +#ifdef CONFIG_PAX_EMUPLT
6930 + case 2:
6931 + case 3:
6932 + return;
6933 +#endif
6934 +
6935 + }
6936 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
6937 + do_group_exit(SIGKILL);
6938 + }
6939 +#endif
6940 +
6941 /* Pure DTLB misses do not tell us whether the fault causing
6942 * load/store/atomic was a write or not, it only says that there
6943 * was no match. So in such a case we (carefully) read the
6944 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
6945 index 07e1453..0a7d9e9 100644
6946 --- a/arch/sparc/mm/hugetlbpage.c
6947 +++ b/arch/sparc/mm/hugetlbpage.c
6948 @@ -67,7 +67,7 @@ full_search:
6949 }
6950 return -ENOMEM;
6951 }
6952 - if (likely(!vma || addr + len <= vma->vm_start)) {
6953 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6954 /*
6955 * Remember the place where we stopped the search:
6956 */
6957 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6958 /* make sure it can fit in the remaining address space */
6959 if (likely(addr > len)) {
6960 vma = find_vma(mm, addr-len);
6961 - if (!vma || addr <= vma->vm_start) {
6962 + if (check_heap_stack_gap(vma, addr - len, len)) {
6963 /* remember the address as a hint for next time */
6964 return (mm->free_area_cache = addr-len);
6965 }
6966 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6967 if (unlikely(mm->mmap_base < len))
6968 goto bottomup;
6969
6970 - addr = (mm->mmap_base-len) & HPAGE_MASK;
6971 + addr = mm->mmap_base - len;
6972
6973 do {
6974 + addr &= HPAGE_MASK;
6975 /*
6976 * Lookup failure means no vma is above this address,
6977 * else if new region fits below vma->vm_start,
6978 * return with success:
6979 */
6980 vma = find_vma(mm, addr);
6981 - if (likely(!vma || addr+len <= vma->vm_start)) {
6982 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6983 /* remember the address as a hint for next time */
6984 return (mm->free_area_cache = addr);
6985 }
6986 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6987 mm->cached_hole_size = vma->vm_start - addr;
6988
6989 /* try just below the current vma->vm_start */
6990 - addr = (vma->vm_start-len) & HPAGE_MASK;
6991 - } while (likely(len < vma->vm_start));
6992 + addr = skip_heap_stack_gap(vma, len);
6993 + } while (!IS_ERR_VALUE(addr));
6994
6995 bottomup:
6996 /*
6997 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
6998 if (addr) {
6999 addr = ALIGN(addr, HPAGE_SIZE);
7000 vma = find_vma(mm, addr);
7001 - if (task_size - len >= addr &&
7002 - (!vma || addr + len <= vma->vm_start))
7003 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7004 return addr;
7005 }
7006 if (mm->get_unmapped_area == arch_get_unmapped_area)
7007 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
7008 index 7b00de6..78239f4 100644
7009 --- a/arch/sparc/mm/init_32.c
7010 +++ b/arch/sparc/mm/init_32.c
7011 @@ -316,6 +316,9 @@ extern void device_scan(void);
7012 pgprot_t PAGE_SHARED __read_mostly;
7013 EXPORT_SYMBOL(PAGE_SHARED);
7014
7015 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7016 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7017 +
7018 void __init paging_init(void)
7019 {
7020 switch(sparc_cpu_model) {
7021 @@ -344,17 +347,17 @@ void __init paging_init(void)
7022
7023 /* Initialize the protection map with non-constant, MMU dependent values. */
7024 protection_map[0] = PAGE_NONE;
7025 - protection_map[1] = PAGE_READONLY;
7026 - protection_map[2] = PAGE_COPY;
7027 - protection_map[3] = PAGE_COPY;
7028 + protection_map[1] = PAGE_READONLY_NOEXEC;
7029 + protection_map[2] = PAGE_COPY_NOEXEC;
7030 + protection_map[3] = PAGE_COPY_NOEXEC;
7031 protection_map[4] = PAGE_READONLY;
7032 protection_map[5] = PAGE_READONLY;
7033 protection_map[6] = PAGE_COPY;
7034 protection_map[7] = PAGE_COPY;
7035 protection_map[8] = PAGE_NONE;
7036 - protection_map[9] = PAGE_READONLY;
7037 - protection_map[10] = PAGE_SHARED;
7038 - protection_map[11] = PAGE_SHARED;
7039 + protection_map[9] = PAGE_READONLY_NOEXEC;
7040 + protection_map[10] = PAGE_SHARED_NOEXEC;
7041 + protection_map[11] = PAGE_SHARED_NOEXEC;
7042 protection_map[12] = PAGE_READONLY;
7043 protection_map[13] = PAGE_READONLY;
7044 protection_map[14] = PAGE_SHARED;
7045 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
7046 index cbef74e..c38fead 100644
7047 --- a/arch/sparc/mm/srmmu.c
7048 +++ b/arch/sparc/mm/srmmu.c
7049 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7050 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7051 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7052 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7053 +
7054 +#ifdef CONFIG_PAX_PAGEEXEC
7055 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7056 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7057 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7058 +#endif
7059 +
7060 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7061 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7062
7063 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7064 index 27fe667..36d474c 100644
7065 --- a/arch/tile/include/asm/atomic_64.h
7066 +++ b/arch/tile/include/asm/atomic_64.h
7067 @@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7068
7069 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7070
7071 +#define atomic64_read_unchecked(v) atomic64_read(v)
7072 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7073 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7074 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7075 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7076 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7077 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7078 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7079 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7080 +
7081 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7082 #define smp_mb__before_atomic_dec() smp_mb()
7083 #define smp_mb__after_atomic_dec() smp_mb()
7084 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7085 index 392e533..536b092 100644
7086 --- a/arch/tile/include/asm/cache.h
7087 +++ b/arch/tile/include/asm/cache.h
7088 @@ -15,11 +15,12 @@
7089 #ifndef _ASM_TILE_CACHE_H
7090 #define _ASM_TILE_CACHE_H
7091
7092 +#include <linux/const.h>
7093 #include <arch/chip.h>
7094
7095 /* bytes per L1 data cache line */
7096 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7097 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7098 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7099
7100 /* bytes per L2 cache line */
7101 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7102 diff --git a/arch/um/Makefile b/arch/um/Makefile
7103 index 28688e6..4c0aa1c 100644
7104 --- a/arch/um/Makefile
7105 +++ b/arch/um/Makefile
7106 @@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7107 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7108 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7109
7110 +ifdef CONSTIFY_PLUGIN
7111 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7112 +endif
7113 +
7114 #This will adjust *FLAGS accordingly to the platform.
7115 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7116
7117 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7118 index 19e1bdd..3665b77 100644
7119 --- a/arch/um/include/asm/cache.h
7120 +++ b/arch/um/include/asm/cache.h
7121 @@ -1,6 +1,7 @@
7122 #ifndef __UM_CACHE_H
7123 #define __UM_CACHE_H
7124
7125 +#include <linux/const.h>
7126
7127 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7128 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7129 @@ -12,6 +13,6 @@
7130 # define L1_CACHE_SHIFT 5
7131 #endif
7132
7133 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7134 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7135
7136 #endif
7137 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7138 index 6c03acd..a5e0215 100644
7139 --- a/arch/um/include/asm/kmap_types.h
7140 +++ b/arch/um/include/asm/kmap_types.h
7141 @@ -23,6 +23,7 @@ enum km_type {
7142 KM_IRQ1,
7143 KM_SOFTIRQ0,
7144 KM_SOFTIRQ1,
7145 + KM_CLEARPAGE,
7146 KM_TYPE_NR
7147 };
7148
7149 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7150 index 7cfc3ce..cbd1a58 100644
7151 --- a/arch/um/include/asm/page.h
7152 +++ b/arch/um/include/asm/page.h
7153 @@ -14,6 +14,9 @@
7154 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7155 #define PAGE_MASK (~(PAGE_SIZE-1))
7156
7157 +#define ktla_ktva(addr) (addr)
7158 +#define ktva_ktla(addr) (addr)
7159 +
7160 #ifndef __ASSEMBLY__
7161
7162 struct page;
7163 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7164 index 0032f92..cd151e0 100644
7165 --- a/arch/um/include/asm/pgtable-3level.h
7166 +++ b/arch/um/include/asm/pgtable-3level.h
7167 @@ -58,6 +58,7 @@
7168 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7169 #define pud_populate(mm, pud, pmd) \
7170 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7171 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7172
7173 #ifdef CONFIG_64BIT
7174 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7175 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7176 index 69f2490..2634831 100644
7177 --- a/arch/um/kernel/process.c
7178 +++ b/arch/um/kernel/process.c
7179 @@ -408,22 +408,6 @@ int singlestepping(void * t)
7180 return 2;
7181 }
7182
7183 -/*
7184 - * Only x86 and x86_64 have an arch_align_stack().
7185 - * All other arches have "#define arch_align_stack(x) (x)"
7186 - * in their asm/system.h
7187 - * As this is included in UML from asm-um/system-generic.h,
7188 - * we can use it to behave as the subarch does.
7189 - */
7190 -#ifndef arch_align_stack
7191 -unsigned long arch_align_stack(unsigned long sp)
7192 -{
7193 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7194 - sp -= get_random_int() % 8192;
7195 - return sp & ~0xf;
7196 -}
7197 -#endif
7198 -
7199 unsigned long get_wchan(struct task_struct *p)
7200 {
7201 unsigned long stack_page, sp, ip;
7202 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7203 index ad8f795..2c7eec6 100644
7204 --- a/arch/unicore32/include/asm/cache.h
7205 +++ b/arch/unicore32/include/asm/cache.h
7206 @@ -12,8 +12,10 @@
7207 #ifndef __UNICORE_CACHE_H__
7208 #define __UNICORE_CACHE_H__
7209
7210 -#define L1_CACHE_SHIFT (5)
7211 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7212 +#include <linux/const.h>
7213 +
7214 +#define L1_CACHE_SHIFT 5
7215 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7216
7217 /*
7218 * Memory returned by kmalloc() may be used for DMA, so we must make
7219 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7220 index 5bed94e..fbcf200 100644
7221 --- a/arch/x86/Kconfig
7222 +++ b/arch/x86/Kconfig
7223 @@ -226,7 +226,7 @@ config X86_HT
7224
7225 config X86_32_LAZY_GS
7226 def_bool y
7227 - depends on X86_32 && !CC_STACKPROTECTOR
7228 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7229
7230 config ARCH_HWEIGHT_CFLAGS
7231 string
7232 @@ -1058,7 +1058,7 @@ choice
7233
7234 config NOHIGHMEM
7235 bool "off"
7236 - depends on !X86_NUMAQ
7237 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7238 ---help---
7239 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7240 However, the address space of 32-bit x86 processors is only 4
7241 @@ -1095,7 +1095,7 @@ config NOHIGHMEM
7242
7243 config HIGHMEM4G
7244 bool "4GB"
7245 - depends on !X86_NUMAQ
7246 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7247 ---help---
7248 Select this if you have a 32-bit processor and between 1 and 4
7249 gigabytes of physical RAM.
7250 @@ -1149,7 +1149,7 @@ config PAGE_OFFSET
7251 hex
7252 default 0xB0000000 if VMSPLIT_3G_OPT
7253 default 0x80000000 if VMSPLIT_2G
7254 - default 0x78000000 if VMSPLIT_2G_OPT
7255 + default 0x70000000 if VMSPLIT_2G_OPT
7256 default 0x40000000 if VMSPLIT_1G
7257 default 0xC0000000
7258 depends on X86_32
7259 @@ -1539,6 +1539,7 @@ config SECCOMP
7260
7261 config CC_STACKPROTECTOR
7262 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7263 + depends on X86_64 || !PAX_MEMORY_UDEREF
7264 ---help---
7265 This option turns on the -fstack-protector GCC feature. This
7266 feature puts, at the beginning of functions, a canary value on
7267 @@ -1596,6 +1597,7 @@ config KEXEC_JUMP
7268 config PHYSICAL_START
7269 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7270 default "0x1000000"
7271 + range 0x400000 0x40000000
7272 ---help---
7273 This gives the physical address where the kernel is loaded.
7274
7275 @@ -1659,6 +1661,7 @@ config X86_NEED_RELOCS
7276 config PHYSICAL_ALIGN
7277 hex "Alignment value to which kernel should be aligned" if X86_32
7278 default "0x1000000"
7279 + range 0x400000 0x1000000 if PAX_KERNEXEC
7280 range 0x2000 0x1000000
7281 ---help---
7282 This value puts the alignment restrictions on physical address
7283 @@ -1690,9 +1693,10 @@ config HOTPLUG_CPU
7284 Say N if you want to disable CPU hotplug.
7285
7286 config COMPAT_VDSO
7287 - def_bool y
7288 + def_bool n
7289 prompt "Compat VDSO support"
7290 depends on X86_32 || IA32_EMULATION
7291 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7292 ---help---
7293 Map the 32-bit VDSO to the predictable old-style address too.
7294
7295 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7296 index 3c57033..22d44aa 100644
7297 --- a/arch/x86/Kconfig.cpu
7298 +++ b/arch/x86/Kconfig.cpu
7299 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
7300
7301 config X86_F00F_BUG
7302 def_bool y
7303 - depends on M586MMX || M586TSC || M586 || M486 || M386
7304 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7305
7306 config X86_INVD_BUG
7307 def_bool y
7308 @@ -359,7 +359,7 @@ config X86_POPAD_OK
7309
7310 config X86_ALIGNMENT_16
7311 def_bool y
7312 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7313 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7314
7315 config X86_INTEL_USERCOPY
7316 def_bool y
7317 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
7318 # generates cmov.
7319 config X86_CMOV
7320 def_bool y
7321 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7322 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7323
7324 config X86_MINIMUM_CPU_FAMILY
7325 int
7326 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7327 index e46c214..7c72b55 100644
7328 --- a/arch/x86/Kconfig.debug
7329 +++ b/arch/x86/Kconfig.debug
7330 @@ -84,7 +84,7 @@ config X86_PTDUMP
7331 config DEBUG_RODATA
7332 bool "Write protect kernel read-only data structures"
7333 default y
7334 - depends on DEBUG_KERNEL
7335 + depends on DEBUG_KERNEL && BROKEN
7336 ---help---
7337 Mark the kernel read-only data as write-protected in the pagetables,
7338 in order to catch accidental (and incorrect) writes to such const
7339 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7340
7341 config DEBUG_SET_MODULE_RONX
7342 bool "Set loadable kernel module data as NX and text as RO"
7343 - depends on MODULES
7344 + depends on MODULES && BROKEN
7345 ---help---
7346 This option helps catch unintended modifications to loadable
7347 kernel module's text and read-only data. It also prevents execution
7348 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7349 index 209ba12..15140db 100644
7350 --- a/arch/x86/Makefile
7351 +++ b/arch/x86/Makefile
7352 @@ -46,6 +46,7 @@ else
7353 UTS_MACHINE := x86_64
7354 CHECKFLAGS += -D__x86_64__ -m64
7355
7356 + biarch := $(call cc-option,-m64)
7357 KBUILD_AFLAGS += -m64
7358 KBUILD_CFLAGS += -m64
7359
7360 @@ -201,3 +202,12 @@ define archhelp
7361 echo ' FDARGS="..." arguments for the booted kernel'
7362 echo ' FDINITRD=file initrd for the booted kernel'
7363 endef
7364 +
7365 +define OLD_LD
7366 +
7367 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7368 +*** Please upgrade your binutils to 2.18 or newer
7369 +endef
7370 +
7371 +archprepare:
7372 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7373 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7374 index 5a747dd..ff7b12c 100644
7375 --- a/arch/x86/boot/Makefile
7376 +++ b/arch/x86/boot/Makefile
7377 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7378 $(call cc-option, -fno-stack-protector) \
7379 $(call cc-option, -mpreferred-stack-boundary=2)
7380 KBUILD_CFLAGS += $(call cc-option, -m32)
7381 +ifdef CONSTIFY_PLUGIN
7382 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7383 +endif
7384 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7385 GCOV_PROFILE := n
7386
7387 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7388 index 878e4b9..20537ab 100644
7389 --- a/arch/x86/boot/bitops.h
7390 +++ b/arch/x86/boot/bitops.h
7391 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7392 u8 v;
7393 const u32 *p = (const u32 *)addr;
7394
7395 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7396 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7397 return v;
7398 }
7399
7400 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7401
7402 static inline void set_bit(int nr, void *addr)
7403 {
7404 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7405 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7406 }
7407
7408 #endif /* BOOT_BITOPS_H */
7409 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7410 index c7093bd..d4247ffe0 100644
7411 --- a/arch/x86/boot/boot.h
7412 +++ b/arch/x86/boot/boot.h
7413 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7414 static inline u16 ds(void)
7415 {
7416 u16 seg;
7417 - asm("movw %%ds,%0" : "=rm" (seg));
7418 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7419 return seg;
7420 }
7421
7422 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7423 static inline int memcmp(const void *s1, const void *s2, size_t len)
7424 {
7425 u8 diff;
7426 - asm("repe; cmpsb; setnz %0"
7427 + asm volatile("repe; cmpsb; setnz %0"
7428 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7429 return diff;
7430 }
7431 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7432 index fd55a2f..217b501 100644
7433 --- a/arch/x86/boot/compressed/Makefile
7434 +++ b/arch/x86/boot/compressed/Makefile
7435 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7436 KBUILD_CFLAGS += $(cflags-y)
7437 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7438 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7439 +ifdef CONSTIFY_PLUGIN
7440 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7441 +endif
7442
7443 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7444 GCOV_PROFILE := n
7445 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7446 index c85e3ac..6f5aa80 100644
7447 --- a/arch/x86/boot/compressed/head_32.S
7448 +++ b/arch/x86/boot/compressed/head_32.S
7449 @@ -106,7 +106,7 @@ preferred_addr:
7450 notl %eax
7451 andl %eax, %ebx
7452 #else
7453 - movl $LOAD_PHYSICAL_ADDR, %ebx
7454 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7455 #endif
7456
7457 /* Target address to relocate to for decompression */
7458 @@ -192,7 +192,7 @@ relocated:
7459 * and where it was actually loaded.
7460 */
7461 movl %ebp, %ebx
7462 - subl $LOAD_PHYSICAL_ADDR, %ebx
7463 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7464 jz 2f /* Nothing to be done if loaded at compiled addr. */
7465 /*
7466 * Process relocations.
7467 @@ -200,8 +200,7 @@ relocated:
7468
7469 1: subl $4, %edi
7470 movl (%edi), %ecx
7471 - testl %ecx, %ecx
7472 - jz 2f
7473 + jecxz 2f
7474 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7475 jmp 1b
7476 2:
7477 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7478 index 87e03a1..0d94c76 100644
7479 --- a/arch/x86/boot/compressed/head_64.S
7480 +++ b/arch/x86/boot/compressed/head_64.S
7481 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7482 notl %eax
7483 andl %eax, %ebx
7484 #else
7485 - movl $LOAD_PHYSICAL_ADDR, %ebx
7486 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7487 #endif
7488
7489 /* Target address to relocate to for decompression */
7490 @@ -263,7 +263,7 @@ preferred_addr:
7491 notq %rax
7492 andq %rax, %rbp
7493 #else
7494 - movq $LOAD_PHYSICAL_ADDR, %rbp
7495 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7496 #endif
7497
7498 /* Target address to relocate to for decompression */
7499 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7500 index 7116dcb..d9ae1d7 100644
7501 --- a/arch/x86/boot/compressed/misc.c
7502 +++ b/arch/x86/boot/compressed/misc.c
7503 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7504 case PT_LOAD:
7505 #ifdef CONFIG_RELOCATABLE
7506 dest = output;
7507 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7508 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7509 #else
7510 dest = (void *)(phdr->p_paddr);
7511 #endif
7512 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7513 error("Destination address too large");
7514 #endif
7515 #ifndef CONFIG_RELOCATABLE
7516 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7517 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7518 error("Wrong destination address");
7519 #endif
7520
7521 diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7522 index 89bbf4e..869908e 100644
7523 --- a/arch/x86/boot/compressed/relocs.c
7524 +++ b/arch/x86/boot/compressed/relocs.c
7525 @@ -13,8 +13,11 @@
7526
7527 static void die(char *fmt, ...);
7528
7529 +#include "../../../../include/generated/autoconf.h"
7530 +
7531 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7532 static Elf32_Ehdr ehdr;
7533 +static Elf32_Phdr *phdr;
7534 static unsigned long reloc_count, reloc_idx;
7535 static unsigned long *relocs;
7536
7537 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7538 }
7539 }
7540
7541 +static void read_phdrs(FILE *fp)
7542 +{
7543 + unsigned int i;
7544 +
7545 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7546 + if (!phdr) {
7547 + die("Unable to allocate %d program headers\n",
7548 + ehdr.e_phnum);
7549 + }
7550 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7551 + die("Seek to %d failed: %s\n",
7552 + ehdr.e_phoff, strerror(errno));
7553 + }
7554 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7555 + die("Cannot read ELF program headers: %s\n",
7556 + strerror(errno));
7557 + }
7558 + for(i = 0; i < ehdr.e_phnum; i++) {
7559 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7560 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7561 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7562 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7563 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7564 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7565 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7566 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7567 + }
7568 +
7569 +}
7570 +
7571 static void read_shdrs(FILE *fp)
7572 {
7573 - int i;
7574 + unsigned int i;
7575 Elf32_Shdr shdr;
7576
7577 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7578 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7579
7580 static void read_strtabs(FILE *fp)
7581 {
7582 - int i;
7583 + unsigned int i;
7584 for (i = 0; i < ehdr.e_shnum; i++) {
7585 struct section *sec = &secs[i];
7586 if (sec->shdr.sh_type != SHT_STRTAB) {
7587 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7588
7589 static void read_symtabs(FILE *fp)
7590 {
7591 - int i,j;
7592 + unsigned int i,j;
7593 for (i = 0; i < ehdr.e_shnum; i++) {
7594 struct section *sec = &secs[i];
7595 if (sec->shdr.sh_type != SHT_SYMTAB) {
7596 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7597
7598 static void read_relocs(FILE *fp)
7599 {
7600 - int i,j;
7601 + unsigned int i,j;
7602 + uint32_t base;
7603 +
7604 for (i = 0; i < ehdr.e_shnum; i++) {
7605 struct section *sec = &secs[i];
7606 if (sec->shdr.sh_type != SHT_REL) {
7607 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7608 die("Cannot read symbol table: %s\n",
7609 strerror(errno));
7610 }
7611 + base = 0;
7612 + for (j = 0; j < ehdr.e_phnum; j++) {
7613 + if (phdr[j].p_type != PT_LOAD )
7614 + continue;
7615 + 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)
7616 + continue;
7617 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7618 + break;
7619 + }
7620 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7621 Elf32_Rel *rel = &sec->reltab[j];
7622 - rel->r_offset = elf32_to_cpu(rel->r_offset);
7623 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7624 rel->r_info = elf32_to_cpu(rel->r_info);
7625 }
7626 }
7627 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
7628
7629 static void print_absolute_symbols(void)
7630 {
7631 - int i;
7632 + unsigned int i;
7633 printf("Absolute symbols\n");
7634 printf(" Num: Value Size Type Bind Visibility Name\n");
7635 for (i = 0; i < ehdr.e_shnum; i++) {
7636 struct section *sec = &secs[i];
7637 char *sym_strtab;
7638 Elf32_Sym *sh_symtab;
7639 - int j;
7640 + unsigned int j;
7641
7642 if (sec->shdr.sh_type != SHT_SYMTAB) {
7643 continue;
7644 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
7645
7646 static void print_absolute_relocs(void)
7647 {
7648 - int i, printed = 0;
7649 + unsigned int i, printed = 0;
7650
7651 for (i = 0; i < ehdr.e_shnum; i++) {
7652 struct section *sec = &secs[i];
7653 struct section *sec_applies, *sec_symtab;
7654 char *sym_strtab;
7655 Elf32_Sym *sh_symtab;
7656 - int j;
7657 + unsigned int j;
7658 if (sec->shdr.sh_type != SHT_REL) {
7659 continue;
7660 }
7661 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
7662
7663 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7664 {
7665 - int i;
7666 + unsigned int i;
7667 /* Walk through the relocations */
7668 for (i = 0; i < ehdr.e_shnum; i++) {
7669 char *sym_strtab;
7670 Elf32_Sym *sh_symtab;
7671 struct section *sec_applies, *sec_symtab;
7672 - int j;
7673 + unsigned int j;
7674 struct section *sec = &secs[i];
7675
7676 if (sec->shdr.sh_type != SHT_REL) {
7677 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7678 !is_rel_reloc(sym_name(sym_strtab, sym))) {
7679 continue;
7680 }
7681 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7682 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7683 + continue;
7684 +
7685 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7686 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7687 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7688 + continue;
7689 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7690 + continue;
7691 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7692 + continue;
7693 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7694 + continue;
7695 +#endif
7696 +
7697 switch (r_type) {
7698 case R_386_NONE:
7699 case R_386_PC32:
7700 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, const void *vb)
7701
7702 static void emit_relocs(int as_text)
7703 {
7704 - int i;
7705 + unsigned int i;
7706 /* Count how many relocations I have and allocate space for them. */
7707 reloc_count = 0;
7708 walk_relocs(count_reloc);
7709 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
7710 fname, strerror(errno));
7711 }
7712 read_ehdr(fp);
7713 + read_phdrs(fp);
7714 read_shdrs(fp);
7715 read_strtabs(fp);
7716 read_symtabs(fp);
7717 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7718 index 4d3ff03..e4972ff 100644
7719 --- a/arch/x86/boot/cpucheck.c
7720 +++ b/arch/x86/boot/cpucheck.c
7721 @@ -74,7 +74,7 @@ static int has_fpu(void)
7722 u16 fcw = -1, fsw = -1;
7723 u32 cr0;
7724
7725 - asm("movl %%cr0,%0" : "=r" (cr0));
7726 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7727 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7728 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7729 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7730 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7731 {
7732 u32 f0, f1;
7733
7734 - asm("pushfl ; "
7735 + asm volatile("pushfl ; "
7736 "pushfl ; "
7737 "popl %0 ; "
7738 "movl %0,%1 ; "
7739 @@ -115,7 +115,7 @@ static void get_flags(void)
7740 set_bit(X86_FEATURE_FPU, cpu.flags);
7741
7742 if (has_eflag(X86_EFLAGS_ID)) {
7743 - asm("cpuid"
7744 + asm volatile("cpuid"
7745 : "=a" (max_intel_level),
7746 "=b" (cpu_vendor[0]),
7747 "=d" (cpu_vendor[1]),
7748 @@ -124,7 +124,7 @@ static void get_flags(void)
7749
7750 if (max_intel_level >= 0x00000001 &&
7751 max_intel_level <= 0x0000ffff) {
7752 - asm("cpuid"
7753 + asm volatile("cpuid"
7754 : "=a" (tfms),
7755 "=c" (cpu.flags[4]),
7756 "=d" (cpu.flags[0])
7757 @@ -136,7 +136,7 @@ static void get_flags(void)
7758 cpu.model += ((tfms >> 16) & 0xf) << 4;
7759 }
7760
7761 - asm("cpuid"
7762 + asm volatile("cpuid"
7763 : "=a" (max_amd_level)
7764 : "a" (0x80000000)
7765 : "ebx", "ecx", "edx");
7766 @@ -144,7 +144,7 @@ static void get_flags(void)
7767 if (max_amd_level >= 0x80000001 &&
7768 max_amd_level <= 0x8000ffff) {
7769 u32 eax = 0x80000001;
7770 - asm("cpuid"
7771 + asm volatile("cpuid"
7772 : "+a" (eax),
7773 "=c" (cpu.flags[6]),
7774 "=d" (cpu.flags[1])
7775 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7776 u32 ecx = MSR_K7_HWCR;
7777 u32 eax, edx;
7778
7779 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7780 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7781 eax &= ~(1 << 15);
7782 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7783 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7784
7785 get_flags(); /* Make sure it really did something */
7786 err = check_flags();
7787 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7788 u32 ecx = MSR_VIA_FCR;
7789 u32 eax, edx;
7790
7791 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7792 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7793 eax |= (1<<1)|(1<<7);
7794 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7795 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7796
7797 set_bit(X86_FEATURE_CX8, cpu.flags);
7798 err = check_flags();
7799 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7800 u32 eax, edx;
7801 u32 level = 1;
7802
7803 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7804 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7805 - asm("cpuid"
7806 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7807 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7808 + asm volatile("cpuid"
7809 : "+a" (level), "=d" (cpu.flags[0])
7810 : : "ecx", "ebx");
7811 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7812 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7813
7814 err = check_flags();
7815 }
7816 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7817 index f1bbeeb..aff09cb 100644
7818 --- a/arch/x86/boot/header.S
7819 +++ b/arch/x86/boot/header.S
7820 @@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
7821 # single linked list of
7822 # struct setup_data
7823
7824 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7825 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7826
7827 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7828 #define VO_INIT_SIZE (VO__end - VO__text)
7829 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7830 index db75d07..8e6d0af 100644
7831 --- a/arch/x86/boot/memory.c
7832 +++ b/arch/x86/boot/memory.c
7833 @@ -19,7 +19,7 @@
7834
7835 static int detect_memory_e820(void)
7836 {
7837 - int count = 0;
7838 + unsigned int count = 0;
7839 struct biosregs ireg, oreg;
7840 struct e820entry *desc = boot_params.e820_map;
7841 static struct e820entry buf; /* static so it is zeroed */
7842 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7843 index 11e8c6e..fdbb1ed 100644
7844 --- a/arch/x86/boot/video-vesa.c
7845 +++ b/arch/x86/boot/video-vesa.c
7846 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7847
7848 boot_params.screen_info.vesapm_seg = oreg.es;
7849 boot_params.screen_info.vesapm_off = oreg.di;
7850 + boot_params.screen_info.vesapm_size = oreg.cx;
7851 }
7852
7853 /*
7854 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7855 index 43eda28..5ab5fdb 100644
7856 --- a/arch/x86/boot/video.c
7857 +++ b/arch/x86/boot/video.c
7858 @@ -96,7 +96,7 @@ static void store_mode_params(void)
7859 static unsigned int get_entry(void)
7860 {
7861 char entry_buf[4];
7862 - int i, len = 0;
7863 + unsigned int i, len = 0;
7864 int key;
7865 unsigned int v;
7866
7867 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
7868 index 5b577d5..3c1fed4 100644
7869 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
7870 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
7871 @@ -8,6 +8,8 @@
7872 * including this sentence is retained in full.
7873 */
7874
7875 +#include <asm/alternative-asm.h>
7876 +
7877 .extern crypto_ft_tab
7878 .extern crypto_it_tab
7879 .extern crypto_fl_tab
7880 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
7881 je B192; \
7882 leaq 32(r9),r9;
7883
7884 +#define ret pax_force_retaddr 0, 1; ret
7885 +
7886 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
7887 movq r1,r2; \
7888 movq r3,r4; \
7889 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
7890 index be6d9e3..21fbbca 100644
7891 --- a/arch/x86/crypto/aesni-intel_asm.S
7892 +++ b/arch/x86/crypto/aesni-intel_asm.S
7893 @@ -31,6 +31,7 @@
7894
7895 #include <linux/linkage.h>
7896 #include <asm/inst.h>
7897 +#include <asm/alternative-asm.h>
7898
7899 #ifdef __x86_64__
7900 .data
7901 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
7902 pop %r14
7903 pop %r13
7904 pop %r12
7905 + pax_force_retaddr 0, 1
7906 ret
7907 +ENDPROC(aesni_gcm_dec)
7908
7909
7910 /*****************************************************************************
7911 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
7912 pop %r14
7913 pop %r13
7914 pop %r12
7915 + pax_force_retaddr 0, 1
7916 ret
7917 +ENDPROC(aesni_gcm_enc)
7918
7919 #endif
7920
7921 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
7922 pxor %xmm1, %xmm0
7923 movaps %xmm0, (TKEYP)
7924 add $0x10, TKEYP
7925 + pax_force_retaddr_bts
7926 ret
7927
7928 .align 4
7929 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
7930 shufps $0b01001110, %xmm2, %xmm1
7931 movaps %xmm1, 0x10(TKEYP)
7932 add $0x20, TKEYP
7933 + pax_force_retaddr_bts
7934 ret
7935
7936 .align 4
7937 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
7938
7939 movaps %xmm0, (TKEYP)
7940 add $0x10, TKEYP
7941 + pax_force_retaddr_bts
7942 ret
7943
7944 .align 4
7945 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
7946 pxor %xmm1, %xmm2
7947 movaps %xmm2, (TKEYP)
7948 add $0x10, TKEYP
7949 + pax_force_retaddr_bts
7950 ret
7951
7952 /*
7953 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
7954 #ifndef __x86_64__
7955 popl KEYP
7956 #endif
7957 + pax_force_retaddr 0, 1
7958 ret
7959 +ENDPROC(aesni_set_key)
7960
7961 /*
7962 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
7963 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
7964 popl KLEN
7965 popl KEYP
7966 #endif
7967 + pax_force_retaddr 0, 1
7968 ret
7969 +ENDPROC(aesni_enc)
7970
7971 /*
7972 * _aesni_enc1: internal ABI
7973 @@ -1959,6 +1972,7 @@ _aesni_enc1:
7974 AESENC KEY STATE
7975 movaps 0x70(TKEYP), KEY
7976 AESENCLAST KEY STATE
7977 + pax_force_retaddr_bts
7978 ret
7979
7980 /*
7981 @@ -2067,6 +2081,7 @@ _aesni_enc4:
7982 AESENCLAST KEY STATE2
7983 AESENCLAST KEY STATE3
7984 AESENCLAST KEY STATE4
7985 + pax_force_retaddr_bts
7986 ret
7987
7988 /*
7989 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
7990 popl KLEN
7991 popl KEYP
7992 #endif
7993 + pax_force_retaddr 0, 1
7994 ret
7995 +ENDPROC(aesni_dec)
7996
7997 /*
7998 * _aesni_dec1: internal ABI
7999 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8000 AESDEC KEY STATE
8001 movaps 0x70(TKEYP), KEY
8002 AESDECLAST KEY STATE
8003 + pax_force_retaddr_bts
8004 ret
8005
8006 /*
8007 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8008 AESDECLAST KEY STATE2
8009 AESDECLAST KEY STATE3
8010 AESDECLAST KEY STATE4
8011 + pax_force_retaddr_bts
8012 ret
8013
8014 /*
8015 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8016 popl KEYP
8017 popl LEN
8018 #endif
8019 + pax_force_retaddr 0, 1
8020 ret
8021 +ENDPROC(aesni_ecb_enc)
8022
8023 /*
8024 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8025 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8026 popl KEYP
8027 popl LEN
8028 #endif
8029 + pax_force_retaddr 0, 1
8030 ret
8031 +ENDPROC(aesni_ecb_dec)
8032
8033 /*
8034 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8035 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8036 popl LEN
8037 popl IVP
8038 #endif
8039 + pax_force_retaddr 0, 1
8040 ret
8041 +ENDPROC(aesni_cbc_enc)
8042
8043 /*
8044 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8045 @@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
8046 popl LEN
8047 popl IVP
8048 #endif
8049 + pax_force_retaddr 0, 1
8050 ret
8051 +ENDPROC(aesni_cbc_dec)
8052
8053 #ifdef __x86_64__
8054 .align 16
8055 @@ -2524,6 +2551,7 @@ _aesni_inc_init:
8056 mov $1, TCTR_LOW
8057 MOVQ_R64_XMM TCTR_LOW INC
8058 MOVQ_R64_XMM CTR TCTR_LOW
8059 + pax_force_retaddr_bts
8060 ret
8061
8062 /*
8063 @@ -2552,6 +2580,7 @@ _aesni_inc:
8064 .Linc_low:
8065 movaps CTR, IV
8066 PSHUFB_XMM BSWAP_MASK IV
8067 + pax_force_retaddr_bts
8068 ret
8069
8070 /*
8071 @@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
8072 .Lctr_enc_ret:
8073 movups IV, (IVP)
8074 .Lctr_enc_just_ret:
8075 + pax_force_retaddr 0, 1
8076 ret
8077 +ENDPROC(aesni_ctr_enc)
8078 #endif
8079 diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
8080 index 545d0ce..14841a6 100644
8081 --- a/arch/x86/crypto/aesni-intel_glue.c
8082 +++ b/arch/x86/crypto/aesni-intel_glue.c
8083 @@ -929,6 +929,8 @@ out_free_ablkcipher:
8084 }
8085
8086 static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key,
8087 + unsigned int key_len) __size_overflow(3);
8088 +static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key,
8089 unsigned int key_len)
8090 {
8091 int ret = 0;
8092 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8093 index 391d245..67f35c2 100644
8094 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8095 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8096 @@ -20,6 +20,8 @@
8097 *
8098 */
8099
8100 +#include <asm/alternative-asm.h>
8101 +
8102 .file "blowfish-x86_64-asm.S"
8103 .text
8104
8105 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8106 jnz __enc_xor;
8107
8108 write_block();
8109 + pax_force_retaddr 0, 1
8110 ret;
8111 __enc_xor:
8112 xor_block();
8113 + pax_force_retaddr 0, 1
8114 ret;
8115
8116 .align 8
8117 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8118
8119 movq %r11, %rbp;
8120
8121 + pax_force_retaddr 0, 1
8122 ret;
8123
8124 /**********************************************************************
8125 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8126
8127 popq %rbx;
8128 popq %rbp;
8129 + pax_force_retaddr 0, 1
8130 ret;
8131
8132 __enc_xor4:
8133 @@ -349,6 +355,7 @@ __enc_xor4:
8134
8135 popq %rbx;
8136 popq %rbp;
8137 + pax_force_retaddr 0, 1
8138 ret;
8139
8140 .align 8
8141 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8142 popq %rbx;
8143 popq %rbp;
8144
8145 + pax_force_retaddr 0, 1
8146 ret;
8147
8148 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8149 index 6214a9b..1f4fc9a 100644
8150 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8151 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8152 @@ -1,3 +1,5 @@
8153 +#include <asm/alternative-asm.h>
8154 +
8155 # enter ECRYPT_encrypt_bytes
8156 .text
8157 .p2align 5
8158 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8159 add %r11,%rsp
8160 mov %rdi,%rax
8161 mov %rsi,%rdx
8162 + pax_force_retaddr 0, 1
8163 ret
8164 # bytesatleast65:
8165 ._bytesatleast65:
8166 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8167 add %r11,%rsp
8168 mov %rdi,%rax
8169 mov %rsi,%rdx
8170 + pax_force_retaddr
8171 ret
8172 # enter ECRYPT_ivsetup
8173 .text
8174 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8175 add %r11,%rsp
8176 mov %rdi,%rax
8177 mov %rsi,%rdx
8178 + pax_force_retaddr
8179 ret
8180 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8181 index 7f24a15..9cd3ffe 100644
8182 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8183 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8184 @@ -24,6 +24,8 @@
8185 *
8186 */
8187
8188 +#include <asm/alternative-asm.h>
8189 +
8190 .file "serpent-sse2-x86_64-asm_64.S"
8191 .text
8192
8193 @@ -695,12 +697,14 @@ __serpent_enc_blk_8way:
8194 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8195 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8196
8197 + pax_force_retaddr
8198 ret;
8199
8200 __enc_xor8:
8201 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8202 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8203
8204 + pax_force_retaddr
8205 ret;
8206
8207 .align 8
8208 @@ -758,4 +762,5 @@ serpent_dec_blk_8way:
8209 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8210 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8211
8212 + pax_force_retaddr
8213 ret;
8214 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8215 index b2c2f57..8470cab 100644
8216 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8217 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8218 @@ -28,6 +28,8 @@
8219 * (at your option) any later version.
8220 */
8221
8222 +#include <asm/alternative-asm.h>
8223 +
8224 #define CTX %rdi // arg1
8225 #define BUF %rsi // arg2
8226 #define CNT %rdx // arg3
8227 @@ -104,6 +106,7 @@
8228 pop %r12
8229 pop %rbp
8230 pop %rbx
8231 + pax_force_retaddr 0, 1
8232 ret
8233
8234 .size \name, .-\name
8235 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8236 index 5b012a2..36d5364 100644
8237 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8238 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8239 @@ -20,6 +20,8 @@
8240 *
8241 */
8242
8243 +#include <asm/alternative-asm.h>
8244 +
8245 .file "twofish-x86_64-asm-3way.S"
8246 .text
8247
8248 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8249 popq %r13;
8250 popq %r14;
8251 popq %r15;
8252 + pax_force_retaddr 0, 1
8253 ret;
8254
8255 __enc_xor3:
8256 @@ -271,6 +274,7 @@ __enc_xor3:
8257 popq %r13;
8258 popq %r14;
8259 popq %r15;
8260 + pax_force_retaddr 0, 1
8261 ret;
8262
8263 .global twofish_dec_blk_3way
8264 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8265 popq %r13;
8266 popq %r14;
8267 popq %r15;
8268 + pax_force_retaddr 0, 1
8269 ret;
8270
8271 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8272 index 7bcf3fc..f53832f 100644
8273 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8274 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8275 @@ -21,6 +21,7 @@
8276 .text
8277
8278 #include <asm/asm-offsets.h>
8279 +#include <asm/alternative-asm.h>
8280
8281 #define a_offset 0
8282 #define b_offset 4
8283 @@ -268,6 +269,7 @@ twofish_enc_blk:
8284
8285 popq R1
8286 movq $1,%rax
8287 + pax_force_retaddr 0, 1
8288 ret
8289
8290 twofish_dec_blk:
8291 @@ -319,4 +321,5 @@ twofish_dec_blk:
8292
8293 popq R1
8294 movq $1,%rax
8295 + pax_force_retaddr 0, 1
8296 ret
8297 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8298 index 39e4909..887aa7e 100644
8299 --- a/arch/x86/ia32/ia32_aout.c
8300 +++ b/arch/x86/ia32/ia32_aout.c
8301 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8302 unsigned long dump_start, dump_size;
8303 struct user32 dump;
8304
8305 + memset(&dump, 0, sizeof(dump));
8306 +
8307 fs = get_fs();
8308 set_fs(KERNEL_DS);
8309 has_dumped = 1;
8310 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8311 index 6557769..ef6ae89 100644
8312 --- a/arch/x86/ia32/ia32_signal.c
8313 +++ b/arch/x86/ia32/ia32_signal.c
8314 @@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8315 }
8316 seg = get_fs();
8317 set_fs(KERNEL_DS);
8318 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8319 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8320 set_fs(seg);
8321 if (ret >= 0 && uoss_ptr) {
8322 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8323 @@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8324 */
8325 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8326 size_t frame_size,
8327 - void **fpstate)
8328 + void __user **fpstate)
8329 {
8330 unsigned long sp;
8331
8332 @@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8333
8334 if (used_math()) {
8335 sp = sp - sig_xstate_ia32_size;
8336 - *fpstate = (struct _fpstate_ia32 *) sp;
8337 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8338 if (save_i387_xstate_ia32(*fpstate) < 0)
8339 return (void __user *) -1L;
8340 }
8341 @@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8342 sp -= frame_size;
8343 /* Align the stack pointer according to the i386 ABI,
8344 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8345 - sp = ((sp + 4) & -16ul) - 4;
8346 + sp = ((sp - 12) & -16ul) - 4;
8347 return (void __user *) sp;
8348 }
8349
8350 @@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8351 * These are actually not used anymore, but left because some
8352 * gdb versions depend on them as a marker.
8353 */
8354 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8355 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8356 } put_user_catch(err);
8357
8358 if (err)
8359 @@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8360 0xb8,
8361 __NR_ia32_rt_sigreturn,
8362 0x80cd,
8363 - 0,
8364 + 0
8365 };
8366
8367 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8368 @@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8369
8370 if (ka->sa.sa_flags & SA_RESTORER)
8371 restorer = ka->sa.sa_restorer;
8372 + else if (current->mm->context.vdso)
8373 + /* Return stub is in 32bit vsyscall page */
8374 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8375 else
8376 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8377 - rt_sigreturn);
8378 + restorer = &frame->retcode;
8379 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8380
8381 /*
8382 * Not actually used anymore, but left because some gdb
8383 * versions need it.
8384 */
8385 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8386 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8387 } put_user_catch(err);
8388
8389 if (err)
8390 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8391 index e3e7340..05ed805 100644
8392 --- a/arch/x86/ia32/ia32entry.S
8393 +++ b/arch/x86/ia32/ia32entry.S
8394 @@ -13,8 +13,10 @@
8395 #include <asm/thread_info.h>
8396 #include <asm/segment.h>
8397 #include <asm/irqflags.h>
8398 +#include <asm/pgtable.h>
8399 #include <linux/linkage.h>
8400 #include <linux/err.h>
8401 +#include <asm/alternative-asm.h>
8402
8403 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8404 #include <linux/elf-em.h>
8405 @@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8406 ENDPROC(native_irq_enable_sysexit)
8407 #endif
8408
8409 + .macro pax_enter_kernel_user
8410 + pax_set_fptr_mask
8411 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8412 + call pax_enter_kernel_user
8413 +#endif
8414 + .endm
8415 +
8416 + .macro pax_exit_kernel_user
8417 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8418 + call pax_exit_kernel_user
8419 +#endif
8420 +#ifdef CONFIG_PAX_RANDKSTACK
8421 + pushq %rax
8422 + pushq %r11
8423 + call pax_randomize_kstack
8424 + popq %r11
8425 + popq %rax
8426 +#endif
8427 + .endm
8428 +
8429 +.macro pax_erase_kstack
8430 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8431 + call pax_erase_kstack
8432 +#endif
8433 +.endm
8434 +
8435 /*
8436 * 32bit SYSENTER instruction entry.
8437 *
8438 @@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8439 CFI_REGISTER rsp,rbp
8440 SWAPGS_UNSAFE_STACK
8441 movq PER_CPU_VAR(kernel_stack), %rsp
8442 - addq $(KERNEL_STACK_OFFSET),%rsp
8443 - /*
8444 - * No need to follow this irqs on/off section: the syscall
8445 - * disabled irqs, here we enable it straight after entry:
8446 - */
8447 - ENABLE_INTERRUPTS(CLBR_NONE)
8448 movl %ebp,%ebp /* zero extension */
8449 pushq_cfi $__USER32_DS
8450 /*CFI_REL_OFFSET ss,0*/
8451 @@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8452 CFI_REL_OFFSET rsp,0
8453 pushfq_cfi
8454 /*CFI_REL_OFFSET rflags,0*/
8455 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8456 - CFI_REGISTER rip,r10
8457 + orl $X86_EFLAGS_IF,(%rsp)
8458 + GET_THREAD_INFO(%r11)
8459 + movl TI_sysenter_return(%r11), %r11d
8460 + CFI_REGISTER rip,r11
8461 pushq_cfi $__USER32_CS
8462 /*CFI_REL_OFFSET cs,0*/
8463 movl %eax, %eax
8464 - pushq_cfi %r10
8465 + pushq_cfi %r11
8466 CFI_REL_OFFSET rip,0
8467 pushq_cfi %rax
8468 cld
8469 SAVE_ARGS 0,1,0
8470 + pax_enter_kernel_user
8471 + /*
8472 + * No need to follow this irqs on/off section: the syscall
8473 + * disabled irqs, here we enable it straight after entry:
8474 + */
8475 + ENABLE_INTERRUPTS(CLBR_NONE)
8476 /* no need to do an access_ok check here because rbp has been
8477 32bit zero extended */
8478 +
8479 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8480 + mov $PAX_USER_SHADOW_BASE,%r11
8481 + add %r11,%rbp
8482 +#endif
8483 +
8484 1: movl (%rbp),%ebp
8485 .section __ex_table,"a"
8486 .quad 1b,ia32_badarg
8487 .previous
8488 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8489 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8490 + GET_THREAD_INFO(%r11)
8491 + orl $TS_COMPAT,TI_status(%r11)
8492 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8493 CFI_REMEMBER_STATE
8494 jnz sysenter_tracesys
8495 cmpq $(IA32_NR_syscalls-1),%rax
8496 @@ -160,12 +197,15 @@ sysenter_do_call:
8497 sysenter_dispatch:
8498 call *ia32_sys_call_table(,%rax,8)
8499 movq %rax,RAX-ARGOFFSET(%rsp)
8500 + GET_THREAD_INFO(%r11)
8501 DISABLE_INTERRUPTS(CLBR_NONE)
8502 TRACE_IRQS_OFF
8503 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8504 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8505 jnz sysexit_audit
8506 sysexit_from_sys_call:
8507 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8508 + pax_exit_kernel_user
8509 + pax_erase_kstack
8510 + andl $~TS_COMPAT,TI_status(%r11)
8511 /* clear IF, that popfq doesn't enable interrupts early */
8512 andl $~0x200,EFLAGS-R11(%rsp)
8513 movl RIP-R11(%rsp),%edx /* User %eip */
8514 @@ -191,6 +231,9 @@ sysexit_from_sys_call:
8515 movl %eax,%esi /* 2nd arg: syscall number */
8516 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8517 call __audit_syscall_entry
8518 +
8519 + pax_erase_kstack
8520 +
8521 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8522 cmpq $(IA32_NR_syscalls-1),%rax
8523 ja ia32_badsys
8524 @@ -202,7 +245,7 @@ sysexit_from_sys_call:
8525 .endm
8526
8527 .macro auditsys_exit exit
8528 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8529 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8530 jnz ia32_ret_from_sys_call
8531 TRACE_IRQS_ON
8532 sti
8533 @@ -213,11 +256,12 @@ sysexit_from_sys_call:
8534 1: setbe %al /* 1 if error, 0 if not */
8535 movzbl %al,%edi /* zero-extend that into %edi */
8536 call __audit_syscall_exit
8537 + GET_THREAD_INFO(%r11)
8538 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8539 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8540 cli
8541 TRACE_IRQS_OFF
8542 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8543 + testl %edi,TI_flags(%r11)
8544 jz \exit
8545 CLEAR_RREGS -ARGOFFSET
8546 jmp int_with_check
8547 @@ -235,7 +279,7 @@ sysexit_audit:
8548
8549 sysenter_tracesys:
8550 #ifdef CONFIG_AUDITSYSCALL
8551 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8552 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8553 jz sysenter_auditsys
8554 #endif
8555 SAVE_REST
8556 @@ -243,6 +287,9 @@ sysenter_tracesys:
8557 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8558 movq %rsp,%rdi /* &pt_regs -> arg1 */
8559 call syscall_trace_enter
8560 +
8561 + pax_erase_kstack
8562 +
8563 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8564 RESTORE_REST
8565 cmpq $(IA32_NR_syscalls-1),%rax
8566 @@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8567 ENTRY(ia32_cstar_target)
8568 CFI_STARTPROC32 simple
8569 CFI_SIGNAL_FRAME
8570 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8571 + CFI_DEF_CFA rsp,0
8572 CFI_REGISTER rip,rcx
8573 /*CFI_REGISTER rflags,r11*/
8574 SWAPGS_UNSAFE_STACK
8575 movl %esp,%r8d
8576 CFI_REGISTER rsp,r8
8577 movq PER_CPU_VAR(kernel_stack),%rsp
8578 + SAVE_ARGS 8*6,0,0
8579 + pax_enter_kernel_user
8580 /*
8581 * No need to follow this irqs on/off section: the syscall
8582 * disabled irqs and here we enable it straight after entry:
8583 */
8584 ENABLE_INTERRUPTS(CLBR_NONE)
8585 - SAVE_ARGS 8,0,0
8586 movl %eax,%eax /* zero extension */
8587 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8588 movq %rcx,RIP-ARGOFFSET(%rsp)
8589 @@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
8590 /* no need to do an access_ok check here because r8 has been
8591 32bit zero extended */
8592 /* hardware stack frame is complete now */
8593 +
8594 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8595 + mov $PAX_USER_SHADOW_BASE,%r11
8596 + add %r11,%r8
8597 +#endif
8598 +
8599 1: movl (%r8),%r9d
8600 .section __ex_table,"a"
8601 .quad 1b,ia32_badarg
8602 .previous
8603 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8604 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8605 + GET_THREAD_INFO(%r11)
8606 + orl $TS_COMPAT,TI_status(%r11)
8607 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8608 CFI_REMEMBER_STATE
8609 jnz cstar_tracesys
8610 cmpq $IA32_NR_syscalls-1,%rax
8611 @@ -317,12 +372,15 @@ cstar_do_call:
8612 cstar_dispatch:
8613 call *ia32_sys_call_table(,%rax,8)
8614 movq %rax,RAX-ARGOFFSET(%rsp)
8615 + GET_THREAD_INFO(%r11)
8616 DISABLE_INTERRUPTS(CLBR_NONE)
8617 TRACE_IRQS_OFF
8618 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8619 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8620 jnz sysretl_audit
8621 sysretl_from_sys_call:
8622 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8623 + pax_exit_kernel_user
8624 + pax_erase_kstack
8625 + andl $~TS_COMPAT,TI_status(%r11)
8626 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8627 movl RIP-ARGOFFSET(%rsp),%ecx
8628 CFI_REGISTER rip,rcx
8629 @@ -350,7 +408,7 @@ sysretl_audit:
8630
8631 cstar_tracesys:
8632 #ifdef CONFIG_AUDITSYSCALL
8633 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8634 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8635 jz cstar_auditsys
8636 #endif
8637 xchgl %r9d,%ebp
8638 @@ -359,6 +417,9 @@ cstar_tracesys:
8639 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8640 movq %rsp,%rdi /* &pt_regs -> arg1 */
8641 call syscall_trace_enter
8642 +
8643 + pax_erase_kstack
8644 +
8645 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8646 RESTORE_REST
8647 xchgl %ebp,%r9d
8648 @@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
8649 CFI_REL_OFFSET rip,RIP-RIP
8650 PARAVIRT_ADJUST_EXCEPTION_FRAME
8651 SWAPGS
8652 - /*
8653 - * No need to follow this irqs on/off section: the syscall
8654 - * disabled irqs and here we enable it straight after entry:
8655 - */
8656 - ENABLE_INTERRUPTS(CLBR_NONE)
8657 movl %eax,%eax
8658 pushq_cfi %rax
8659 cld
8660 /* note the registers are not zero extended to the sf.
8661 this could be a problem. */
8662 SAVE_ARGS 0,1,0
8663 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8664 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8665 + pax_enter_kernel_user
8666 + /*
8667 + * No need to follow this irqs on/off section: the syscall
8668 + * disabled irqs and here we enable it straight after entry:
8669 + */
8670 + ENABLE_INTERRUPTS(CLBR_NONE)
8671 + GET_THREAD_INFO(%r11)
8672 + orl $TS_COMPAT,TI_status(%r11)
8673 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8674 jnz ia32_tracesys
8675 cmpq $(IA32_NR_syscalls-1),%rax
8676 ja ia32_badsys
8677 @@ -435,6 +498,9 @@ ia32_tracesys:
8678 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8679 movq %rsp,%rdi /* &pt_regs -> arg1 */
8680 call syscall_trace_enter
8681 +
8682 + pax_erase_kstack
8683 +
8684 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8685 RESTORE_REST
8686 cmpq $(IA32_NR_syscalls-1),%rax
8687 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8688 index f6f5c53..b358b28 100644
8689 --- a/arch/x86/ia32/sys_ia32.c
8690 +++ b/arch/x86/ia32/sys_ia32.c
8691 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8692 */
8693 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8694 {
8695 - typeof(ubuf->st_uid) uid = 0;
8696 - typeof(ubuf->st_gid) gid = 0;
8697 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8698 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8699 SET_UID(uid, stat->uid);
8700 SET_GID(gid, stat->gid);
8701 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8702 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
8703 }
8704 set_fs(KERNEL_DS);
8705 ret = sys_rt_sigprocmask(how,
8706 - set ? (sigset_t __user *)&s : NULL,
8707 - oset ? (sigset_t __user *)&s : NULL,
8708 + set ? (sigset_t __force_user *)&s : NULL,
8709 + oset ? (sigset_t __force_user *)&s : NULL,
8710 sigsetsize);
8711 set_fs(old_fs);
8712 if (ret)
8713 @@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
8714 return alarm_setitimer(seconds);
8715 }
8716
8717 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8718 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8719 int options)
8720 {
8721 return compat_sys_wait4(pid, stat_addr, options, NULL);
8722 @@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8723 mm_segment_t old_fs = get_fs();
8724
8725 set_fs(KERNEL_DS);
8726 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8727 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8728 set_fs(old_fs);
8729 if (put_compat_timespec(&t, interval))
8730 return -EFAULT;
8731 @@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8732 mm_segment_t old_fs = get_fs();
8733
8734 set_fs(KERNEL_DS);
8735 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8736 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8737 set_fs(old_fs);
8738 if (!ret) {
8739 switch (_NSIG_WORDS) {
8740 @@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8741 if (copy_siginfo_from_user32(&info, uinfo))
8742 return -EFAULT;
8743 set_fs(KERNEL_DS);
8744 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8745 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8746 set_fs(old_fs);
8747 return ret;
8748 }
8749 @@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8750 return -EFAULT;
8751
8752 set_fs(KERNEL_DS);
8753 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8754 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8755 count);
8756 set_fs(old_fs);
8757
8758 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8759 index 952bd01..7692c6f 100644
8760 --- a/arch/x86/include/asm/alternative-asm.h
8761 +++ b/arch/x86/include/asm/alternative-asm.h
8762 @@ -15,6 +15,45 @@
8763 .endm
8764 #endif
8765
8766 +#ifdef KERNEXEC_PLUGIN
8767 + .macro pax_force_retaddr_bts rip=0
8768 + btsq $63,\rip(%rsp)
8769 + .endm
8770 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8771 + .macro pax_force_retaddr rip=0, reload=0
8772 + btsq $63,\rip(%rsp)
8773 + .endm
8774 + .macro pax_force_fptr ptr
8775 + btsq $63,\ptr
8776 + .endm
8777 + .macro pax_set_fptr_mask
8778 + .endm
8779 +#endif
8780 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8781 + .macro pax_force_retaddr rip=0, reload=0
8782 + .if \reload
8783 + pax_set_fptr_mask
8784 + .endif
8785 + orq %r10,\rip(%rsp)
8786 + .endm
8787 + .macro pax_force_fptr ptr
8788 + orq %r10,\ptr
8789 + .endm
8790 + .macro pax_set_fptr_mask
8791 + movabs $0x8000000000000000,%r10
8792 + .endm
8793 +#endif
8794 +#else
8795 + .macro pax_force_retaddr rip=0, reload=0
8796 + .endm
8797 + .macro pax_force_fptr ptr
8798 + .endm
8799 + .macro pax_force_retaddr_bts rip=0
8800 + .endm
8801 + .macro pax_set_fptr_mask
8802 + .endm
8803 +#endif
8804 +
8805 .macro altinstruction_entry orig alt feature orig_len alt_len
8806 .long \orig - .
8807 .long \alt - .
8808 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8809 index 37ad100..7d47faa 100644
8810 --- a/arch/x86/include/asm/alternative.h
8811 +++ b/arch/x86/include/asm/alternative.h
8812 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
8813 ".section .discard,\"aw\",@progbits\n" \
8814 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8815 ".previous\n" \
8816 - ".section .altinstr_replacement, \"ax\"\n" \
8817 + ".section .altinstr_replacement, \"a\"\n" \
8818 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8819 ".previous"
8820
8821 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
8822 index 3ab9bdd..238033e 100644
8823 --- a/arch/x86/include/asm/apic.h
8824 +++ b/arch/x86/include/asm/apic.h
8825 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
8826
8827 #ifdef CONFIG_X86_LOCAL_APIC
8828
8829 -extern unsigned int apic_verbosity;
8830 +extern int apic_verbosity;
8831 extern int local_apic_timer_c2_ok;
8832
8833 extern int disable_apic;
8834 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
8835 index 20370c6..a2eb9b0 100644
8836 --- a/arch/x86/include/asm/apm.h
8837 +++ b/arch/x86/include/asm/apm.h
8838 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
8839 __asm__ __volatile__(APM_DO_ZERO_SEGS
8840 "pushl %%edi\n\t"
8841 "pushl %%ebp\n\t"
8842 - "lcall *%%cs:apm_bios_entry\n\t"
8843 + "lcall *%%ss:apm_bios_entry\n\t"
8844 "setc %%al\n\t"
8845 "popl %%ebp\n\t"
8846 "popl %%edi\n\t"
8847 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
8848 __asm__ __volatile__(APM_DO_ZERO_SEGS
8849 "pushl %%edi\n\t"
8850 "pushl %%ebp\n\t"
8851 - "lcall *%%cs:apm_bios_entry\n\t"
8852 + "lcall *%%ss:apm_bios_entry\n\t"
8853 "setc %%bl\n\t"
8854 "popl %%ebp\n\t"
8855 "popl %%edi\n\t"
8856 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
8857 index 58cb6d4..ca9010d 100644
8858 --- a/arch/x86/include/asm/atomic.h
8859 +++ b/arch/x86/include/asm/atomic.h
8860 @@ -22,7 +22,18 @@
8861 */
8862 static inline int atomic_read(const atomic_t *v)
8863 {
8864 - return (*(volatile int *)&(v)->counter);
8865 + return (*(volatile const int *)&(v)->counter);
8866 +}
8867 +
8868 +/**
8869 + * atomic_read_unchecked - read atomic variable
8870 + * @v: pointer of type atomic_unchecked_t
8871 + *
8872 + * Atomically reads the value of @v.
8873 + */
8874 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8875 +{
8876 + return (*(volatile const int *)&(v)->counter);
8877 }
8878
8879 /**
8880 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
8881 }
8882
8883 /**
8884 + * atomic_set_unchecked - set atomic variable
8885 + * @v: pointer of type atomic_unchecked_t
8886 + * @i: required value
8887 + *
8888 + * Atomically sets the value of @v to @i.
8889 + */
8890 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8891 +{
8892 + v->counter = i;
8893 +}
8894 +
8895 +/**
8896 * atomic_add - add integer to atomic variable
8897 * @i: integer value to add
8898 * @v: pointer of type atomic_t
8899 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
8900 */
8901 static inline void atomic_add(int i, atomic_t *v)
8902 {
8903 - asm volatile(LOCK_PREFIX "addl %1,%0"
8904 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8905 +
8906 +#ifdef CONFIG_PAX_REFCOUNT
8907 + "jno 0f\n"
8908 + LOCK_PREFIX "subl %1,%0\n"
8909 + "int $4\n0:\n"
8910 + _ASM_EXTABLE(0b, 0b)
8911 +#endif
8912 +
8913 + : "+m" (v->counter)
8914 + : "ir" (i));
8915 +}
8916 +
8917 +/**
8918 + * atomic_add_unchecked - add integer to atomic variable
8919 + * @i: integer value to add
8920 + * @v: pointer of type atomic_unchecked_t
8921 + *
8922 + * Atomically adds @i to @v.
8923 + */
8924 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8925 +{
8926 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8927 : "+m" (v->counter)
8928 : "ir" (i));
8929 }
8930 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
8931 */
8932 static inline void atomic_sub(int i, atomic_t *v)
8933 {
8934 - asm volatile(LOCK_PREFIX "subl %1,%0"
8935 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8936 +
8937 +#ifdef CONFIG_PAX_REFCOUNT
8938 + "jno 0f\n"
8939 + LOCK_PREFIX "addl %1,%0\n"
8940 + "int $4\n0:\n"
8941 + _ASM_EXTABLE(0b, 0b)
8942 +#endif
8943 +
8944 + : "+m" (v->counter)
8945 + : "ir" (i));
8946 +}
8947 +
8948 +/**
8949 + * atomic_sub_unchecked - subtract integer from atomic variable
8950 + * @i: integer value to subtract
8951 + * @v: pointer of type atomic_unchecked_t
8952 + *
8953 + * Atomically subtracts @i from @v.
8954 + */
8955 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8956 +{
8957 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8958 : "+m" (v->counter)
8959 : "ir" (i));
8960 }
8961 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8962 {
8963 unsigned char c;
8964
8965 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8966 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
8967 +
8968 +#ifdef CONFIG_PAX_REFCOUNT
8969 + "jno 0f\n"
8970 + LOCK_PREFIX "addl %2,%0\n"
8971 + "int $4\n0:\n"
8972 + _ASM_EXTABLE(0b, 0b)
8973 +#endif
8974 +
8975 + "sete %1\n"
8976 : "+m" (v->counter), "=qm" (c)
8977 : "ir" (i) : "memory");
8978 return c;
8979 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8980 */
8981 static inline void atomic_inc(atomic_t *v)
8982 {
8983 - asm volatile(LOCK_PREFIX "incl %0"
8984 + asm volatile(LOCK_PREFIX "incl %0\n"
8985 +
8986 +#ifdef CONFIG_PAX_REFCOUNT
8987 + "jno 0f\n"
8988 + LOCK_PREFIX "decl %0\n"
8989 + "int $4\n0:\n"
8990 + _ASM_EXTABLE(0b, 0b)
8991 +#endif
8992 +
8993 + : "+m" (v->counter));
8994 +}
8995 +
8996 +/**
8997 + * atomic_inc_unchecked - increment atomic variable
8998 + * @v: pointer of type atomic_unchecked_t
8999 + *
9000 + * Atomically increments @v by 1.
9001 + */
9002 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9003 +{
9004 + asm volatile(LOCK_PREFIX "incl %0\n"
9005 : "+m" (v->counter));
9006 }
9007
9008 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9009 */
9010 static inline void atomic_dec(atomic_t *v)
9011 {
9012 - asm volatile(LOCK_PREFIX "decl %0"
9013 + asm volatile(LOCK_PREFIX "decl %0\n"
9014 +
9015 +#ifdef CONFIG_PAX_REFCOUNT
9016 + "jno 0f\n"
9017 + LOCK_PREFIX "incl %0\n"
9018 + "int $4\n0:\n"
9019 + _ASM_EXTABLE(0b, 0b)
9020 +#endif
9021 +
9022 + : "+m" (v->counter));
9023 +}
9024 +
9025 +/**
9026 + * atomic_dec_unchecked - decrement atomic variable
9027 + * @v: pointer of type atomic_unchecked_t
9028 + *
9029 + * Atomically decrements @v by 1.
9030 + */
9031 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9032 +{
9033 + asm volatile(LOCK_PREFIX "decl %0\n"
9034 : "+m" (v->counter));
9035 }
9036
9037 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9038 {
9039 unsigned char c;
9040
9041 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9042 + asm volatile(LOCK_PREFIX "decl %0\n"
9043 +
9044 +#ifdef CONFIG_PAX_REFCOUNT
9045 + "jno 0f\n"
9046 + LOCK_PREFIX "incl %0\n"
9047 + "int $4\n0:\n"
9048 + _ASM_EXTABLE(0b, 0b)
9049 +#endif
9050 +
9051 + "sete %1\n"
9052 : "+m" (v->counter), "=qm" (c)
9053 : : "memory");
9054 return c != 0;
9055 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9056 {
9057 unsigned char c;
9058
9059 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9060 + asm volatile(LOCK_PREFIX "incl %0\n"
9061 +
9062 +#ifdef CONFIG_PAX_REFCOUNT
9063 + "jno 0f\n"
9064 + LOCK_PREFIX "decl %0\n"
9065 + "int $4\n0:\n"
9066 + _ASM_EXTABLE(0b, 0b)
9067 +#endif
9068 +
9069 + "sete %1\n"
9070 + : "+m" (v->counter), "=qm" (c)
9071 + : : "memory");
9072 + return c != 0;
9073 +}
9074 +
9075 +/**
9076 + * atomic_inc_and_test_unchecked - increment and test
9077 + * @v: pointer of type atomic_unchecked_t
9078 + *
9079 + * Atomically increments @v by 1
9080 + * and returns true if the result is zero, or false for all
9081 + * other cases.
9082 + */
9083 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9084 +{
9085 + unsigned char c;
9086 +
9087 + asm volatile(LOCK_PREFIX "incl %0\n"
9088 + "sete %1\n"
9089 : "+m" (v->counter), "=qm" (c)
9090 : : "memory");
9091 return c != 0;
9092 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9093 {
9094 unsigned char c;
9095
9096 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9097 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9098 +
9099 +#ifdef CONFIG_PAX_REFCOUNT
9100 + "jno 0f\n"
9101 + LOCK_PREFIX "subl %2,%0\n"
9102 + "int $4\n0:\n"
9103 + _ASM_EXTABLE(0b, 0b)
9104 +#endif
9105 +
9106 + "sets %1\n"
9107 : "+m" (v->counter), "=qm" (c)
9108 : "ir" (i) : "memory");
9109 return c;
9110 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9111 goto no_xadd;
9112 #endif
9113 /* Modern 486+ processor */
9114 - return i + xadd(&v->counter, i);
9115 + return i + xadd_check_overflow(&v->counter, i);
9116
9117 #ifdef CONFIG_M386
9118 no_xadd: /* Legacy 386 processor */
9119 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9120 }
9121
9122 /**
9123 + * atomic_add_return_unchecked - add integer and return
9124 + * @i: integer value to add
9125 + * @v: pointer of type atomic_unchecked_t
9126 + *
9127 + * Atomically adds @i to @v and returns @i + @v
9128 + */
9129 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9130 +{
9131 +#ifdef CONFIG_M386
9132 + int __i;
9133 + unsigned long flags;
9134 + if (unlikely(boot_cpu_data.x86 <= 3))
9135 + goto no_xadd;
9136 +#endif
9137 + /* Modern 486+ processor */
9138 + return i + xadd(&v->counter, i);
9139 +
9140 +#ifdef CONFIG_M386
9141 +no_xadd: /* Legacy 386 processor */
9142 + raw_local_irq_save(flags);
9143 + __i = atomic_read_unchecked(v);
9144 + atomic_set_unchecked(v, i + __i);
9145 + raw_local_irq_restore(flags);
9146 + return i + __i;
9147 +#endif
9148 +}
9149 +
9150 +/**
9151 * atomic_sub_return - subtract integer and return
9152 * @v: pointer of type atomic_t
9153 * @i: integer value to subtract
9154 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9155 }
9156
9157 #define atomic_inc_return(v) (atomic_add_return(1, v))
9158 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9159 +{
9160 + return atomic_add_return_unchecked(1, v);
9161 +}
9162 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9163
9164 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9165 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9166 return cmpxchg(&v->counter, old, new);
9167 }
9168
9169 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9170 +{
9171 + return cmpxchg(&v->counter, old, new);
9172 +}
9173 +
9174 static inline int atomic_xchg(atomic_t *v, int new)
9175 {
9176 return xchg(&v->counter, new);
9177 }
9178
9179 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9180 +{
9181 + return xchg(&v->counter, new);
9182 +}
9183 +
9184 /**
9185 * __atomic_add_unless - add unless the number is already a given value
9186 * @v: pointer of type atomic_t
9187 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9188 */
9189 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9190 {
9191 - int c, old;
9192 + int c, old, new;
9193 c = atomic_read(v);
9194 for (;;) {
9195 - if (unlikely(c == (u)))
9196 + if (unlikely(c == u))
9197 break;
9198 - old = atomic_cmpxchg((v), c, c + (a));
9199 +
9200 + asm volatile("addl %2,%0\n"
9201 +
9202 +#ifdef CONFIG_PAX_REFCOUNT
9203 + "jno 0f\n"
9204 + "subl %2,%0\n"
9205 + "int $4\n0:\n"
9206 + _ASM_EXTABLE(0b, 0b)
9207 +#endif
9208 +
9209 + : "=r" (new)
9210 + : "0" (c), "ir" (a));
9211 +
9212 + old = atomic_cmpxchg(v, c, new);
9213 if (likely(old == c))
9214 break;
9215 c = old;
9216 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9217 return c;
9218 }
9219
9220 +/**
9221 + * atomic_inc_not_zero_hint - increment if not null
9222 + * @v: pointer of type atomic_t
9223 + * @hint: probable value of the atomic before the increment
9224 + *
9225 + * This version of atomic_inc_not_zero() gives a hint of probable
9226 + * value of the atomic. This helps processor to not read the memory
9227 + * before doing the atomic read/modify/write cycle, lowering
9228 + * number of bus transactions on some arches.
9229 + *
9230 + * Returns: 0 if increment was not done, 1 otherwise.
9231 + */
9232 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9233 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9234 +{
9235 + int val, c = hint, new;
9236 +
9237 + /* sanity test, should be removed by compiler if hint is a constant */
9238 + if (!hint)
9239 + return __atomic_add_unless(v, 1, 0);
9240 +
9241 + do {
9242 + asm volatile("incl %0\n"
9243 +
9244 +#ifdef CONFIG_PAX_REFCOUNT
9245 + "jno 0f\n"
9246 + "decl %0\n"
9247 + "int $4\n0:\n"
9248 + _ASM_EXTABLE(0b, 0b)
9249 +#endif
9250 +
9251 + : "=r" (new)
9252 + : "0" (c));
9253 +
9254 + val = atomic_cmpxchg(v, c, new);
9255 + if (val == c)
9256 + return 1;
9257 + c = val;
9258 + } while (c);
9259 +
9260 + return 0;
9261 +}
9262
9263 /*
9264 * atomic_dec_if_positive - decrement by 1 if old value positive
9265 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9266 index fa13f0e..27c2e08 100644
9267 --- a/arch/x86/include/asm/atomic64_32.h
9268 +++ b/arch/x86/include/asm/atomic64_32.h
9269 @@ -12,6 +12,14 @@ typedef struct {
9270 u64 __aligned(8) counter;
9271 } atomic64_t;
9272
9273 +#ifdef CONFIG_PAX_REFCOUNT
9274 +typedef struct {
9275 + u64 __aligned(8) counter;
9276 +} atomic64_unchecked_t;
9277 +#else
9278 +typedef atomic64_t atomic64_unchecked_t;
9279 +#endif
9280 +
9281 #define ATOMIC64_INIT(val) { (val) }
9282
9283 #ifdef CONFIG_X86_CMPXCHG64
9284 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9285 }
9286
9287 /**
9288 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9289 + * @p: pointer to type atomic64_unchecked_t
9290 + * @o: expected value
9291 + * @n: new value
9292 + *
9293 + * Atomically sets @v to @n if it was equal to @o and returns
9294 + * the old value.
9295 + */
9296 +
9297 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9298 +{
9299 + return cmpxchg64(&v->counter, o, n);
9300 +}
9301 +
9302 +/**
9303 * atomic64_xchg - xchg atomic64 variable
9304 * @v: pointer to type atomic64_t
9305 * @n: value to assign
9306 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9307 }
9308
9309 /**
9310 + * atomic64_set_unchecked - set atomic64 variable
9311 + * @v: pointer to type atomic64_unchecked_t
9312 + * @n: value to assign
9313 + *
9314 + * Atomically sets the value of @v to @n.
9315 + */
9316 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9317 +{
9318 + unsigned high = (unsigned)(i >> 32);
9319 + unsigned low = (unsigned)i;
9320 + asm volatile(ATOMIC64_ALTERNATIVE(set)
9321 + : "+b" (low), "+c" (high)
9322 + : "S" (v)
9323 + : "eax", "edx", "memory"
9324 + );
9325 +}
9326 +
9327 +/**
9328 * atomic64_read - read atomic64 variable
9329 * @v: pointer to type atomic64_t
9330 *
9331 @@ -93,6 +134,22 @@ static inline long long atomic64_read(const atomic64_t *v)
9332 }
9333
9334 /**
9335 + * atomic64_read_unchecked - read atomic64 variable
9336 + * @v: pointer to type atomic64_unchecked_t
9337 + *
9338 + * Atomically reads the value of @v and returns it.
9339 + */
9340 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9341 +{
9342 + long long r;
9343 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
9344 + : "=A" (r), "+c" (v)
9345 + : : "memory"
9346 + );
9347 + return r;
9348 + }
9349 +
9350 +/**
9351 * atomic64_add_return - add and return
9352 * @i: integer value to add
9353 * @v: pointer to type atomic64_t
9354 @@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9355 return i;
9356 }
9357
9358 +/**
9359 + * atomic64_add_return_unchecked - add and return
9360 + * @i: integer value to add
9361 + * @v: pointer to type atomic64_unchecked_t
9362 + *
9363 + * Atomically adds @i to @v and returns @i + *@v
9364 + */
9365 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9366 +{
9367 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
9368 + : "+A" (i), "+c" (v)
9369 + : : "memory"
9370 + );
9371 + return i;
9372 +}
9373 +
9374 /*
9375 * Other variants with different arithmetic operators:
9376 */
9377 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9378 return a;
9379 }
9380
9381 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9382 +{
9383 + long long a;
9384 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
9385 + : "=A" (a)
9386 + : "S" (v)
9387 + : "memory", "ecx"
9388 + );
9389 + return a;
9390 +}
9391 +
9392 static inline long long atomic64_dec_return(atomic64_t *v)
9393 {
9394 long long a;
9395 @@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9396 }
9397
9398 /**
9399 + * atomic64_add_unchecked - add integer to atomic64 variable
9400 + * @i: integer value to add
9401 + * @v: pointer to type atomic64_unchecked_t
9402 + *
9403 + * Atomically adds @i to @v.
9404 + */
9405 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9406 +{
9407 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
9408 + : "+A" (i), "+c" (v)
9409 + : : "memory"
9410 + );
9411 + return i;
9412 +}
9413 +
9414 +/**
9415 * atomic64_sub - subtract the atomic64 variable
9416 * @i: integer value to subtract
9417 * @v: pointer to type atomic64_t
9418 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9419 index 0e1cbfc..5623683 100644
9420 --- a/arch/x86/include/asm/atomic64_64.h
9421 +++ b/arch/x86/include/asm/atomic64_64.h
9422 @@ -18,7 +18,19 @@
9423 */
9424 static inline long atomic64_read(const atomic64_t *v)
9425 {
9426 - return (*(volatile long *)&(v)->counter);
9427 + return (*(volatile const long *)&(v)->counter);
9428 +}
9429 +
9430 +/**
9431 + * atomic64_read_unchecked - read atomic64 variable
9432 + * @v: pointer of type atomic64_unchecked_t
9433 + *
9434 + * Atomically reads the value of @v.
9435 + * Doesn't imply a read memory barrier.
9436 + */
9437 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9438 +{
9439 + return (*(volatile const long *)&(v)->counter);
9440 }
9441
9442 /**
9443 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9444 }
9445
9446 /**
9447 + * atomic64_set_unchecked - set atomic64 variable
9448 + * @v: pointer to type atomic64_unchecked_t
9449 + * @i: required value
9450 + *
9451 + * Atomically sets the value of @v to @i.
9452 + */
9453 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9454 +{
9455 + v->counter = i;
9456 +}
9457 +
9458 +/**
9459 * atomic64_add - add integer to atomic64 variable
9460 * @i: integer value to add
9461 * @v: pointer to type atomic64_t
9462 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9463 */
9464 static inline void atomic64_add(long i, atomic64_t *v)
9465 {
9466 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9467 +
9468 +#ifdef CONFIG_PAX_REFCOUNT
9469 + "jno 0f\n"
9470 + LOCK_PREFIX "subq %1,%0\n"
9471 + "int $4\n0:\n"
9472 + _ASM_EXTABLE(0b, 0b)
9473 +#endif
9474 +
9475 + : "=m" (v->counter)
9476 + : "er" (i), "m" (v->counter));
9477 +}
9478 +
9479 +/**
9480 + * atomic64_add_unchecked - add integer to atomic64 variable
9481 + * @i: integer value to add
9482 + * @v: pointer to type atomic64_unchecked_t
9483 + *
9484 + * Atomically adds @i to @v.
9485 + */
9486 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9487 +{
9488 asm volatile(LOCK_PREFIX "addq %1,%0"
9489 : "=m" (v->counter)
9490 : "er" (i), "m" (v->counter));
9491 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9492 */
9493 static inline void atomic64_sub(long i, atomic64_t *v)
9494 {
9495 - asm volatile(LOCK_PREFIX "subq %1,%0"
9496 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9497 +
9498 +#ifdef CONFIG_PAX_REFCOUNT
9499 + "jno 0f\n"
9500 + LOCK_PREFIX "addq %1,%0\n"
9501 + "int $4\n0:\n"
9502 + _ASM_EXTABLE(0b, 0b)
9503 +#endif
9504 +
9505 + : "=m" (v->counter)
9506 + : "er" (i), "m" (v->counter));
9507 +}
9508 +
9509 +/**
9510 + * atomic64_sub_unchecked - subtract the atomic64 variable
9511 + * @i: integer value to subtract
9512 + * @v: pointer to type atomic64_unchecked_t
9513 + *
9514 + * Atomically subtracts @i from @v.
9515 + */
9516 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9517 +{
9518 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9519 : "=m" (v->counter)
9520 : "er" (i), "m" (v->counter));
9521 }
9522 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9523 {
9524 unsigned char c;
9525
9526 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9527 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9528 +
9529 +#ifdef CONFIG_PAX_REFCOUNT
9530 + "jno 0f\n"
9531 + LOCK_PREFIX "addq %2,%0\n"
9532 + "int $4\n0:\n"
9533 + _ASM_EXTABLE(0b, 0b)
9534 +#endif
9535 +
9536 + "sete %1\n"
9537 : "=m" (v->counter), "=qm" (c)
9538 : "er" (i), "m" (v->counter) : "memory");
9539 return c;
9540 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9541 */
9542 static inline void atomic64_inc(atomic64_t *v)
9543 {
9544 + asm volatile(LOCK_PREFIX "incq %0\n"
9545 +
9546 +#ifdef CONFIG_PAX_REFCOUNT
9547 + "jno 0f\n"
9548 + LOCK_PREFIX "decq %0\n"
9549 + "int $4\n0:\n"
9550 + _ASM_EXTABLE(0b, 0b)
9551 +#endif
9552 +
9553 + : "=m" (v->counter)
9554 + : "m" (v->counter));
9555 +}
9556 +
9557 +/**
9558 + * atomic64_inc_unchecked - increment atomic64 variable
9559 + * @v: pointer to type atomic64_unchecked_t
9560 + *
9561 + * Atomically increments @v by 1.
9562 + */
9563 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9564 +{
9565 asm volatile(LOCK_PREFIX "incq %0"
9566 : "=m" (v->counter)
9567 : "m" (v->counter));
9568 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9569 */
9570 static inline void atomic64_dec(atomic64_t *v)
9571 {
9572 - asm volatile(LOCK_PREFIX "decq %0"
9573 + asm volatile(LOCK_PREFIX "decq %0\n"
9574 +
9575 +#ifdef CONFIG_PAX_REFCOUNT
9576 + "jno 0f\n"
9577 + LOCK_PREFIX "incq %0\n"
9578 + "int $4\n0:\n"
9579 + _ASM_EXTABLE(0b, 0b)
9580 +#endif
9581 +
9582 + : "=m" (v->counter)
9583 + : "m" (v->counter));
9584 +}
9585 +
9586 +/**
9587 + * atomic64_dec_unchecked - decrement atomic64 variable
9588 + * @v: pointer to type atomic64_t
9589 + *
9590 + * Atomically decrements @v by 1.
9591 + */
9592 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9593 +{
9594 + asm volatile(LOCK_PREFIX "decq %0\n"
9595 : "=m" (v->counter)
9596 : "m" (v->counter));
9597 }
9598 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9599 {
9600 unsigned char c;
9601
9602 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9603 + asm volatile(LOCK_PREFIX "decq %0\n"
9604 +
9605 +#ifdef CONFIG_PAX_REFCOUNT
9606 + "jno 0f\n"
9607 + LOCK_PREFIX "incq %0\n"
9608 + "int $4\n0:\n"
9609 + _ASM_EXTABLE(0b, 0b)
9610 +#endif
9611 +
9612 + "sete %1\n"
9613 : "=m" (v->counter), "=qm" (c)
9614 : "m" (v->counter) : "memory");
9615 return c != 0;
9616 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9617 {
9618 unsigned char c;
9619
9620 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9621 + asm volatile(LOCK_PREFIX "incq %0\n"
9622 +
9623 +#ifdef CONFIG_PAX_REFCOUNT
9624 + "jno 0f\n"
9625 + LOCK_PREFIX "decq %0\n"
9626 + "int $4\n0:\n"
9627 + _ASM_EXTABLE(0b, 0b)
9628 +#endif
9629 +
9630 + "sete %1\n"
9631 : "=m" (v->counter), "=qm" (c)
9632 : "m" (v->counter) : "memory");
9633 return c != 0;
9634 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9635 {
9636 unsigned char c;
9637
9638 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9639 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9640 +
9641 +#ifdef CONFIG_PAX_REFCOUNT
9642 + "jno 0f\n"
9643 + LOCK_PREFIX "subq %2,%0\n"
9644 + "int $4\n0:\n"
9645 + _ASM_EXTABLE(0b, 0b)
9646 +#endif
9647 +
9648 + "sets %1\n"
9649 : "=m" (v->counter), "=qm" (c)
9650 : "er" (i), "m" (v->counter) : "memory");
9651 return c;
9652 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9653 */
9654 static inline long atomic64_add_return(long i, atomic64_t *v)
9655 {
9656 + return i + xadd_check_overflow(&v->counter, i);
9657 +}
9658 +
9659 +/**
9660 + * atomic64_add_return_unchecked - add and return
9661 + * @i: integer value to add
9662 + * @v: pointer to type atomic64_unchecked_t
9663 + *
9664 + * Atomically adds @i to @v and returns @i + @v
9665 + */
9666 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9667 +{
9668 return i + xadd(&v->counter, i);
9669 }
9670
9671 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9672 }
9673
9674 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9675 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9676 +{
9677 + return atomic64_add_return_unchecked(1, v);
9678 +}
9679 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9680
9681 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9682 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9683 return cmpxchg(&v->counter, old, new);
9684 }
9685
9686 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9687 +{
9688 + return cmpxchg(&v->counter, old, new);
9689 +}
9690 +
9691 static inline long atomic64_xchg(atomic64_t *v, long new)
9692 {
9693 return xchg(&v->counter, new);
9694 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9695 */
9696 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9697 {
9698 - long c, old;
9699 + long c, old, new;
9700 c = atomic64_read(v);
9701 for (;;) {
9702 - if (unlikely(c == (u)))
9703 + if (unlikely(c == u))
9704 break;
9705 - old = atomic64_cmpxchg((v), c, c + (a));
9706 +
9707 + asm volatile("add %2,%0\n"
9708 +
9709 +#ifdef CONFIG_PAX_REFCOUNT
9710 + "jno 0f\n"
9711 + "sub %2,%0\n"
9712 + "int $4\n0:\n"
9713 + _ASM_EXTABLE(0b, 0b)
9714 +#endif
9715 +
9716 + : "=r" (new)
9717 + : "0" (c), "ir" (a));
9718 +
9719 + old = atomic64_cmpxchg(v, c, new);
9720 if (likely(old == c))
9721 break;
9722 c = old;
9723 }
9724 - return c != (u);
9725 + return c != u;
9726 }
9727
9728 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9729 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9730 index b97596e..9bd48b06 100644
9731 --- a/arch/x86/include/asm/bitops.h
9732 +++ b/arch/x86/include/asm/bitops.h
9733 @@ -38,7 +38,7 @@
9734 * a mask operation on a byte.
9735 */
9736 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9737 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9738 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9739 #define CONST_MASK(nr) (1 << ((nr) & 7))
9740
9741 /**
9742 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9743 index 5e1a2ee..c9f9533 100644
9744 --- a/arch/x86/include/asm/boot.h
9745 +++ b/arch/x86/include/asm/boot.h
9746 @@ -11,10 +11,15 @@
9747 #include <asm/pgtable_types.h>
9748
9749 /* Physical address where kernel should be loaded. */
9750 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9751 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9752 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9753 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9754
9755 +#ifndef __ASSEMBLY__
9756 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
9757 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9758 +#endif
9759 +
9760 /* Minimum kernel alignment, as a power of two */
9761 #ifdef CONFIG_X86_64
9762 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9763 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
9764 index 48f99f1..d78ebf9 100644
9765 --- a/arch/x86/include/asm/cache.h
9766 +++ b/arch/x86/include/asm/cache.h
9767 @@ -5,12 +5,13 @@
9768
9769 /* L1 cache line size */
9770 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9771 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9772 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9773
9774 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9775 +#define __read_only __attribute__((__section__(".data..read_only")))
9776
9777 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9778 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9779 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
9780
9781 #ifdef CONFIG_X86_VSMP
9782 #ifdef CONFIG_SMP
9783 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
9784 index 4e12668..501d239 100644
9785 --- a/arch/x86/include/asm/cacheflush.h
9786 +++ b/arch/x86/include/asm/cacheflush.h
9787 @@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
9788 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9789
9790 if (pg_flags == _PGMT_DEFAULT)
9791 - return -1;
9792 + return ~0UL;
9793 else if (pg_flags == _PGMT_WC)
9794 return _PAGE_CACHE_WC;
9795 else if (pg_flags == _PGMT_UC_MINUS)
9796 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
9797 index 46fc474..b02b0f9 100644
9798 --- a/arch/x86/include/asm/checksum_32.h
9799 +++ b/arch/x86/include/asm/checksum_32.h
9800 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
9801 int len, __wsum sum,
9802 int *src_err_ptr, int *dst_err_ptr);
9803
9804 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9805 + int len, __wsum sum,
9806 + int *src_err_ptr, int *dst_err_ptr);
9807 +
9808 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9809 + int len, __wsum sum,
9810 + int *src_err_ptr, int *dst_err_ptr);
9811 +
9812 /*
9813 * Note: when you get a NULL pointer exception here this means someone
9814 * passed in an incorrect kernel address to one of these functions.
9815 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
9816 int *err_ptr)
9817 {
9818 might_sleep();
9819 - return csum_partial_copy_generic((__force void *)src, dst,
9820 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
9821 len, sum, err_ptr, NULL);
9822 }
9823
9824 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
9825 {
9826 might_sleep();
9827 if (access_ok(VERIFY_WRITE, dst, len))
9828 - return csum_partial_copy_generic(src, (__force void *)dst,
9829 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9830 len, sum, NULL, err_ptr);
9831
9832 if (len)
9833 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
9834 index 99480e5..d81165b 100644
9835 --- a/arch/x86/include/asm/cmpxchg.h
9836 +++ b/arch/x86/include/asm/cmpxchg.h
9837 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
9838 __compiletime_error("Bad argument size for cmpxchg");
9839 extern void __xadd_wrong_size(void)
9840 __compiletime_error("Bad argument size for xadd");
9841 +extern void __xadd_check_overflow_wrong_size(void)
9842 + __compiletime_error("Bad argument size for xadd_check_overflow");
9843 extern void __add_wrong_size(void)
9844 __compiletime_error("Bad argument size for add");
9845 +extern void __add_check_overflow_wrong_size(void)
9846 + __compiletime_error("Bad argument size for add_check_overflow");
9847
9848 /*
9849 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
9850 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
9851 __ret; \
9852 })
9853
9854 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
9855 + ({ \
9856 + __typeof__ (*(ptr)) __ret = (arg); \
9857 + switch (sizeof(*(ptr))) { \
9858 + case __X86_CASE_L: \
9859 + asm volatile (lock #op "l %0, %1\n" \
9860 + "jno 0f\n" \
9861 + "mov %0,%1\n" \
9862 + "int $4\n0:\n" \
9863 + _ASM_EXTABLE(0b, 0b) \
9864 + : "+r" (__ret), "+m" (*(ptr)) \
9865 + : : "memory", "cc"); \
9866 + break; \
9867 + case __X86_CASE_Q: \
9868 + asm volatile (lock #op "q %q0, %1\n" \
9869 + "jno 0f\n" \
9870 + "mov %0,%1\n" \
9871 + "int $4\n0:\n" \
9872 + _ASM_EXTABLE(0b, 0b) \
9873 + : "+r" (__ret), "+m" (*(ptr)) \
9874 + : : "memory", "cc"); \
9875 + break; \
9876 + default: \
9877 + __ ## op ## _check_overflow_wrong_size(); \
9878 + } \
9879 + __ret; \
9880 + })
9881 +
9882 /*
9883 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
9884 * Since this is generally used to protect other memory information, we
9885 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
9886 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
9887 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
9888
9889 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
9890 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
9891 +
9892 #define __add(ptr, inc, lock) \
9893 ({ \
9894 __typeof__ (*(ptr)) __ret = (inc); \
9895 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
9896 index 8d67d42..183d0eb 100644
9897 --- a/arch/x86/include/asm/cpufeature.h
9898 +++ b/arch/x86/include/asm/cpufeature.h
9899 @@ -367,7 +367,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
9900 ".section .discard,\"aw\",@progbits\n"
9901 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9902 ".previous\n"
9903 - ".section .altinstr_replacement,\"ax\"\n"
9904 + ".section .altinstr_replacement,\"a\"\n"
9905 "3: movb $1,%0\n"
9906 "4:\n"
9907 ".previous\n"
9908 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9909 index e95822d..a90010e 100644
9910 --- a/arch/x86/include/asm/desc.h
9911 +++ b/arch/x86/include/asm/desc.h
9912 @@ -4,6 +4,7 @@
9913 #include <asm/desc_defs.h>
9914 #include <asm/ldt.h>
9915 #include <asm/mmu.h>
9916 +#include <asm/pgtable.h>
9917
9918 #include <linux/smp.h>
9919
9920 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9921
9922 desc->type = (info->read_exec_only ^ 1) << 1;
9923 desc->type |= info->contents << 2;
9924 + desc->type |= info->seg_not_present ^ 1;
9925
9926 desc->s = 1;
9927 desc->dpl = 0x3;
9928 @@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9929 }
9930
9931 extern struct desc_ptr idt_descr;
9932 -extern gate_desc idt_table[];
9933 extern struct desc_ptr nmi_idt_descr;
9934 -extern gate_desc nmi_idt_table[];
9935 -
9936 -struct gdt_page {
9937 - struct desc_struct gdt[GDT_ENTRIES];
9938 -} __attribute__((aligned(PAGE_SIZE)));
9939 -
9940 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9941 +extern gate_desc idt_table[256];
9942 +extern gate_desc nmi_idt_table[256];
9943
9944 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9945 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9946 {
9947 - return per_cpu(gdt_page, cpu).gdt;
9948 + return cpu_gdt_table[cpu];
9949 }
9950
9951 #ifdef CONFIG_X86_64
9952 @@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
9953 unsigned long base, unsigned dpl, unsigned flags,
9954 unsigned short seg)
9955 {
9956 - gate->a = (seg << 16) | (base & 0xffff);
9957 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9958 + gate->gate.offset_low = base;
9959 + gate->gate.seg = seg;
9960 + gate->gate.reserved = 0;
9961 + gate->gate.type = type;
9962 + gate->gate.s = 0;
9963 + gate->gate.dpl = dpl;
9964 + gate->gate.p = 1;
9965 + gate->gate.offset_high = base >> 16;
9966 }
9967
9968 #endif
9969 @@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
9970
9971 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
9972 {
9973 + pax_open_kernel();
9974 memcpy(&idt[entry], gate, sizeof(*gate));
9975 + pax_close_kernel();
9976 }
9977
9978 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
9979 {
9980 + pax_open_kernel();
9981 memcpy(&ldt[entry], desc, 8);
9982 + pax_close_kernel();
9983 }
9984
9985 static inline void
9986 @@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
9987 default: size = sizeof(*gdt); break;
9988 }
9989
9990 + pax_open_kernel();
9991 memcpy(&gdt[entry], desc, size);
9992 + pax_close_kernel();
9993 }
9994
9995 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9996 @@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
9997
9998 static inline void native_load_tr_desc(void)
9999 {
10000 + pax_open_kernel();
10001 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10002 + pax_close_kernel();
10003 }
10004
10005 static inline void native_load_gdt(const struct desc_ptr *dtr)
10006 @@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10007 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10008 unsigned int i;
10009
10010 + pax_open_kernel();
10011 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10012 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10013 + pax_close_kernel();
10014 }
10015
10016 #define _LDT_empty(info) \
10017 @@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10018 }
10019
10020 #ifdef CONFIG_X86_64
10021 -static inline void set_nmi_gate(int gate, void *addr)
10022 +static inline void set_nmi_gate(int gate, const void *addr)
10023 {
10024 gate_desc s;
10025
10026 @@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10027 }
10028 #endif
10029
10030 -static inline void _set_gate(int gate, unsigned type, void *addr,
10031 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10032 unsigned dpl, unsigned ist, unsigned seg)
10033 {
10034 gate_desc s;
10035 @@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10036 * Pentium F0 0F bugfix can have resulted in the mapped
10037 * IDT being write-protected.
10038 */
10039 -static inline void set_intr_gate(unsigned int n, void *addr)
10040 +static inline void set_intr_gate(unsigned int n, const void *addr)
10041 {
10042 BUG_ON((unsigned)n > 0xFF);
10043 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10044 @@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10045 /*
10046 * This routine sets up an interrupt gate at directory privilege level 3.
10047 */
10048 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10049 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10050 {
10051 BUG_ON((unsigned)n > 0xFF);
10052 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10053 }
10054
10055 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10056 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10057 {
10058 BUG_ON((unsigned)n > 0xFF);
10059 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10060 }
10061
10062 -static inline void set_trap_gate(unsigned int n, void *addr)
10063 +static inline void set_trap_gate(unsigned int n, const void *addr)
10064 {
10065 BUG_ON((unsigned)n > 0xFF);
10066 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10067 @@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10068 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10069 {
10070 BUG_ON((unsigned)n > 0xFF);
10071 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10072 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10073 }
10074
10075 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10076 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10077 {
10078 BUG_ON((unsigned)n > 0xFF);
10079 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10080 }
10081
10082 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10083 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10084 {
10085 BUG_ON((unsigned)n > 0xFF);
10086 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10087 }
10088
10089 +#ifdef CONFIG_X86_32
10090 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10091 +{
10092 + struct desc_struct d;
10093 +
10094 + if (likely(limit))
10095 + limit = (limit - 1UL) >> PAGE_SHIFT;
10096 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10097 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10098 +}
10099 +#endif
10100 +
10101 #endif /* _ASM_X86_DESC_H */
10102 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10103 index 278441f..b95a174 100644
10104 --- a/arch/x86/include/asm/desc_defs.h
10105 +++ b/arch/x86/include/asm/desc_defs.h
10106 @@ -31,6 +31,12 @@ struct desc_struct {
10107 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10108 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10109 };
10110 + struct {
10111 + u16 offset_low;
10112 + u16 seg;
10113 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10114 + unsigned offset_high: 16;
10115 + } gate;
10116 };
10117 } __attribute__((packed));
10118
10119 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10120 index 3778256..c5d4fce 100644
10121 --- a/arch/x86/include/asm/e820.h
10122 +++ b/arch/x86/include/asm/e820.h
10123 @@ -69,7 +69,7 @@ struct e820map {
10124 #define ISA_START_ADDRESS 0xa0000
10125 #define ISA_END_ADDRESS 0x100000
10126
10127 -#define BIOS_BEGIN 0x000a0000
10128 +#define BIOS_BEGIN 0x000c0000
10129 #define BIOS_END 0x00100000
10130
10131 #define BIOS_ROM_BASE 0xffe00000
10132 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10133 index 5f962df..7289f09 100644
10134 --- a/arch/x86/include/asm/elf.h
10135 +++ b/arch/x86/include/asm/elf.h
10136 @@ -238,7 +238,25 @@ extern int force_personality32;
10137 the loader. We need to make sure that it is out of the way of the program
10138 that it will "exec", and that there is sufficient room for the brk. */
10139
10140 +#ifdef CONFIG_PAX_SEGMEXEC
10141 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10142 +#else
10143 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10144 +#endif
10145 +
10146 +#ifdef CONFIG_PAX_ASLR
10147 +#ifdef CONFIG_X86_32
10148 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10149 +
10150 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10151 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10152 +#else
10153 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10154 +
10155 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10156 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10157 +#endif
10158 +#endif
10159
10160 /* This yields a mask that user programs can use to figure out what
10161 instruction set this CPU supports. This could be done in user space,
10162 @@ -291,9 +309,7 @@ do { \
10163
10164 #define ARCH_DLINFO \
10165 do { \
10166 - if (vdso_enabled) \
10167 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10168 - (unsigned long)current->mm->context.vdso); \
10169 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10170 } while (0)
10171
10172 #define AT_SYSINFO 32
10173 @@ -304,7 +320,7 @@ do { \
10174
10175 #endif /* !CONFIG_X86_32 */
10176
10177 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10178 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10179
10180 #define VDSO_ENTRY \
10181 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10182 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
10183 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10184 #define compat_arch_setup_additional_pages syscall32_setup_pages
10185
10186 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10187 -#define arch_randomize_brk arch_randomize_brk
10188 -
10189 /*
10190 * True on X86_32 or when emulating IA32 on X86_64
10191 */
10192 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10193 index cc70c1c..d96d011 100644
10194 --- a/arch/x86/include/asm/emergency-restart.h
10195 +++ b/arch/x86/include/asm/emergency-restart.h
10196 @@ -15,6 +15,6 @@ enum reboot_type {
10197
10198 extern enum reboot_type reboot_type;
10199
10200 -extern void machine_emergency_restart(void);
10201 +extern void machine_emergency_restart(void) __noreturn;
10202
10203 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10204 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
10205 index dbe82a5..c6d8a00 100644
10206 --- a/arch/x86/include/asm/floppy.h
10207 +++ b/arch/x86/include/asm/floppy.h
10208 @@ -157,6 +157,7 @@ static unsigned long dma_mem_alloc(unsigned long size)
10209 }
10210
10211
10212 +static unsigned long vdma_mem_alloc(unsigned long size) __size_overflow(1);
10213 static unsigned long vdma_mem_alloc(unsigned long size)
10214 {
10215 return (unsigned long)vmalloc(size);
10216 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10217 index d09bb03..4ea4194 100644
10218 --- a/arch/x86/include/asm/futex.h
10219 +++ b/arch/x86/include/asm/futex.h
10220 @@ -12,16 +12,18 @@
10221 #include <asm/system.h>
10222
10223 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10224 + typecheck(u32 __user *, uaddr); \
10225 asm volatile("1:\t" insn "\n" \
10226 "2:\t.section .fixup,\"ax\"\n" \
10227 "3:\tmov\t%3, %1\n" \
10228 "\tjmp\t2b\n" \
10229 "\t.previous\n" \
10230 _ASM_EXTABLE(1b, 3b) \
10231 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10232 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10233 : "i" (-EFAULT), "0" (oparg), "1" (0))
10234
10235 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10236 + typecheck(u32 __user *, uaddr); \
10237 asm volatile("1:\tmovl %2, %0\n" \
10238 "\tmovl\t%0, %3\n" \
10239 "\t" insn "\n" \
10240 @@ -34,7 +36,7 @@
10241 _ASM_EXTABLE(1b, 4b) \
10242 _ASM_EXTABLE(2b, 4b) \
10243 : "=&a" (oldval), "=&r" (ret), \
10244 - "+m" (*uaddr), "=&r" (tem) \
10245 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10246 : "r" (oparg), "i" (-EFAULT), "1" (0))
10247
10248 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10249 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10250
10251 switch (op) {
10252 case FUTEX_OP_SET:
10253 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10254 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10255 break;
10256 case FUTEX_OP_ADD:
10257 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10258 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10259 uaddr, oparg);
10260 break;
10261 case FUTEX_OP_OR:
10262 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10263 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10264 return -EFAULT;
10265
10266 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10267 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10268 "2:\t.section .fixup, \"ax\"\n"
10269 "3:\tmov %3, %0\n"
10270 "\tjmp 2b\n"
10271 "\t.previous\n"
10272 _ASM_EXTABLE(1b, 3b)
10273 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10274 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10275 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10276 : "memory"
10277 );
10278 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10279 index eb92a6e..b98b2f4 100644
10280 --- a/arch/x86/include/asm/hw_irq.h
10281 +++ b/arch/x86/include/asm/hw_irq.h
10282 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10283 extern void enable_IO_APIC(void);
10284
10285 /* Statistics */
10286 -extern atomic_t irq_err_count;
10287 -extern atomic_t irq_mis_count;
10288 +extern atomic_unchecked_t irq_err_count;
10289 +extern atomic_unchecked_t irq_mis_count;
10290
10291 /* EISA */
10292 extern void eisa_set_level_irq(unsigned int irq);
10293 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10294 index 2479049..3fb9795 100644
10295 --- a/arch/x86/include/asm/i387.h
10296 +++ b/arch/x86/include/asm/i387.h
10297 @@ -93,6 +93,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10298 {
10299 int err;
10300
10301 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10302 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10303 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10304 +#endif
10305 +
10306 /* See comment in fxsave() below. */
10307 #ifdef CONFIG_AS_FXSAVEQ
10308 asm volatile("1: fxrstorq %[fx]\n\t"
10309 @@ -122,6 +127,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10310 {
10311 int err;
10312
10313 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10314 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10315 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10316 +#endif
10317 +
10318 /*
10319 * Clear the bytes not touched by the fxsave and reserved
10320 * for the SW usage.
10321 @@ -278,7 +288,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10322 "emms\n\t" /* clear stack tags */
10323 "fildl %P[addr]", /* set F?P to defined value */
10324 X86_FEATURE_FXSAVE_LEAK,
10325 - [addr] "m" (tsk->thread.fpu.has_fpu));
10326 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10327
10328 return fpu_restore_checking(&tsk->thread.fpu);
10329 }
10330 @@ -445,7 +455,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
10331 static inline bool interrupted_user_mode(void)
10332 {
10333 struct pt_regs *regs = get_irq_regs();
10334 - return regs && user_mode_vm(regs);
10335 + return regs && user_mode(regs);
10336 }
10337
10338 /*
10339 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10340 index d8e8eef..99f81ae 100644
10341 --- a/arch/x86/include/asm/io.h
10342 +++ b/arch/x86/include/asm/io.h
10343 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10344
10345 #include <linux/vmalloc.h>
10346
10347 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10348 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10349 +{
10350 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10351 +}
10352 +
10353 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10354 +{
10355 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10356 +}
10357 +
10358 /*
10359 * Convert a virtual cached pointer to an uncached pointer
10360 */
10361 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10362 index bba3cf8..06bc8da 100644
10363 --- a/arch/x86/include/asm/irqflags.h
10364 +++ b/arch/x86/include/asm/irqflags.h
10365 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10366 sti; \
10367 sysexit
10368
10369 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10370 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10371 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10372 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10373 +
10374 #else
10375 #define INTERRUPT_RETURN iret
10376 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10377 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10378 index 5478825..839e88c 100644
10379 --- a/arch/x86/include/asm/kprobes.h
10380 +++ b/arch/x86/include/asm/kprobes.h
10381 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10382 #define RELATIVEJUMP_SIZE 5
10383 #define RELATIVECALL_OPCODE 0xe8
10384 #define RELATIVE_ADDR_SIZE 4
10385 -#define MAX_STACK_SIZE 64
10386 -#define MIN_STACK_SIZE(ADDR) \
10387 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10388 - THREAD_SIZE - (unsigned long)(ADDR))) \
10389 - ? (MAX_STACK_SIZE) \
10390 - : (((unsigned long)current_thread_info()) + \
10391 - THREAD_SIZE - (unsigned long)(ADDR)))
10392 +#define MAX_STACK_SIZE 64UL
10393 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10394
10395 #define flush_insn_slot(p) do { } while (0)
10396
10397 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10398 index 52d6640..136b3bd 100644
10399 --- a/arch/x86/include/asm/kvm_host.h
10400 +++ b/arch/x86/include/asm/kvm_host.h
10401 @@ -663,7 +663,7 @@ struct kvm_x86_ops {
10402 int (*check_intercept)(struct kvm_vcpu *vcpu,
10403 struct x86_instruction_info *info,
10404 enum x86_intercept_stage stage);
10405 -};
10406 +} __do_const;
10407
10408 struct kvm_arch_async_pf {
10409 u32 token;
10410 @@ -694,7 +694,7 @@ void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
10411 int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3);
10412
10413 int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
10414 - const void *val, int bytes);
10415 + const void *val, int bytes) __size_overflow(2);
10416 u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn);
10417
10418 extern bool tdp_enabled;
10419 @@ -781,7 +781,7 @@ int fx_init(struct kvm_vcpu *vcpu);
10420
10421 void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu);
10422 void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
10423 - const u8 *new, int bytes);
10424 + const u8 *new, int bytes) __size_overflow(2);
10425 int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn);
10426 int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
10427 void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
10428 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10429 index 9cdae5d..300d20f 100644
10430 --- a/arch/x86/include/asm/local.h
10431 +++ b/arch/x86/include/asm/local.h
10432 @@ -18,26 +18,58 @@ typedef struct {
10433
10434 static inline void local_inc(local_t *l)
10435 {
10436 - asm volatile(_ASM_INC "%0"
10437 + asm volatile(_ASM_INC "%0\n"
10438 +
10439 +#ifdef CONFIG_PAX_REFCOUNT
10440 + "jno 0f\n"
10441 + _ASM_DEC "%0\n"
10442 + "int $4\n0:\n"
10443 + _ASM_EXTABLE(0b, 0b)
10444 +#endif
10445 +
10446 : "+m" (l->a.counter));
10447 }
10448
10449 static inline void local_dec(local_t *l)
10450 {
10451 - asm volatile(_ASM_DEC "%0"
10452 + asm volatile(_ASM_DEC "%0\n"
10453 +
10454 +#ifdef CONFIG_PAX_REFCOUNT
10455 + "jno 0f\n"
10456 + _ASM_INC "%0\n"
10457 + "int $4\n0:\n"
10458 + _ASM_EXTABLE(0b, 0b)
10459 +#endif
10460 +
10461 : "+m" (l->a.counter));
10462 }
10463
10464 static inline void local_add(long i, local_t *l)
10465 {
10466 - asm volatile(_ASM_ADD "%1,%0"
10467 + asm volatile(_ASM_ADD "%1,%0\n"
10468 +
10469 +#ifdef CONFIG_PAX_REFCOUNT
10470 + "jno 0f\n"
10471 + _ASM_SUB "%1,%0\n"
10472 + "int $4\n0:\n"
10473 + _ASM_EXTABLE(0b, 0b)
10474 +#endif
10475 +
10476 : "+m" (l->a.counter)
10477 : "ir" (i));
10478 }
10479
10480 static inline void local_sub(long i, local_t *l)
10481 {
10482 - asm volatile(_ASM_SUB "%1,%0"
10483 + asm volatile(_ASM_SUB "%1,%0\n"
10484 +
10485 +#ifdef CONFIG_PAX_REFCOUNT
10486 + "jno 0f\n"
10487 + _ASM_ADD "%1,%0\n"
10488 + "int $4\n0:\n"
10489 + _ASM_EXTABLE(0b, 0b)
10490 +#endif
10491 +
10492 : "+m" (l->a.counter)
10493 : "ir" (i));
10494 }
10495 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10496 {
10497 unsigned char c;
10498
10499 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10500 + asm volatile(_ASM_SUB "%2,%0\n"
10501 +
10502 +#ifdef CONFIG_PAX_REFCOUNT
10503 + "jno 0f\n"
10504 + _ASM_ADD "%2,%0\n"
10505 + "int $4\n0:\n"
10506 + _ASM_EXTABLE(0b, 0b)
10507 +#endif
10508 +
10509 + "sete %1\n"
10510 : "+m" (l->a.counter), "=qm" (c)
10511 : "ir" (i) : "memory");
10512 return c;
10513 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10514 {
10515 unsigned char c;
10516
10517 - asm volatile(_ASM_DEC "%0; sete %1"
10518 + asm volatile(_ASM_DEC "%0\n"
10519 +
10520 +#ifdef CONFIG_PAX_REFCOUNT
10521 + "jno 0f\n"
10522 + _ASM_INC "%0\n"
10523 + "int $4\n0:\n"
10524 + _ASM_EXTABLE(0b, 0b)
10525 +#endif
10526 +
10527 + "sete %1\n"
10528 : "+m" (l->a.counter), "=qm" (c)
10529 : : "memory");
10530 return c != 0;
10531 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10532 {
10533 unsigned char c;
10534
10535 - asm volatile(_ASM_INC "%0; sete %1"
10536 + asm volatile(_ASM_INC "%0\n"
10537 +
10538 +#ifdef CONFIG_PAX_REFCOUNT
10539 + "jno 0f\n"
10540 + _ASM_DEC "%0\n"
10541 + "int $4\n0:\n"
10542 + _ASM_EXTABLE(0b, 0b)
10543 +#endif
10544 +
10545 + "sete %1\n"
10546 : "+m" (l->a.counter), "=qm" (c)
10547 : : "memory");
10548 return c != 0;
10549 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10550 {
10551 unsigned char c;
10552
10553 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10554 + asm volatile(_ASM_ADD "%2,%0\n"
10555 +
10556 +#ifdef CONFIG_PAX_REFCOUNT
10557 + "jno 0f\n"
10558 + _ASM_SUB "%2,%0\n"
10559 + "int $4\n0:\n"
10560 + _ASM_EXTABLE(0b, 0b)
10561 +#endif
10562 +
10563 + "sets %1\n"
10564 : "+m" (l->a.counter), "=qm" (c)
10565 : "ir" (i) : "memory");
10566 return c;
10567 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10568 #endif
10569 /* Modern 486+ processor */
10570 __i = i;
10571 - asm volatile(_ASM_XADD "%0, %1;"
10572 + asm volatile(_ASM_XADD "%0, %1\n"
10573 +
10574 +#ifdef CONFIG_PAX_REFCOUNT
10575 + "jno 0f\n"
10576 + _ASM_MOV "%0,%1\n"
10577 + "int $4\n0:\n"
10578 + _ASM_EXTABLE(0b, 0b)
10579 +#endif
10580 +
10581 : "+r" (i), "+m" (l->a.counter)
10582 : : "memory");
10583 return i + __i;
10584 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10585 index 593e51d..fa69c9a 100644
10586 --- a/arch/x86/include/asm/mman.h
10587 +++ b/arch/x86/include/asm/mman.h
10588 @@ -5,4 +5,14 @@
10589
10590 #include <asm-generic/mman.h>
10591
10592 +#ifdef __KERNEL__
10593 +#ifndef __ASSEMBLY__
10594 +#ifdef CONFIG_X86_32
10595 +#define arch_mmap_check i386_mmap_check
10596 +int i386_mmap_check(unsigned long addr, unsigned long len,
10597 + unsigned long flags);
10598 +#endif
10599 +#endif
10600 +#endif
10601 +
10602 #endif /* _ASM_X86_MMAN_H */
10603 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10604 index 5f55e69..e20bfb1 100644
10605 --- a/arch/x86/include/asm/mmu.h
10606 +++ b/arch/x86/include/asm/mmu.h
10607 @@ -9,7 +9,7 @@
10608 * we put the segment information here.
10609 */
10610 typedef struct {
10611 - void *ldt;
10612 + struct desc_struct *ldt;
10613 int size;
10614
10615 #ifdef CONFIG_X86_64
10616 @@ -18,7 +18,19 @@ typedef struct {
10617 #endif
10618
10619 struct mutex lock;
10620 - void *vdso;
10621 + unsigned long vdso;
10622 +
10623 +#ifdef CONFIG_X86_32
10624 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10625 + unsigned long user_cs_base;
10626 + unsigned long user_cs_limit;
10627 +
10628 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10629 + cpumask_t cpu_user_cs_mask;
10630 +#endif
10631 +
10632 +#endif
10633 +#endif
10634 } mm_context_t;
10635
10636 #ifdef CONFIG_SMP
10637 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10638 index 6902152..399f3a2 100644
10639 --- a/arch/x86/include/asm/mmu_context.h
10640 +++ b/arch/x86/include/asm/mmu_context.h
10641 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10642
10643 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10644 {
10645 +
10646 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10647 + unsigned int i;
10648 + pgd_t *pgd;
10649 +
10650 + pax_open_kernel();
10651 + pgd = get_cpu_pgd(smp_processor_id());
10652 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10653 + set_pgd_batched(pgd+i, native_make_pgd(0));
10654 + pax_close_kernel();
10655 +#endif
10656 +
10657 #ifdef CONFIG_SMP
10658 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10659 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10660 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10661 struct task_struct *tsk)
10662 {
10663 unsigned cpu = smp_processor_id();
10664 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10665 + int tlbstate = TLBSTATE_OK;
10666 +#endif
10667
10668 if (likely(prev != next)) {
10669 #ifdef CONFIG_SMP
10670 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10671 + tlbstate = percpu_read(cpu_tlbstate.state);
10672 +#endif
10673 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10674 percpu_write(cpu_tlbstate.active_mm, next);
10675 #endif
10676 cpumask_set_cpu(cpu, mm_cpumask(next));
10677
10678 /* Re-load page tables */
10679 +#ifdef CONFIG_PAX_PER_CPU_PGD
10680 + pax_open_kernel();
10681 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10682 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10683 + pax_close_kernel();
10684 + load_cr3(get_cpu_pgd(cpu));
10685 +#else
10686 load_cr3(next->pgd);
10687 +#endif
10688
10689 /* stop flush ipis for the previous mm */
10690 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10691 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10692 */
10693 if (unlikely(prev->context.ldt != next->context.ldt))
10694 load_LDT_nolock(&next->context);
10695 - }
10696 +
10697 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10698 + if (!(__supported_pte_mask & _PAGE_NX)) {
10699 + smp_mb__before_clear_bit();
10700 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10701 + smp_mb__after_clear_bit();
10702 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10703 + }
10704 +#endif
10705 +
10706 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10707 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10708 + prev->context.user_cs_limit != next->context.user_cs_limit))
10709 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10710 #ifdef CONFIG_SMP
10711 + else if (unlikely(tlbstate != TLBSTATE_OK))
10712 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10713 +#endif
10714 +#endif
10715 +
10716 + }
10717 else {
10718 +
10719 +#ifdef CONFIG_PAX_PER_CPU_PGD
10720 + pax_open_kernel();
10721 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10722 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10723 + pax_close_kernel();
10724 + load_cr3(get_cpu_pgd(cpu));
10725 +#endif
10726 +
10727 +#ifdef CONFIG_SMP
10728 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10729 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10730
10731 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10732 * tlb flush IPI delivery. We must reload CR3
10733 * to make sure to use no freed page tables.
10734 */
10735 +
10736 +#ifndef CONFIG_PAX_PER_CPU_PGD
10737 load_cr3(next->pgd);
10738 +#endif
10739 +
10740 load_LDT_nolock(&next->context);
10741 +
10742 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10743 + if (!(__supported_pte_mask & _PAGE_NX))
10744 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10745 +#endif
10746 +
10747 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10748 +#ifdef CONFIG_PAX_PAGEEXEC
10749 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10750 +#endif
10751 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10752 +#endif
10753 +
10754 }
10755 +#endif
10756 }
10757 -#endif
10758 }
10759
10760 #define activate_mm(prev, next) \
10761 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10762 index 9eae775..c914fea 100644
10763 --- a/arch/x86/include/asm/module.h
10764 +++ b/arch/x86/include/asm/module.h
10765 @@ -5,6 +5,7 @@
10766
10767 #ifdef CONFIG_X86_64
10768 /* X86_64 does not define MODULE_PROC_FAMILY */
10769 +#define MODULE_PROC_FAMILY ""
10770 #elif defined CONFIG_M386
10771 #define MODULE_PROC_FAMILY "386 "
10772 #elif defined CONFIG_M486
10773 @@ -59,8 +60,20 @@
10774 #error unknown processor family
10775 #endif
10776
10777 -#ifdef CONFIG_X86_32
10778 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10779 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10780 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10781 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10782 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10783 +#else
10784 +#define MODULE_PAX_KERNEXEC ""
10785 #endif
10786
10787 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10788 +#define MODULE_PAX_UDEREF "UDEREF "
10789 +#else
10790 +#define MODULE_PAX_UDEREF ""
10791 +#endif
10792 +
10793 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10794 +
10795 #endif /* _ASM_X86_MODULE_H */
10796 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10797 index 7639dbf..e08a58c 100644
10798 --- a/arch/x86/include/asm/page_64_types.h
10799 +++ b/arch/x86/include/asm/page_64_types.h
10800 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10801
10802 /* duplicated to the one in bootmem.h */
10803 extern unsigned long max_pfn;
10804 -extern unsigned long phys_base;
10805 +extern const unsigned long phys_base;
10806
10807 extern unsigned long __phys_addr(unsigned long);
10808 #define __phys_reloc_hide(x) (x)
10809 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10810 index a7d2db9..edb023e 100644
10811 --- a/arch/x86/include/asm/paravirt.h
10812 +++ b/arch/x86/include/asm/paravirt.h
10813 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10814 val);
10815 }
10816
10817 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10818 +{
10819 + pgdval_t val = native_pgd_val(pgd);
10820 +
10821 + if (sizeof(pgdval_t) > sizeof(long))
10822 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10823 + val, (u64)val >> 32);
10824 + else
10825 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10826 + val);
10827 +}
10828 +
10829 static inline void pgd_clear(pgd_t *pgdp)
10830 {
10831 set_pgd(pgdp, __pgd(0));
10832 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10833 pv_mmu_ops.set_fixmap(idx, phys, flags);
10834 }
10835
10836 +#ifdef CONFIG_PAX_KERNEXEC
10837 +static inline unsigned long pax_open_kernel(void)
10838 +{
10839 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10840 +}
10841 +
10842 +static inline unsigned long pax_close_kernel(void)
10843 +{
10844 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10845 +}
10846 +#else
10847 +static inline unsigned long pax_open_kernel(void) { return 0; }
10848 +static inline unsigned long pax_close_kernel(void) { return 0; }
10849 +#endif
10850 +
10851 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10852
10853 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10854 @@ -964,7 +991,7 @@ extern void default_banner(void);
10855
10856 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10857 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10858 -#define PARA_INDIRECT(addr) *%cs:addr
10859 +#define PARA_INDIRECT(addr) *%ss:addr
10860 #endif
10861
10862 #define INTERRUPT_RETURN \
10863 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
10864 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10865 CLBR_NONE, \
10866 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10867 +
10868 +#define GET_CR0_INTO_RDI \
10869 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10870 + mov %rax,%rdi
10871 +
10872 +#define SET_RDI_INTO_CR0 \
10873 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10874 +
10875 +#define GET_CR3_INTO_RDI \
10876 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10877 + mov %rax,%rdi
10878 +
10879 +#define SET_RDI_INTO_CR3 \
10880 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10881 +
10882 #endif /* CONFIG_X86_32 */
10883
10884 #endif /* __ASSEMBLY__ */
10885 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10886 index 8e8b9a4..f07d725 100644
10887 --- a/arch/x86/include/asm/paravirt_types.h
10888 +++ b/arch/x86/include/asm/paravirt_types.h
10889 @@ -84,20 +84,20 @@ struct pv_init_ops {
10890 */
10891 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10892 unsigned long addr, unsigned len);
10893 -};
10894 +} __no_const;
10895
10896
10897 struct pv_lazy_ops {
10898 /* Set deferred update mode, used for batching operations. */
10899 void (*enter)(void);
10900 void (*leave)(void);
10901 -};
10902 +} __no_const;
10903
10904 struct pv_time_ops {
10905 unsigned long long (*sched_clock)(void);
10906 unsigned long long (*steal_clock)(int cpu);
10907 unsigned long (*get_tsc_khz)(void);
10908 -};
10909 +} __no_const;
10910
10911 struct pv_cpu_ops {
10912 /* hooks for various privileged instructions */
10913 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
10914
10915 void (*start_context_switch)(struct task_struct *prev);
10916 void (*end_context_switch)(struct task_struct *next);
10917 -};
10918 +} __no_const;
10919
10920 struct pv_irq_ops {
10921 /*
10922 @@ -224,7 +224,7 @@ struct pv_apic_ops {
10923 unsigned long start_eip,
10924 unsigned long start_esp);
10925 #endif
10926 -};
10927 +} __no_const;
10928
10929 struct pv_mmu_ops {
10930 unsigned long (*read_cr2)(void);
10931 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
10932 struct paravirt_callee_save make_pud;
10933
10934 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10935 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10936 #endif /* PAGETABLE_LEVELS == 4 */
10937 #endif /* PAGETABLE_LEVELS >= 3 */
10938
10939 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
10940 an mfn. We can tell which is which from the index. */
10941 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10942 phys_addr_t phys, pgprot_t flags);
10943 +
10944 +#ifdef CONFIG_PAX_KERNEXEC
10945 + unsigned long (*pax_open_kernel)(void);
10946 + unsigned long (*pax_close_kernel)(void);
10947 +#endif
10948 +
10949 };
10950
10951 struct arch_spinlock;
10952 @@ -334,7 +341,7 @@ struct pv_lock_ops {
10953 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
10954 int (*spin_trylock)(struct arch_spinlock *lock);
10955 void (*spin_unlock)(struct arch_spinlock *lock);
10956 -};
10957 +} __no_const;
10958
10959 /* This contains all the paravirt structures: we get a convenient
10960 * number for each function using the offset which we use to indicate
10961 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10962 index b4389a4..7024269 100644
10963 --- a/arch/x86/include/asm/pgalloc.h
10964 +++ b/arch/x86/include/asm/pgalloc.h
10965 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
10966 pmd_t *pmd, pte_t *pte)
10967 {
10968 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10969 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10970 +}
10971 +
10972 +static inline void pmd_populate_user(struct mm_struct *mm,
10973 + pmd_t *pmd, pte_t *pte)
10974 +{
10975 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10976 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10977 }
10978
10979 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
10980
10981 #ifdef CONFIG_X86_PAE
10982 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
10983 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
10984 +{
10985 + pud_populate(mm, pudp, pmd);
10986 +}
10987 #else /* !CONFIG_X86_PAE */
10988 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
10989 {
10990 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
10991 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
10992 }
10993 +
10994 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
10995 +{
10996 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
10997 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
10998 +}
10999 #endif /* CONFIG_X86_PAE */
11000
11001 #if PAGETABLE_LEVELS > 3
11002 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11003 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11004 }
11005
11006 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11007 +{
11008 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11009 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11010 +}
11011 +
11012 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11013 {
11014 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11015 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11016 index 98391db..8f6984e 100644
11017 --- a/arch/x86/include/asm/pgtable-2level.h
11018 +++ b/arch/x86/include/asm/pgtable-2level.h
11019 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11020
11021 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11022 {
11023 + pax_open_kernel();
11024 *pmdp = pmd;
11025 + pax_close_kernel();
11026 }
11027
11028 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11029 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11030 index effff47..f9e4035 100644
11031 --- a/arch/x86/include/asm/pgtable-3level.h
11032 +++ b/arch/x86/include/asm/pgtable-3level.h
11033 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11034
11035 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11036 {
11037 + pax_open_kernel();
11038 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11039 + pax_close_kernel();
11040 }
11041
11042 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11043 {
11044 + pax_open_kernel();
11045 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11046 + pax_close_kernel();
11047 }
11048
11049 /*
11050 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11051 index 49afb3f..ed14d07 100644
11052 --- a/arch/x86/include/asm/pgtable.h
11053 +++ b/arch/x86/include/asm/pgtable.h
11054 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11055
11056 #ifndef __PAGETABLE_PUD_FOLDED
11057 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11058 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11059 #define pgd_clear(pgd) native_pgd_clear(pgd)
11060 #endif
11061
11062 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11063
11064 #define arch_end_context_switch(prev) do {} while(0)
11065
11066 +#define pax_open_kernel() native_pax_open_kernel()
11067 +#define pax_close_kernel() native_pax_close_kernel()
11068 #endif /* CONFIG_PARAVIRT */
11069
11070 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11071 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11072 +
11073 +#ifdef CONFIG_PAX_KERNEXEC
11074 +static inline unsigned long native_pax_open_kernel(void)
11075 +{
11076 + unsigned long cr0;
11077 +
11078 + preempt_disable();
11079 + barrier();
11080 + cr0 = read_cr0() ^ X86_CR0_WP;
11081 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11082 + write_cr0(cr0);
11083 + return cr0 ^ X86_CR0_WP;
11084 +}
11085 +
11086 +static inline unsigned long native_pax_close_kernel(void)
11087 +{
11088 + unsigned long cr0;
11089 +
11090 + cr0 = read_cr0() ^ X86_CR0_WP;
11091 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11092 + write_cr0(cr0);
11093 + barrier();
11094 + preempt_enable_no_resched();
11095 + return cr0 ^ X86_CR0_WP;
11096 +}
11097 +#else
11098 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11099 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11100 +#endif
11101 +
11102 /*
11103 * The following only work if pte_present() is true.
11104 * Undefined behaviour if not..
11105 */
11106 +static inline int pte_user(pte_t pte)
11107 +{
11108 + return pte_val(pte) & _PAGE_USER;
11109 +}
11110 +
11111 static inline int pte_dirty(pte_t pte)
11112 {
11113 return pte_flags(pte) & _PAGE_DIRTY;
11114 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11115 return pte_clear_flags(pte, _PAGE_RW);
11116 }
11117
11118 +static inline pte_t pte_mkread(pte_t pte)
11119 +{
11120 + return __pte(pte_val(pte) | _PAGE_USER);
11121 +}
11122 +
11123 static inline pte_t pte_mkexec(pte_t pte)
11124 {
11125 - return pte_clear_flags(pte, _PAGE_NX);
11126 +#ifdef CONFIG_X86_PAE
11127 + if (__supported_pte_mask & _PAGE_NX)
11128 + return pte_clear_flags(pte, _PAGE_NX);
11129 + else
11130 +#endif
11131 + return pte_set_flags(pte, _PAGE_USER);
11132 +}
11133 +
11134 +static inline pte_t pte_exprotect(pte_t pte)
11135 +{
11136 +#ifdef CONFIG_X86_PAE
11137 + if (__supported_pte_mask & _PAGE_NX)
11138 + return pte_set_flags(pte, _PAGE_NX);
11139 + else
11140 +#endif
11141 + return pte_clear_flags(pte, _PAGE_USER);
11142 }
11143
11144 static inline pte_t pte_mkdirty(pte_t pte)
11145 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11146 #endif
11147
11148 #ifndef __ASSEMBLY__
11149 +
11150 +#ifdef CONFIG_PAX_PER_CPU_PGD
11151 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11152 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11153 +{
11154 + return cpu_pgd[cpu];
11155 +}
11156 +#endif
11157 +
11158 #include <linux/mm_types.h>
11159
11160 static inline int pte_none(pte_t pte)
11161 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11162
11163 static inline int pgd_bad(pgd_t pgd)
11164 {
11165 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11166 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11167 }
11168
11169 static inline int pgd_none(pgd_t pgd)
11170 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11171 * pgd_offset() returns a (pgd_t *)
11172 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11173 */
11174 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11175 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11176 +
11177 +#ifdef CONFIG_PAX_PER_CPU_PGD
11178 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11179 +#endif
11180 +
11181 /*
11182 * a shortcut which implies the use of the kernel's pgd, instead
11183 * of a process's
11184 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11185 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11186 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11187
11188 +#ifdef CONFIG_X86_32
11189 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11190 +#else
11191 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11192 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11193 +
11194 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11195 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11196 +#else
11197 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11198 +#endif
11199 +
11200 +#endif
11201 +
11202 #ifndef __ASSEMBLY__
11203
11204 extern int direct_gbpages;
11205 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11206 * dst and src can be on the same page, but the range must not overlap,
11207 * and must not cross a page boundary.
11208 */
11209 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11210 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11211 {
11212 - memcpy(dst, src, count * sizeof(pgd_t));
11213 + pax_open_kernel();
11214 + while (count--)
11215 + *dst++ = *src++;
11216 + pax_close_kernel();
11217 }
11218
11219 +#ifdef CONFIG_PAX_PER_CPU_PGD
11220 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11221 +#endif
11222 +
11223 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11224 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11225 +#else
11226 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
11227 +#endif
11228
11229 #include <asm-generic/pgtable.h>
11230 #endif /* __ASSEMBLY__ */
11231 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11232 index 0c92113..34a77c6 100644
11233 --- a/arch/x86/include/asm/pgtable_32.h
11234 +++ b/arch/x86/include/asm/pgtable_32.h
11235 @@ -25,9 +25,6 @@
11236 struct mm_struct;
11237 struct vm_area_struct;
11238
11239 -extern pgd_t swapper_pg_dir[1024];
11240 -extern pgd_t initial_page_table[1024];
11241 -
11242 static inline void pgtable_cache_init(void) { }
11243 static inline void check_pgt_cache(void) { }
11244 void paging_init(void);
11245 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11246 # include <asm/pgtable-2level.h>
11247 #endif
11248
11249 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11250 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11251 +#ifdef CONFIG_X86_PAE
11252 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11253 +#endif
11254 +
11255 #if defined(CONFIG_HIGHPTE)
11256 #define pte_offset_map(dir, address) \
11257 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11258 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11259 /* Clear a kernel PTE and flush it from the TLB */
11260 #define kpte_clear_flush(ptep, vaddr) \
11261 do { \
11262 + pax_open_kernel(); \
11263 pte_clear(&init_mm, (vaddr), (ptep)); \
11264 + pax_close_kernel(); \
11265 __flush_tlb_one((vaddr)); \
11266 } while (0)
11267
11268 @@ -74,6 +79,9 @@ do { \
11269
11270 #endif /* !__ASSEMBLY__ */
11271
11272 +#define HAVE_ARCH_UNMAPPED_AREA
11273 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11274 +
11275 /*
11276 * kern_addr_valid() is (1) for FLATMEM and (0) for
11277 * SPARSEMEM and DISCONTIGMEM
11278 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11279 index ed5903b..c7fe163 100644
11280 --- a/arch/x86/include/asm/pgtable_32_types.h
11281 +++ b/arch/x86/include/asm/pgtable_32_types.h
11282 @@ -8,7 +8,7 @@
11283 */
11284 #ifdef CONFIG_X86_PAE
11285 # include <asm/pgtable-3level_types.h>
11286 -# define PMD_SIZE (1UL << PMD_SHIFT)
11287 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11288 # define PMD_MASK (~(PMD_SIZE - 1))
11289 #else
11290 # include <asm/pgtable-2level_types.h>
11291 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11292 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11293 #endif
11294
11295 +#ifdef CONFIG_PAX_KERNEXEC
11296 +#ifndef __ASSEMBLY__
11297 +extern unsigned char MODULES_EXEC_VADDR[];
11298 +extern unsigned char MODULES_EXEC_END[];
11299 +#endif
11300 +#include <asm/boot.h>
11301 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11302 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11303 +#else
11304 +#define ktla_ktva(addr) (addr)
11305 +#define ktva_ktla(addr) (addr)
11306 +#endif
11307 +
11308 #define MODULES_VADDR VMALLOC_START
11309 #define MODULES_END VMALLOC_END
11310 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11311 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11312 index 975f709..9f779c9 100644
11313 --- a/arch/x86/include/asm/pgtable_64.h
11314 +++ b/arch/x86/include/asm/pgtable_64.h
11315 @@ -16,10 +16,14 @@
11316
11317 extern pud_t level3_kernel_pgt[512];
11318 extern pud_t level3_ident_pgt[512];
11319 +extern pud_t level3_vmalloc_start_pgt[512];
11320 +extern pud_t level3_vmalloc_end_pgt[512];
11321 +extern pud_t level3_vmemmap_pgt[512];
11322 +extern pud_t level2_vmemmap_pgt[512];
11323 extern pmd_t level2_kernel_pgt[512];
11324 extern pmd_t level2_fixmap_pgt[512];
11325 -extern pmd_t level2_ident_pgt[512];
11326 -extern pgd_t init_level4_pgt[];
11327 +extern pmd_t level2_ident_pgt[512*2];
11328 +extern pgd_t init_level4_pgt[512];
11329
11330 #define swapper_pg_dir init_level4_pgt
11331
11332 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11333
11334 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11335 {
11336 + pax_open_kernel();
11337 *pmdp = pmd;
11338 + pax_close_kernel();
11339 }
11340
11341 static inline void native_pmd_clear(pmd_t *pmd)
11342 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11343
11344 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11345 {
11346 + pax_open_kernel();
11347 *pudp = pud;
11348 + pax_close_kernel();
11349 }
11350
11351 static inline void native_pud_clear(pud_t *pud)
11352 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11353
11354 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11355 {
11356 + pax_open_kernel();
11357 + *pgdp = pgd;
11358 + pax_close_kernel();
11359 +}
11360 +
11361 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11362 +{
11363 *pgdp = pgd;
11364 }
11365
11366 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11367 index 766ea16..5b96cb3 100644
11368 --- a/arch/x86/include/asm/pgtable_64_types.h
11369 +++ b/arch/x86/include/asm/pgtable_64_types.h
11370 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11371 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11372 #define MODULES_END _AC(0xffffffffff000000, UL)
11373 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11374 +#define MODULES_EXEC_VADDR MODULES_VADDR
11375 +#define MODULES_EXEC_END MODULES_END
11376 +
11377 +#define ktla_ktva(addr) (addr)
11378 +#define ktva_ktla(addr) (addr)
11379
11380 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11381 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11382 index 013286a..8b42f4f 100644
11383 --- a/arch/x86/include/asm/pgtable_types.h
11384 +++ b/arch/x86/include/asm/pgtable_types.h
11385 @@ -16,13 +16,12 @@
11386 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11387 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11388 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11389 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11390 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11391 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11392 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11393 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11394 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11395 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11396 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11397 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11398 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11399 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11400
11401 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11402 @@ -40,7 +39,6 @@
11403 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11404 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11405 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11406 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11407 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11408 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11409 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11410 @@ -57,8 +55,10 @@
11411
11412 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11413 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11414 -#else
11415 +#elif defined(CONFIG_KMEMCHECK)
11416 #define _PAGE_NX (_AT(pteval_t, 0))
11417 +#else
11418 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11419 #endif
11420
11421 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11422 @@ -96,6 +96,9 @@
11423 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11424 _PAGE_ACCESSED)
11425
11426 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11427 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11428 +
11429 #define __PAGE_KERNEL_EXEC \
11430 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11431 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11432 @@ -106,7 +109,7 @@
11433 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11434 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11435 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11436 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11437 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11438 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11439 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11440 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11441 @@ -168,8 +171,8 @@
11442 * bits are combined, this will alow user to access the high address mapped
11443 * VDSO in the presence of CONFIG_COMPAT_VDSO
11444 */
11445 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11446 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11447 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11448 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11449 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11450 #endif
11451
11452 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11453 {
11454 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11455 }
11456 +#endif
11457
11458 +#if PAGETABLE_LEVELS == 3
11459 +#include <asm-generic/pgtable-nopud.h>
11460 +#endif
11461 +
11462 +#if PAGETABLE_LEVELS == 2
11463 +#include <asm-generic/pgtable-nopmd.h>
11464 +#endif
11465 +
11466 +#ifndef __ASSEMBLY__
11467 #if PAGETABLE_LEVELS > 3
11468 typedef struct { pudval_t pud; } pud_t;
11469
11470 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11471 return pud.pud;
11472 }
11473 #else
11474 -#include <asm-generic/pgtable-nopud.h>
11475 -
11476 static inline pudval_t native_pud_val(pud_t pud)
11477 {
11478 return native_pgd_val(pud.pgd);
11479 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11480 return pmd.pmd;
11481 }
11482 #else
11483 -#include <asm-generic/pgtable-nopmd.h>
11484 -
11485 static inline pmdval_t native_pmd_val(pmd_t pmd)
11486 {
11487 return native_pgd_val(pmd.pud.pgd);
11488 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11489
11490 extern pteval_t __supported_pte_mask;
11491 extern void set_nx(void);
11492 -extern int nx_enabled;
11493
11494 #define pgprot_writecombine pgprot_writecombine
11495 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11496 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11497 index 58545c9..fe6fc38e 100644
11498 --- a/arch/x86/include/asm/processor.h
11499 +++ b/arch/x86/include/asm/processor.h
11500 @@ -266,7 +266,7 @@ struct tss_struct {
11501
11502 } ____cacheline_aligned;
11503
11504 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11505 +extern struct tss_struct init_tss[NR_CPUS];
11506
11507 /*
11508 * Save the original ist values for checking stack pointers during debugging
11509 @@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(const void *x)
11510 */
11511 #define TASK_SIZE PAGE_OFFSET
11512 #define TASK_SIZE_MAX TASK_SIZE
11513 +
11514 +#ifdef CONFIG_PAX_SEGMEXEC
11515 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11516 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11517 +#else
11518 #define STACK_TOP TASK_SIZE
11519 -#define STACK_TOP_MAX STACK_TOP
11520 +#endif
11521 +
11522 +#define STACK_TOP_MAX TASK_SIZE
11523
11524 #define INIT_THREAD { \
11525 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11526 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11527 .vm86_info = NULL, \
11528 .sysenter_cs = __KERNEL_CS, \
11529 .io_bitmap_ptr = NULL, \
11530 @@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(const void *x)
11531 */
11532 #define INIT_TSS { \
11533 .x86_tss = { \
11534 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11535 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11536 .ss0 = __KERNEL_DS, \
11537 .ss1 = __KERNEL_CS, \
11538 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11539 @@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(const void *x)
11540 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11541
11542 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11543 -#define KSTK_TOP(info) \
11544 -({ \
11545 - unsigned long *__ptr = (unsigned long *)(info); \
11546 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11547 -})
11548 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11549
11550 /*
11551 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11552 @@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11553 #define task_pt_regs(task) \
11554 ({ \
11555 struct pt_regs *__regs__; \
11556 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11557 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11558 __regs__ - 1; \
11559 })
11560
11561 @@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11562 /*
11563 * User space process size. 47bits minus one guard page.
11564 */
11565 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11566 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11567
11568 /* This decides where the kernel will search for a free chunk of vm
11569 * space during mmap's.
11570 */
11571 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11572 - 0xc0000000 : 0xFFFFe000)
11573 + 0xc0000000 : 0xFFFFf000)
11574
11575 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11576 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11577 @@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11578 #define STACK_TOP_MAX TASK_SIZE_MAX
11579
11580 #define INIT_THREAD { \
11581 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11582 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11583 }
11584
11585 #define INIT_TSS { \
11586 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11587 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11588 }
11589
11590 /*
11591 @@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11592 */
11593 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11594
11595 +#ifdef CONFIG_PAX_SEGMEXEC
11596 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11597 +#endif
11598 +
11599 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11600
11601 /* Get/set a process' ability to use the timestamp counter instruction */
11602 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11603 index 3566454..4bdfb8c 100644
11604 --- a/arch/x86/include/asm/ptrace.h
11605 +++ b/arch/x86/include/asm/ptrace.h
11606 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11607 }
11608
11609 /*
11610 - * user_mode_vm(regs) determines whether a register set came from user mode.
11611 + * user_mode(regs) determines whether a register set came from user mode.
11612 * This is true if V8086 mode was enabled OR if the register set was from
11613 * protected mode with RPL-3 CS value. This tricky test checks that with
11614 * one comparison. Many places in the kernel can bypass this full check
11615 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11616 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11617 + * be used.
11618 */
11619 -static inline int user_mode(struct pt_regs *regs)
11620 +static inline int user_mode_novm(struct pt_regs *regs)
11621 {
11622 #ifdef CONFIG_X86_32
11623 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11624 #else
11625 - return !!(regs->cs & 3);
11626 + return !!(regs->cs & SEGMENT_RPL_MASK);
11627 #endif
11628 }
11629
11630 -static inline int user_mode_vm(struct pt_regs *regs)
11631 +static inline int user_mode(struct pt_regs *regs)
11632 {
11633 #ifdef CONFIG_X86_32
11634 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11635 USER_RPL;
11636 #else
11637 - return user_mode(regs);
11638 + return user_mode_novm(regs);
11639 #endif
11640 }
11641
11642 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11643 #ifdef CONFIG_X86_64
11644 static inline bool user_64bit_mode(struct pt_regs *regs)
11645 {
11646 + unsigned long cs = regs->cs & 0xffff;
11647 #ifndef CONFIG_PARAVIRT
11648 /*
11649 * On non-paravirt systems, this is the only long mode CPL 3
11650 * selector. We do not allow long mode selectors in the LDT.
11651 */
11652 - return regs->cs == __USER_CS;
11653 + return cs == __USER_CS;
11654 #else
11655 /* Headers are too twisted for this to go in paravirt.h. */
11656 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11657 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11658 #endif
11659 }
11660 #endif
11661 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11662 index 92f29706..a79cbbb 100644
11663 --- a/arch/x86/include/asm/reboot.h
11664 +++ b/arch/x86/include/asm/reboot.h
11665 @@ -6,19 +6,19 @@
11666 struct pt_regs;
11667
11668 struct machine_ops {
11669 - void (*restart)(char *cmd);
11670 - void (*halt)(void);
11671 - void (*power_off)(void);
11672 + void (* __noreturn restart)(char *cmd);
11673 + void (* __noreturn halt)(void);
11674 + void (* __noreturn power_off)(void);
11675 void (*shutdown)(void);
11676 void (*crash_shutdown)(struct pt_regs *);
11677 - void (*emergency_restart)(void);
11678 -};
11679 + void (* __noreturn emergency_restart)(void);
11680 +} __no_const;
11681
11682 extern struct machine_ops machine_ops;
11683
11684 void native_machine_crash_shutdown(struct pt_regs *regs);
11685 void native_machine_shutdown(void);
11686 -void machine_real_restart(unsigned int type);
11687 +void machine_real_restart(unsigned int type) __noreturn;
11688 /* These must match dispatch_table in reboot_32.S */
11689 #define MRR_BIOS 0
11690 #define MRR_APM 1
11691 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11692 index 2dbe4a7..ce1db00 100644
11693 --- a/arch/x86/include/asm/rwsem.h
11694 +++ b/arch/x86/include/asm/rwsem.h
11695 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11696 {
11697 asm volatile("# beginning down_read\n\t"
11698 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11699 +
11700 +#ifdef CONFIG_PAX_REFCOUNT
11701 + "jno 0f\n"
11702 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11703 + "int $4\n0:\n"
11704 + _ASM_EXTABLE(0b, 0b)
11705 +#endif
11706 +
11707 /* adds 0x00000001 */
11708 " jns 1f\n"
11709 " call call_rwsem_down_read_failed\n"
11710 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11711 "1:\n\t"
11712 " mov %1,%2\n\t"
11713 " add %3,%2\n\t"
11714 +
11715 +#ifdef CONFIG_PAX_REFCOUNT
11716 + "jno 0f\n"
11717 + "sub %3,%2\n"
11718 + "int $4\n0:\n"
11719 + _ASM_EXTABLE(0b, 0b)
11720 +#endif
11721 +
11722 " jle 2f\n\t"
11723 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11724 " jnz 1b\n\t"
11725 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11726 long tmp;
11727 asm volatile("# beginning down_write\n\t"
11728 LOCK_PREFIX " xadd %1,(%2)\n\t"
11729 +
11730 +#ifdef CONFIG_PAX_REFCOUNT
11731 + "jno 0f\n"
11732 + "mov %1,(%2)\n"
11733 + "int $4\n0:\n"
11734 + _ASM_EXTABLE(0b, 0b)
11735 +#endif
11736 +
11737 /* adds 0xffff0001, returns the old value */
11738 " test %1,%1\n\t"
11739 /* was the count 0 before? */
11740 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11741 long tmp;
11742 asm volatile("# beginning __up_read\n\t"
11743 LOCK_PREFIX " xadd %1,(%2)\n\t"
11744 +
11745 +#ifdef CONFIG_PAX_REFCOUNT
11746 + "jno 0f\n"
11747 + "mov %1,(%2)\n"
11748 + "int $4\n0:\n"
11749 + _ASM_EXTABLE(0b, 0b)
11750 +#endif
11751 +
11752 /* subtracts 1, returns the old value */
11753 " jns 1f\n\t"
11754 " call call_rwsem_wake\n" /* expects old value in %edx */
11755 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11756 long tmp;
11757 asm volatile("# beginning __up_write\n\t"
11758 LOCK_PREFIX " xadd %1,(%2)\n\t"
11759 +
11760 +#ifdef CONFIG_PAX_REFCOUNT
11761 + "jno 0f\n"
11762 + "mov %1,(%2)\n"
11763 + "int $4\n0:\n"
11764 + _ASM_EXTABLE(0b, 0b)
11765 +#endif
11766 +
11767 /* subtracts 0xffff0001, returns the old value */
11768 " jns 1f\n\t"
11769 " call call_rwsem_wake\n" /* expects old value in %edx */
11770 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11771 {
11772 asm volatile("# beginning __downgrade_write\n\t"
11773 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11774 +
11775 +#ifdef CONFIG_PAX_REFCOUNT
11776 + "jno 0f\n"
11777 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11778 + "int $4\n0:\n"
11779 + _ASM_EXTABLE(0b, 0b)
11780 +#endif
11781 +
11782 /*
11783 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11784 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11785 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11786 */
11787 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11788 {
11789 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11790 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11791 +
11792 +#ifdef CONFIG_PAX_REFCOUNT
11793 + "jno 0f\n"
11794 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11795 + "int $4\n0:\n"
11796 + _ASM_EXTABLE(0b, 0b)
11797 +#endif
11798 +
11799 : "+m" (sem->count)
11800 : "er" (delta));
11801 }
11802 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11803 */
11804 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
11805 {
11806 - return delta + xadd(&sem->count, delta);
11807 + return delta + xadd_check_overflow(&sem->count, delta);
11808 }
11809
11810 #endif /* __KERNEL__ */
11811 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11812 index 5e64171..f58957e 100644
11813 --- a/arch/x86/include/asm/segment.h
11814 +++ b/arch/x86/include/asm/segment.h
11815 @@ -64,10 +64,15 @@
11816 * 26 - ESPFIX small SS
11817 * 27 - per-cpu [ offset to per-cpu data area ]
11818 * 28 - stack_canary-20 [ for stack protector ]
11819 - * 29 - unused
11820 - * 30 - unused
11821 + * 29 - PCI BIOS CS
11822 + * 30 - PCI BIOS DS
11823 * 31 - TSS for double fault handler
11824 */
11825 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11826 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11827 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11828 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11829 +
11830 #define GDT_ENTRY_TLS_MIN 6
11831 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11832
11833 @@ -79,6 +84,8 @@
11834
11835 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11836
11837 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11838 +
11839 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11840
11841 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11842 @@ -104,6 +111,12 @@
11843 #define __KERNEL_STACK_CANARY 0
11844 #endif
11845
11846 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11847 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11848 +
11849 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11850 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11851 +
11852 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11853
11854 /*
11855 @@ -141,7 +154,7 @@
11856 */
11857
11858 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11859 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11860 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11861
11862
11863 #else
11864 @@ -165,6 +178,8 @@
11865 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
11866 #define __USER32_DS __USER_DS
11867
11868 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11869 +
11870 #define GDT_ENTRY_TSS 8 /* needs two entries */
11871 #define GDT_ENTRY_LDT 10 /* needs two entries */
11872 #define GDT_ENTRY_TLS_MIN 12
11873 @@ -185,6 +200,7 @@
11874 #endif
11875
11876 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11877 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11878 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11879 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11880 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11881 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11882 index 0434c40..1714bf0 100644
11883 --- a/arch/x86/include/asm/smp.h
11884 +++ b/arch/x86/include/asm/smp.h
11885 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11886 /* cpus sharing the last level cache: */
11887 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11888 DECLARE_PER_CPU(u16, cpu_llc_id);
11889 -DECLARE_PER_CPU(int, cpu_number);
11890 +DECLARE_PER_CPU(unsigned int, cpu_number);
11891
11892 static inline struct cpumask *cpu_sibling_mask(int cpu)
11893 {
11894 @@ -77,7 +77,7 @@ struct smp_ops {
11895
11896 void (*send_call_func_ipi)(const struct cpumask *mask);
11897 void (*send_call_func_single_ipi)(int cpu);
11898 -};
11899 +} __no_const;
11900
11901 /* Globals due to paravirt */
11902 extern void set_cpu_sibling_map(int cpu);
11903 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
11904 extern int safe_smp_processor_id(void);
11905
11906 #elif defined(CONFIG_X86_64_SMP)
11907 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11908 -
11909 -#define stack_smp_processor_id() \
11910 -({ \
11911 - struct thread_info *ti; \
11912 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11913 - ti->cpu; \
11914 -})
11915 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11916 +#define stack_smp_processor_id() raw_smp_processor_id()
11917 #define safe_smp_processor_id() smp_processor_id()
11918
11919 #endif
11920 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11921 index a82c2bf..2198f61 100644
11922 --- a/arch/x86/include/asm/spinlock.h
11923 +++ b/arch/x86/include/asm/spinlock.h
11924 @@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
11925 static inline void arch_read_lock(arch_rwlock_t *rw)
11926 {
11927 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
11928 +
11929 +#ifdef CONFIG_PAX_REFCOUNT
11930 + "jno 0f\n"
11931 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
11932 + "int $4\n0:\n"
11933 + _ASM_EXTABLE(0b, 0b)
11934 +#endif
11935 +
11936 "jns 1f\n"
11937 "call __read_lock_failed\n\t"
11938 "1:\n"
11939 @@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
11940 static inline void arch_write_lock(arch_rwlock_t *rw)
11941 {
11942 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
11943 +
11944 +#ifdef CONFIG_PAX_REFCOUNT
11945 + "jno 0f\n"
11946 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
11947 + "int $4\n0:\n"
11948 + _ASM_EXTABLE(0b, 0b)
11949 +#endif
11950 +
11951 "jz 1f\n"
11952 "call __write_lock_failed\n\t"
11953 "1:\n"
11954 @@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
11955
11956 static inline void arch_read_unlock(arch_rwlock_t *rw)
11957 {
11958 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
11959 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
11960 +
11961 +#ifdef CONFIG_PAX_REFCOUNT
11962 + "jno 0f\n"
11963 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
11964 + "int $4\n0:\n"
11965 + _ASM_EXTABLE(0b, 0b)
11966 +#endif
11967 +
11968 :"+m" (rw->lock) : : "memory");
11969 }
11970
11971 static inline void arch_write_unlock(arch_rwlock_t *rw)
11972 {
11973 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
11974 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
11975 +
11976 +#ifdef CONFIG_PAX_REFCOUNT
11977 + "jno 0f\n"
11978 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
11979 + "int $4\n0:\n"
11980 + _ASM_EXTABLE(0b, 0b)
11981 +#endif
11982 +
11983 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
11984 }
11985
11986 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11987 index 1575177..cb23f52 100644
11988 --- a/arch/x86/include/asm/stackprotector.h
11989 +++ b/arch/x86/include/asm/stackprotector.h
11990 @@ -48,7 +48,7 @@
11991 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11992 */
11993 #define GDT_STACK_CANARY_INIT \
11994 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11995 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11996
11997 /*
11998 * Initialize the stackprotector canary value.
11999 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
12000
12001 static inline void load_stack_canary_segment(void)
12002 {
12003 -#ifdef CONFIG_X86_32
12004 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12005 asm volatile ("mov %0, %%gs" : : "r" (0));
12006 #endif
12007 }
12008 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12009 index 70bbe39..4ae2bd4 100644
12010 --- a/arch/x86/include/asm/stacktrace.h
12011 +++ b/arch/x86/include/asm/stacktrace.h
12012 @@ -11,28 +11,20 @@
12013
12014 extern int kstack_depth_to_print;
12015
12016 -struct thread_info;
12017 +struct task_struct;
12018 struct stacktrace_ops;
12019
12020 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12021 - unsigned long *stack,
12022 - unsigned long bp,
12023 - const struct stacktrace_ops *ops,
12024 - void *data,
12025 - unsigned long *end,
12026 - int *graph);
12027 +typedef unsigned long walk_stack_t(struct task_struct *task,
12028 + void *stack_start,
12029 + unsigned long *stack,
12030 + unsigned long bp,
12031 + const struct stacktrace_ops *ops,
12032 + void *data,
12033 + unsigned long *end,
12034 + int *graph);
12035
12036 -extern unsigned long
12037 -print_context_stack(struct thread_info *tinfo,
12038 - unsigned long *stack, unsigned long bp,
12039 - const struct stacktrace_ops *ops, void *data,
12040 - unsigned long *end, int *graph);
12041 -
12042 -extern unsigned long
12043 -print_context_stack_bp(struct thread_info *tinfo,
12044 - unsigned long *stack, unsigned long bp,
12045 - const struct stacktrace_ops *ops, void *data,
12046 - unsigned long *end, int *graph);
12047 +extern walk_stack_t print_context_stack;
12048 +extern walk_stack_t print_context_stack_bp;
12049
12050 /* Generic stack tracer with callbacks */
12051
12052 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12053 void (*address)(void *data, unsigned long address, int reliable);
12054 /* On negative return stop dumping */
12055 int (*stack)(void *data, char *name);
12056 - walk_stack_t walk_stack;
12057 + walk_stack_t *walk_stack;
12058 };
12059
12060 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12061 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12062 index cb23852..2dde194 100644
12063 --- a/arch/x86/include/asm/sys_ia32.h
12064 +++ b/arch/x86/include/asm/sys_ia32.h
12065 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
12066 compat_sigset_t __user *, unsigned int);
12067 asmlinkage long sys32_alarm(unsigned int);
12068
12069 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12070 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12071 asmlinkage long sys32_sysfs(int, u32, u32);
12072
12073 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12074 diff --git a/arch/x86/include/asm/syscalls.h b/arch/x86/include/asm/syscalls.h
12075 index f1d8b44..a4de8b7 100644
12076 --- a/arch/x86/include/asm/syscalls.h
12077 +++ b/arch/x86/include/asm/syscalls.h
12078 @@ -30,7 +30,7 @@ long sys_clone(unsigned long, unsigned long, void __user *,
12079 void __user *, struct pt_regs *);
12080
12081 /* kernel/ldt.c */
12082 -asmlinkage int sys_modify_ldt(int, void __user *, unsigned long);
12083 +asmlinkage int sys_modify_ldt(int, void __user *, unsigned long) __size_overflow(3);
12084
12085 /* kernel/signal.c */
12086 long sys_rt_sigreturn(struct pt_regs *);
12087 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
12088 index 2d2f01c..f985723 100644
12089 --- a/arch/x86/include/asm/system.h
12090 +++ b/arch/x86/include/asm/system.h
12091 @@ -129,7 +129,7 @@ do { \
12092 "call __switch_to\n\t" \
12093 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12094 __switch_canary \
12095 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12096 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12097 "movq %%rax,%%rdi\n\t" \
12098 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12099 "jnz ret_from_fork\n\t" \
12100 @@ -140,7 +140,7 @@ do { \
12101 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12102 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12103 [_tif_fork] "i" (_TIF_FORK), \
12104 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12105 + [thread_info] "m" (current_tinfo), \
12106 [current_task] "m" (current_task) \
12107 __switch_canary_iparam \
12108 : "memory", "cc" __EXTRA_CLOBBER)
12109 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
12110 {
12111 unsigned long __limit;
12112 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12113 - return __limit + 1;
12114 + return __limit;
12115 }
12116
12117 static inline void native_clts(void)
12118 @@ -397,13 +397,13 @@ void enable_hlt(void);
12119
12120 void cpu_idle_wait(void);
12121
12122 -extern unsigned long arch_align_stack(unsigned long sp);
12123 +#define arch_align_stack(x) ((x) & ~0xfUL)
12124 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
12125
12126 void default_idle(void);
12127 bool set_pm_idle_to_default(void);
12128
12129 -void stop_this_cpu(void *dummy);
12130 +void stop_this_cpu(void *dummy) __noreturn;
12131
12132 /*
12133 * Force strict CPU ordering.
12134 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12135 index cfd8144..1b1127d 100644
12136 --- a/arch/x86/include/asm/thread_info.h
12137 +++ b/arch/x86/include/asm/thread_info.h
12138 @@ -10,6 +10,7 @@
12139 #include <linux/compiler.h>
12140 #include <asm/page.h>
12141 #include <asm/types.h>
12142 +#include <asm/percpu.h>
12143
12144 /*
12145 * low level task data that entry.S needs immediate access to
12146 @@ -24,7 +25,6 @@ struct exec_domain;
12147 #include <linux/atomic.h>
12148
12149 struct thread_info {
12150 - struct task_struct *task; /* main task structure */
12151 struct exec_domain *exec_domain; /* execution domain */
12152 __u32 flags; /* low level flags */
12153 __u32 status; /* thread synchronous flags */
12154 @@ -34,19 +34,13 @@ struct thread_info {
12155 mm_segment_t addr_limit;
12156 struct restart_block restart_block;
12157 void __user *sysenter_return;
12158 -#ifdef CONFIG_X86_32
12159 - unsigned long previous_esp; /* ESP of the previous stack in
12160 - case of nested (IRQ) stacks
12161 - */
12162 - __u8 supervisor_stack[0];
12163 -#endif
12164 + unsigned long lowest_stack;
12165 unsigned int sig_on_uaccess_error:1;
12166 unsigned int uaccess_err:1; /* uaccess failed */
12167 };
12168
12169 -#define INIT_THREAD_INFO(tsk) \
12170 +#define INIT_THREAD_INFO \
12171 { \
12172 - .task = &tsk, \
12173 .exec_domain = &default_exec_domain, \
12174 .flags = 0, \
12175 .cpu = 0, \
12176 @@ -57,7 +51,7 @@ struct thread_info {
12177 }, \
12178 }
12179
12180 -#define init_thread_info (init_thread_union.thread_info)
12181 +#define init_thread_info (init_thread_union.stack)
12182 #define init_stack (init_thread_union.stack)
12183
12184 #else /* !__ASSEMBLY__ */
12185 @@ -169,45 +163,40 @@ struct thread_info {
12186 ret; \
12187 })
12188
12189 -#ifdef CONFIG_X86_32
12190 -
12191 -#define STACK_WARN (THREAD_SIZE/8)
12192 -/*
12193 - * macros/functions for gaining access to the thread information structure
12194 - *
12195 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12196 - */
12197 -#ifndef __ASSEMBLY__
12198 -
12199 -
12200 -/* how to get the current stack pointer from C */
12201 -register unsigned long current_stack_pointer asm("esp") __used;
12202 -
12203 -/* how to get the thread information struct from C */
12204 -static inline struct thread_info *current_thread_info(void)
12205 -{
12206 - return (struct thread_info *)
12207 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12208 -}
12209 -
12210 -#else /* !__ASSEMBLY__ */
12211 -
12212 +#ifdef __ASSEMBLY__
12213 /* how to get the thread information struct from ASM */
12214 #define GET_THREAD_INFO(reg) \
12215 - movl $-THREAD_SIZE, reg; \
12216 - andl %esp, reg
12217 + mov PER_CPU_VAR(current_tinfo), reg
12218
12219 /* use this one if reg already contains %esp */
12220 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12221 - andl $-THREAD_SIZE, reg
12222 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12223 +#else
12224 +/* how to get the thread information struct from C */
12225 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12226 +
12227 +static __always_inline struct thread_info *current_thread_info(void)
12228 +{
12229 + return percpu_read_stable(current_tinfo);
12230 +}
12231 +#endif
12232 +
12233 +#ifdef CONFIG_X86_32
12234 +
12235 +#define STACK_WARN (THREAD_SIZE/8)
12236 +/*
12237 + * macros/functions for gaining access to the thread information structure
12238 + *
12239 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12240 + */
12241 +#ifndef __ASSEMBLY__
12242 +
12243 +/* how to get the current stack pointer from C */
12244 +register unsigned long current_stack_pointer asm("esp") __used;
12245
12246 #endif
12247
12248 #else /* X86_32 */
12249
12250 -#include <asm/percpu.h>
12251 -#define KERNEL_STACK_OFFSET (5*8)
12252 -
12253 /*
12254 * macros/functions for gaining access to the thread information structure
12255 * preempt_count needs to be 1 initially, until the scheduler is functional.
12256 @@ -215,27 +204,8 @@ static inline struct thread_info *current_thread_info(void)
12257 #ifndef __ASSEMBLY__
12258 DECLARE_PER_CPU(unsigned long, kernel_stack);
12259
12260 -static inline struct thread_info *current_thread_info(void)
12261 -{
12262 - struct thread_info *ti;
12263 - ti = (void *)(percpu_read_stable(kernel_stack) +
12264 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12265 - return ti;
12266 -}
12267 -
12268 -#else /* !__ASSEMBLY__ */
12269 -
12270 -/* how to get the thread information struct from ASM */
12271 -#define GET_THREAD_INFO(reg) \
12272 - movq PER_CPU_VAR(kernel_stack),reg ; \
12273 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12274 -
12275 -/*
12276 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12277 - * a certain register (to be used in assembler memory operands).
12278 - */
12279 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12280 -
12281 +/* how to get the current stack pointer from C */
12282 +register unsigned long current_stack_pointer asm("rsp") __used;
12283 #endif
12284
12285 #endif /* !X86_32 */
12286 @@ -269,5 +239,16 @@ extern void arch_task_cache_init(void);
12287 extern void free_thread_info(struct thread_info *ti);
12288 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12289 #define arch_task_cache_init arch_task_cache_init
12290 +
12291 +#define __HAVE_THREAD_FUNCTIONS
12292 +#define task_thread_info(task) (&(task)->tinfo)
12293 +#define task_stack_page(task) ((task)->stack)
12294 +#define setup_thread_stack(p, org) do {} while (0)
12295 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12296 +
12297 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12298 +extern struct task_struct *alloc_task_struct_node(int node);
12299 +extern void free_task_struct(struct task_struct *);
12300 +
12301 #endif
12302 #endif /* _ASM_X86_THREAD_INFO_H */
12303 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12304 index 8be5f54..7ae826d 100644
12305 --- a/arch/x86/include/asm/uaccess.h
12306 +++ b/arch/x86/include/asm/uaccess.h
12307 @@ -7,12 +7,15 @@
12308 #include <linux/compiler.h>
12309 #include <linux/thread_info.h>
12310 #include <linux/string.h>
12311 +#include <linux/sched.h>
12312 #include <asm/asm.h>
12313 #include <asm/page.h>
12314
12315 #define VERIFY_READ 0
12316 #define VERIFY_WRITE 1
12317
12318 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12319 +
12320 /*
12321 * The fs value determines whether argument validity checking should be
12322 * performed or not. If get_fs() == USER_DS, checking is performed, with
12323 @@ -28,7 +31,12 @@
12324
12325 #define get_ds() (KERNEL_DS)
12326 #define get_fs() (current_thread_info()->addr_limit)
12327 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12328 +void __set_fs(mm_segment_t x);
12329 +void set_fs(mm_segment_t x);
12330 +#else
12331 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12332 +#endif
12333
12334 #define segment_eq(a, b) ((a).seg == (b).seg)
12335
12336 @@ -76,7 +84,33 @@
12337 * checks that the pointer is in the user space range - after calling
12338 * this function, memory access functions may still return -EFAULT.
12339 */
12340 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12341 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12342 +#define access_ok(type, addr, size) \
12343 +({ \
12344 + long __size = size; \
12345 + unsigned long __addr = (unsigned long)addr; \
12346 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12347 + unsigned long __end_ao = __addr + __size - 1; \
12348 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12349 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12350 + while(__addr_ao <= __end_ao) { \
12351 + char __c_ao; \
12352 + __addr_ao += PAGE_SIZE; \
12353 + if (__size > PAGE_SIZE) \
12354 + cond_resched(); \
12355 + if (__get_user(__c_ao, (char __user *)__addr)) \
12356 + break; \
12357 + if (type != VERIFY_WRITE) { \
12358 + __addr = __addr_ao; \
12359 + continue; \
12360 + } \
12361 + if (__put_user(__c_ao, (char __user *)__addr)) \
12362 + break; \
12363 + __addr = __addr_ao; \
12364 + } \
12365 + } \
12366 + __ret_ao; \
12367 +})
12368
12369 /*
12370 * The exception table consists of pairs of addresses: the first is the
12371 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12372 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12373 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12374
12375 -
12376 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12377 +#define __copyuser_seg "gs;"
12378 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12379 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12380 +#else
12381 +#define __copyuser_seg
12382 +#define __COPYUSER_SET_ES
12383 +#define __COPYUSER_RESTORE_ES
12384 +#endif
12385
12386 #ifdef CONFIG_X86_32
12387 #define __put_user_asm_u64(x, addr, err, errret) \
12388 - asm volatile("1: movl %%eax,0(%2)\n" \
12389 - "2: movl %%edx,4(%2)\n" \
12390 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12391 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12392 "3:\n" \
12393 ".section .fixup,\"ax\"\n" \
12394 "4: movl %3,%0\n" \
12395 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12396 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12397
12398 #define __put_user_asm_ex_u64(x, addr) \
12399 - asm volatile("1: movl %%eax,0(%1)\n" \
12400 - "2: movl %%edx,4(%1)\n" \
12401 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12402 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12403 "3:\n" \
12404 _ASM_EXTABLE(1b, 2b - 1b) \
12405 _ASM_EXTABLE(2b, 3b - 2b) \
12406 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
12407 __typeof__(*(ptr)) __pu_val; \
12408 __chk_user_ptr(ptr); \
12409 might_fault(); \
12410 - __pu_val = x; \
12411 + __pu_val = (x); \
12412 switch (sizeof(*(ptr))) { \
12413 case 1: \
12414 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12415 @@ -373,7 +415,7 @@ do { \
12416 } while (0)
12417
12418 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12419 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12420 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12421 "2:\n" \
12422 ".section .fixup,\"ax\"\n" \
12423 "3: mov %3,%0\n" \
12424 @@ -381,7 +423,7 @@ do { \
12425 " jmp 2b\n" \
12426 ".previous\n" \
12427 _ASM_EXTABLE(1b, 3b) \
12428 - : "=r" (err), ltype(x) \
12429 + : "=r" (err), ltype (x) \
12430 : "m" (__m(addr)), "i" (errret), "0" (err))
12431
12432 #define __get_user_size_ex(x, ptr, size) \
12433 @@ -406,7 +448,7 @@ do { \
12434 } while (0)
12435
12436 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12437 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12438 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12439 "2:\n" \
12440 _ASM_EXTABLE(1b, 2b - 1b) \
12441 : ltype(x) : "m" (__m(addr)))
12442 @@ -423,13 +465,24 @@ do { \
12443 int __gu_err; \
12444 unsigned long __gu_val; \
12445 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12446 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12447 + (x) = (__typeof__(*(ptr)))__gu_val; \
12448 __gu_err; \
12449 })
12450
12451 /* FIXME: this hack is definitely wrong -AK */
12452 struct __large_struct { unsigned long buf[100]; };
12453 -#define __m(x) (*(struct __large_struct __user *)(x))
12454 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12455 +#define ____m(x) \
12456 +({ \
12457 + unsigned long ____x = (unsigned long)(x); \
12458 + if (____x < PAX_USER_SHADOW_BASE) \
12459 + ____x += PAX_USER_SHADOW_BASE; \
12460 + (void __user *)____x; \
12461 +})
12462 +#else
12463 +#define ____m(x) (x)
12464 +#endif
12465 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12466
12467 /*
12468 * Tell gcc we read from memory instead of writing: this is because
12469 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12470 * aliasing issues.
12471 */
12472 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12473 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12474 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12475 "2:\n" \
12476 ".section .fixup,\"ax\"\n" \
12477 "3: mov %3,%0\n" \
12478 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12479 ".previous\n" \
12480 _ASM_EXTABLE(1b, 3b) \
12481 : "=r"(err) \
12482 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12483 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12484
12485 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12486 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12487 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12488 "2:\n" \
12489 _ASM_EXTABLE(1b, 2b - 1b) \
12490 : : ltype(x), "m" (__m(addr)))
12491 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12492 * On error, the variable @x is set to zero.
12493 */
12494
12495 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12496 +#define __get_user(x, ptr) get_user((x), (ptr))
12497 +#else
12498 #define __get_user(x, ptr) \
12499 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12500 +#endif
12501
12502 /**
12503 * __put_user: - Write a simple value into user space, with less checking.
12504 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12505 * Returns zero on success, or -EFAULT on error.
12506 */
12507
12508 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12509 +#define __put_user(x, ptr) put_user((x), (ptr))
12510 +#else
12511 #define __put_user(x, ptr) \
12512 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12513 +#endif
12514
12515 #define __get_user_unaligned __get_user
12516 #define __put_user_unaligned __put_user
12517 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12518 #define get_user_ex(x, ptr) do { \
12519 unsigned long __gue_val; \
12520 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12521 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12522 + (x) = (__typeof__(*(ptr)))__gue_val; \
12523 } while (0)
12524
12525 #ifdef CONFIG_X86_WP_WORKS_OK
12526 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12527 index 566e803..7183d0b 100644
12528 --- a/arch/x86/include/asm/uaccess_32.h
12529 +++ b/arch/x86/include/asm/uaccess_32.h
12530 @@ -11,15 +11,15 @@
12531 #include <asm/page.h>
12532
12533 unsigned long __must_check __copy_to_user_ll
12534 - (void __user *to, const void *from, unsigned long n);
12535 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12536 unsigned long __must_check __copy_from_user_ll
12537 - (void *to, const void __user *from, unsigned long n);
12538 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12539 unsigned long __must_check __copy_from_user_ll_nozero
12540 - (void *to, const void __user *from, unsigned long n);
12541 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12542 unsigned long __must_check __copy_from_user_ll_nocache
12543 - (void *to, const void __user *from, unsigned long n);
12544 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12545 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12546 - (void *to, const void __user *from, unsigned long n);
12547 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12548
12549 /**
12550 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12551 @@ -41,8 +41,13 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12552 */
12553
12554 static __always_inline unsigned long __must_check
12555 +__copy_to_user_inatomic(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12556 +static __always_inline unsigned long __must_check
12557 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12558 {
12559 + if ((long)n < 0)
12560 + return n;
12561 +
12562 if (__builtin_constant_p(n)) {
12563 unsigned long ret;
12564
12565 @@ -61,6 +66,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12566 return ret;
12567 }
12568 }
12569 + if (!__builtin_constant_p(n))
12570 + check_object_size(from, n, true);
12571 return __copy_to_user_ll(to, from, n);
12572 }
12573
12574 @@ -79,15 +86,23 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12575 * On success, this will be zero.
12576 */
12577 static __always_inline unsigned long __must_check
12578 +__copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12579 +static __always_inline unsigned long __must_check
12580 __copy_to_user(void __user *to, const void *from, unsigned long n)
12581 {
12582 might_fault();
12583 +
12584 return __copy_to_user_inatomic(to, from, n);
12585 }
12586
12587 static __always_inline unsigned long
12588 +__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12589 +static __always_inline unsigned long
12590 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12591 {
12592 + if ((long)n < 0)
12593 + return n;
12594 +
12595 /* Avoid zeroing the tail if the copy fails..
12596 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12597 * but as the zeroing behaviour is only significant when n is not
12598 @@ -134,9 +149,15 @@ __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12599 * for explanation of why this is needed.
12600 */
12601 static __always_inline unsigned long
12602 +__copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12603 +static __always_inline unsigned long
12604 __copy_from_user(void *to, const void __user *from, unsigned long n)
12605 {
12606 might_fault();
12607 +
12608 + if ((long)n < 0)
12609 + return n;
12610 +
12611 if (__builtin_constant_p(n)) {
12612 unsigned long ret;
12613
12614 @@ -152,13 +173,21 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12615 return ret;
12616 }
12617 }
12618 + if (!__builtin_constant_p(n))
12619 + check_object_size(to, n, false);
12620 return __copy_from_user_ll(to, from, n);
12621 }
12622
12623 static __always_inline unsigned long __copy_from_user_nocache(void *to,
12624 + const void __user *from, unsigned long n) __size_overflow(3);
12625 +static __always_inline unsigned long __copy_from_user_nocache(void *to,
12626 const void __user *from, unsigned long n)
12627 {
12628 might_fault();
12629 +
12630 + if ((long)n < 0)
12631 + return n;
12632 +
12633 if (__builtin_constant_p(n)) {
12634 unsigned long ret;
12635
12636 @@ -179,17 +208,24 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12637
12638 static __always_inline unsigned long
12639 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12640 + unsigned long n) __size_overflow(3);
12641 +static __always_inline unsigned long
12642 +__copy_from_user_inatomic_nocache(void *to, const void __user *from,
12643 unsigned long n)
12644 {
12645 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12646 + if ((long)n < 0)
12647 + return n;
12648 +
12649 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12650 }
12651
12652 -unsigned long __must_check copy_to_user(void __user *to,
12653 - const void *from, unsigned long n);
12654 -unsigned long __must_check _copy_from_user(void *to,
12655 - const void __user *from,
12656 - unsigned long n);
12657 -
12658 +extern void copy_to_user_overflow(void)
12659 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12660 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12661 +#else
12662 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12663 +#endif
12664 +;
12665
12666 extern void copy_from_user_overflow(void)
12667 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12668 @@ -199,17 +235,65 @@ extern void copy_from_user_overflow(void)
12669 #endif
12670 ;
12671
12672 -static inline unsigned long __must_check copy_from_user(void *to,
12673 - const void __user *from,
12674 - unsigned long n)
12675 +/**
12676 + * copy_to_user: - Copy a block of data into user space.
12677 + * @to: Destination address, in user space.
12678 + * @from: Source address, in kernel space.
12679 + * @n: Number of bytes to copy.
12680 + *
12681 + * Context: User context only. This function may sleep.
12682 + *
12683 + * Copy data from kernel space to user space.
12684 + *
12685 + * Returns number of bytes that could not be copied.
12686 + * On success, this will be zero.
12687 + */
12688 +static inline unsigned long __must_check
12689 +copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12690 +static inline unsigned long __must_check
12691 +copy_to_user(void __user *to, const void *from, unsigned long n)
12692 +{
12693 + int sz = __compiletime_object_size(from);
12694 +
12695 + if (unlikely(sz != -1 && sz < n))
12696 + copy_to_user_overflow();
12697 + else if (access_ok(VERIFY_WRITE, to, n))
12698 + n = __copy_to_user(to, from, n);
12699 + return n;
12700 +}
12701 +
12702 +/**
12703 + * copy_from_user: - Copy a block of data from user space.
12704 + * @to: Destination address, in kernel space.
12705 + * @from: Source address, in user space.
12706 + * @n: Number of bytes to copy.
12707 + *
12708 + * Context: User context only. This function may sleep.
12709 + *
12710 + * Copy data from user space to kernel space.
12711 + *
12712 + * Returns number of bytes that could not be copied.
12713 + * On success, this will be zero.
12714 + *
12715 + * If some data could not be copied, this function will pad the copied
12716 + * data to the requested size using zero bytes.
12717 + */
12718 +static inline unsigned long __must_check
12719 +copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12720 +static inline unsigned long __must_check
12721 +copy_from_user(void *to, const void __user *from, unsigned long n)
12722 {
12723 int sz = __compiletime_object_size(to);
12724
12725 - if (likely(sz == -1 || sz >= n))
12726 - n = _copy_from_user(to, from, n);
12727 - else
12728 + if (unlikely(sz != -1 && sz < n))
12729 copy_from_user_overflow();
12730 -
12731 + else if (access_ok(VERIFY_READ, from, n))
12732 + n = __copy_from_user(to, from, n);
12733 + else if ((long)n > 0) {
12734 + if (!__builtin_constant_p(n))
12735 + check_object_size(to, n, false);
12736 + memset(to, 0, n);
12737 + }
12738 return n;
12739 }
12740
12741 @@ -235,7 +319,7 @@ long __must_check __strncpy_from_user(char *dst,
12742 #define strlen_user(str) strnlen_user(str, LONG_MAX)
12743
12744 long strnlen_user(const char __user *str, long n);
12745 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
12746 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
12747 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12748 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12749
12750 #endif /* _ASM_X86_UACCESS_32_H */
12751 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12752 index 1c66d30..e294b5f 100644
12753 --- a/arch/x86/include/asm/uaccess_64.h
12754 +++ b/arch/x86/include/asm/uaccess_64.h
12755 @@ -10,6 +10,9 @@
12756 #include <asm/alternative.h>
12757 #include <asm/cpufeature.h>
12758 #include <asm/page.h>
12759 +#include <asm/pgtable.h>
12760 +
12761 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
12762
12763 /*
12764 * Copy To/From Userspace
12765 @@ -17,12 +20,14 @@
12766
12767 /* Handles exceptions in both to and from, but doesn't do access_ok */
12768 __must_check unsigned long
12769 -copy_user_generic_string(void *to, const void *from, unsigned len);
12770 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
12771 __must_check unsigned long
12772 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
12773 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
12774
12775 static __always_inline __must_check unsigned long
12776 -copy_user_generic(void *to, const void *from, unsigned len)
12777 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
12778 +static __always_inline __must_check unsigned long
12779 +copy_user_generic(void *to, const void *from, unsigned long len)
12780 {
12781 unsigned ret;
12782
12783 @@ -32,142 +37,237 @@ copy_user_generic(void *to, const void *from, unsigned len)
12784 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
12785 "=d" (len)),
12786 "1" (to), "2" (from), "3" (len)
12787 - : "memory", "rcx", "r8", "r9", "r10", "r11");
12788 + : "memory", "rcx", "r8", "r9", "r11");
12789 return ret;
12790 }
12791
12792 +static __always_inline __must_check unsigned long
12793 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
12794 +static __always_inline __must_check unsigned long
12795 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
12796 __must_check unsigned long
12797 -_copy_to_user(void __user *to, const void *from, unsigned len);
12798 -__must_check unsigned long
12799 -_copy_from_user(void *to, const void __user *from, unsigned len);
12800 -__must_check unsigned long
12801 -copy_in_user(void __user *to, const void __user *from, unsigned len);
12802 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
12803
12804 static inline unsigned long __must_check copy_from_user(void *to,
12805 const void __user *from,
12806 + unsigned long n) __size_overflow(3);
12807 +static inline unsigned long __must_check copy_from_user(void *to,
12808 + const void __user *from,
12809 unsigned long n)
12810 {
12811 - int sz = __compiletime_object_size(to);
12812 -
12813 might_fault();
12814 - if (likely(sz == -1 || sz >= n))
12815 - n = _copy_from_user(to, from, n);
12816 -#ifdef CONFIG_DEBUG_VM
12817 - else
12818 - WARN(1, "Buffer overflow detected!\n");
12819 -#endif
12820 +
12821 + if (access_ok(VERIFY_READ, from, n))
12822 + n = __copy_from_user(to, from, n);
12823 + else if (n < INT_MAX) {
12824 + if (!__builtin_constant_p(n))
12825 + check_object_size(to, n, false);
12826 + memset(to, 0, n);
12827 + }
12828 return n;
12829 }
12830
12831 static __always_inline __must_check
12832 -int copy_to_user(void __user *dst, const void *src, unsigned size)
12833 +int copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12834 +static __always_inline __must_check
12835 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
12836 {
12837 might_fault();
12838
12839 - return _copy_to_user(dst, src, size);
12840 + if (access_ok(VERIFY_WRITE, dst, size))
12841 + size = __copy_to_user(dst, src, size);
12842 + return size;
12843 }
12844
12845 static __always_inline __must_check
12846 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
12847 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12848 +static __always_inline __must_check
12849 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
12850 {
12851 - int ret = 0;
12852 + int sz = __compiletime_object_size(dst);
12853 + unsigned ret = 0;
12854
12855 might_fault();
12856 - if (!__builtin_constant_p(size))
12857 - return copy_user_generic(dst, (__force void *)src, size);
12858 +
12859 + if (size > INT_MAX)
12860 + return size;
12861 +
12862 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12863 + if (!__access_ok(VERIFY_READ, src, size))
12864 + return size;
12865 +#endif
12866 +
12867 + if (unlikely(sz != -1 && sz < size)) {
12868 +#ifdef CONFIG_DEBUG_VM
12869 + WARN(1, "Buffer overflow detected!\n");
12870 +#endif
12871 + return size;
12872 + }
12873 +
12874 + if (!__builtin_constant_p(size)) {
12875 + check_object_size(dst, size, false);
12876 +
12877 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12878 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12879 + src += PAX_USER_SHADOW_BASE;
12880 +#endif
12881 +
12882 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12883 + }
12884 switch (size) {
12885 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
12886 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
12887 ret, "b", "b", "=q", 1);
12888 return ret;
12889 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
12890 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
12891 ret, "w", "w", "=r", 2);
12892 return ret;
12893 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
12894 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
12895 ret, "l", "k", "=r", 4);
12896 return ret;
12897 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
12898 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12899 ret, "q", "", "=r", 8);
12900 return ret;
12901 case 10:
12902 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12903 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12904 ret, "q", "", "=r", 10);
12905 if (unlikely(ret))
12906 return ret;
12907 __get_user_asm(*(u16 *)(8 + (char *)dst),
12908 - (u16 __user *)(8 + (char __user *)src),
12909 + (const u16 __user *)(8 + (const char __user *)src),
12910 ret, "w", "w", "=r", 2);
12911 return ret;
12912 case 16:
12913 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12914 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12915 ret, "q", "", "=r", 16);
12916 if (unlikely(ret))
12917 return ret;
12918 __get_user_asm(*(u64 *)(8 + (char *)dst),
12919 - (u64 __user *)(8 + (char __user *)src),
12920 + (const u64 __user *)(8 + (const char __user *)src),
12921 ret, "q", "", "=r", 8);
12922 return ret;
12923 default:
12924 - return copy_user_generic(dst, (__force void *)src, size);
12925 +
12926 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12927 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12928 + src += PAX_USER_SHADOW_BASE;
12929 +#endif
12930 +
12931 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12932 }
12933 }
12934
12935 static __always_inline __must_check
12936 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
12937 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12938 +static __always_inline __must_check
12939 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
12940 {
12941 - int ret = 0;
12942 + int sz = __compiletime_object_size(src);
12943 + unsigned ret = 0;
12944
12945 might_fault();
12946 - if (!__builtin_constant_p(size))
12947 - return copy_user_generic((__force void *)dst, src, size);
12948 +
12949 + if (size > INT_MAX)
12950 + return size;
12951 +
12952 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12953 + if (!__access_ok(VERIFY_WRITE, dst, size))
12954 + return size;
12955 +#endif
12956 +
12957 + if (unlikely(sz != -1 && sz < size)) {
12958 +#ifdef CONFIG_DEBUG_VM
12959 + WARN(1, "Buffer overflow detected!\n");
12960 +#endif
12961 + return size;
12962 + }
12963 +
12964 + if (!__builtin_constant_p(size)) {
12965 + check_object_size(src, size, true);
12966 +
12967 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12968 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12969 + dst += PAX_USER_SHADOW_BASE;
12970 +#endif
12971 +
12972 + return copy_user_generic((__force_kernel void *)dst, src, size);
12973 + }
12974 switch (size) {
12975 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
12976 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
12977 ret, "b", "b", "iq", 1);
12978 return ret;
12979 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
12980 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
12981 ret, "w", "w", "ir", 2);
12982 return ret;
12983 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
12984 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
12985 ret, "l", "k", "ir", 4);
12986 return ret;
12987 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
12988 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12989 ret, "q", "", "er", 8);
12990 return ret;
12991 case 10:
12992 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12993 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12994 ret, "q", "", "er", 10);
12995 if (unlikely(ret))
12996 return ret;
12997 asm("":::"memory");
12998 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12999 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13000 ret, "w", "w", "ir", 2);
13001 return ret;
13002 case 16:
13003 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13004 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13005 ret, "q", "", "er", 16);
13006 if (unlikely(ret))
13007 return ret;
13008 asm("":::"memory");
13009 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13010 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13011 ret, "q", "", "er", 8);
13012 return ret;
13013 default:
13014 - return copy_user_generic((__force void *)dst, src, size);
13015 +
13016 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13017 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13018 + dst += PAX_USER_SHADOW_BASE;
13019 +#endif
13020 +
13021 + return copy_user_generic((__force_kernel void *)dst, src, size);
13022 }
13023 }
13024
13025 static __always_inline __must_check
13026 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13027 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size) __size_overflow(3);
13028 +static __always_inline __must_check
13029 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13030 {
13031 - int ret = 0;
13032 + unsigned ret = 0;
13033
13034 might_fault();
13035 - if (!__builtin_constant_p(size))
13036 - return copy_user_generic((__force void *)dst,
13037 - (__force void *)src, size);
13038 +
13039 + if (size > INT_MAX)
13040 + return size;
13041 +
13042 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13043 + if (!__access_ok(VERIFY_READ, src, size))
13044 + return size;
13045 + if (!__access_ok(VERIFY_WRITE, dst, size))
13046 + return size;
13047 +#endif
13048 +
13049 + if (!__builtin_constant_p(size)) {
13050 +
13051 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13052 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13053 + src += PAX_USER_SHADOW_BASE;
13054 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13055 + dst += PAX_USER_SHADOW_BASE;
13056 +#endif
13057 +
13058 + return copy_user_generic((__force_kernel void *)dst,
13059 + (__force_kernel const void *)src, size);
13060 + }
13061 switch (size) {
13062 case 1: {
13063 u8 tmp;
13064 - __get_user_asm(tmp, (u8 __user *)src,
13065 + __get_user_asm(tmp, (const u8 __user *)src,
13066 ret, "b", "b", "=q", 1);
13067 if (likely(!ret))
13068 __put_user_asm(tmp, (u8 __user *)dst,
13069 @@ -176,7 +276,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13070 }
13071 case 2: {
13072 u16 tmp;
13073 - __get_user_asm(tmp, (u16 __user *)src,
13074 + __get_user_asm(tmp, (const u16 __user *)src,
13075 ret, "w", "w", "=r", 2);
13076 if (likely(!ret))
13077 __put_user_asm(tmp, (u16 __user *)dst,
13078 @@ -186,7 +286,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13079
13080 case 4: {
13081 u32 tmp;
13082 - __get_user_asm(tmp, (u32 __user *)src,
13083 + __get_user_asm(tmp, (const u32 __user *)src,
13084 ret, "l", "k", "=r", 4);
13085 if (likely(!ret))
13086 __put_user_asm(tmp, (u32 __user *)dst,
13087 @@ -195,7 +295,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13088 }
13089 case 8: {
13090 u64 tmp;
13091 - __get_user_asm(tmp, (u64 __user *)src,
13092 + __get_user_asm(tmp, (const u64 __user *)src,
13093 ret, "q", "", "=r", 8);
13094 if (likely(!ret))
13095 __put_user_asm(tmp, (u64 __user *)dst,
13096 @@ -203,8 +303,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13097 return ret;
13098 }
13099 default:
13100 - return copy_user_generic((__force void *)dst,
13101 - (__force void *)src, size);
13102 +
13103 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13104 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13105 + src += PAX_USER_SHADOW_BASE;
13106 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13107 + dst += PAX_USER_SHADOW_BASE;
13108 +#endif
13109 +
13110 + return copy_user_generic((__force_kernel void *)dst,
13111 + (__force_kernel const void *)src, size);
13112 }
13113 }
13114
13115 @@ -215,39 +323,83 @@ __strncpy_from_user(char *dst, const char __user *src, long count);
13116 __must_check long strnlen_user(const char __user *str, long n);
13117 __must_check long __strnlen_user(const char __user *str, long n);
13118 __must_check long strlen_user(const char __user *str);
13119 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13120 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13121 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13122 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13123
13124 static __must_check __always_inline int
13125 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13126 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
13127 +static __must_check __always_inline int
13128 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13129 {
13130 - return copy_user_generic(dst, (__force const void *)src, size);
13131 + if (size > INT_MAX)
13132 + return size;
13133 +
13134 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13135 + if (!__access_ok(VERIFY_READ, src, size))
13136 + return size;
13137 +
13138 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13139 + src += PAX_USER_SHADOW_BASE;
13140 +#endif
13141 +
13142 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13143 }
13144
13145 -static __must_check __always_inline int
13146 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13147 +static __must_check __always_inline unsigned long
13148 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
13149 +static __must_check __always_inline unsigned long
13150 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13151 {
13152 - return copy_user_generic((__force void *)dst, src, size);
13153 + if (size > INT_MAX)
13154 + return size;
13155 +
13156 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13157 + if (!__access_ok(VERIFY_WRITE, dst, size))
13158 + return size;
13159 +
13160 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13161 + dst += PAX_USER_SHADOW_BASE;
13162 +#endif
13163 +
13164 + return copy_user_generic((__force_kernel void *)dst, src, size);
13165 }
13166
13167 -extern long __copy_user_nocache(void *dst, const void __user *src,
13168 - unsigned size, int zerorest);
13169 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13170 + unsigned long size, int zerorest) __size_overflow(3);
13171
13172 -static inline int
13173 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13174 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
13175 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13176 {
13177 might_sleep();
13178 +
13179 + if (size > INT_MAX)
13180 + return size;
13181 +
13182 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13183 + if (!__access_ok(VERIFY_READ, src, size))
13184 + return size;
13185 +#endif
13186 +
13187 return __copy_user_nocache(dst, src, size, 1);
13188 }
13189
13190 -static inline int
13191 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13192 - unsigned size)
13193 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13194 + unsigned long size) __size_overflow(3);
13195 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13196 + unsigned long size)
13197 {
13198 + if (size > INT_MAX)
13199 + return size;
13200 +
13201 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13202 + if (!__access_ok(VERIFY_READ, src, size))
13203 + return size;
13204 +#endif
13205 +
13206 return __copy_user_nocache(dst, src, size, 0);
13207 }
13208
13209 -unsigned long
13210 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13211 +extern unsigned long
13212 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13213
13214 #endif /* _ASM_X86_UACCESS_64_H */
13215 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13216 index bb05228..d763d5b 100644
13217 --- a/arch/x86/include/asm/vdso.h
13218 +++ b/arch/x86/include/asm/vdso.h
13219 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13220 #define VDSO32_SYMBOL(base, name) \
13221 ({ \
13222 extern const char VDSO32_##name[]; \
13223 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13224 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13225 })
13226 #endif
13227
13228 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13229 index a609c39..7a68dc7 100644
13230 --- a/arch/x86/include/asm/x86_init.h
13231 +++ b/arch/x86/include/asm/x86_init.h
13232 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13233 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13234 void (*find_smp_config)(void);
13235 void (*get_smp_config)(unsigned int early);
13236 -};
13237 +} __no_const;
13238
13239 /**
13240 * struct x86_init_resources - platform specific resource related ops
13241 @@ -43,7 +43,7 @@ struct x86_init_resources {
13242 void (*probe_roms)(void);
13243 void (*reserve_resources)(void);
13244 char *(*memory_setup)(void);
13245 -};
13246 +} __no_const;
13247
13248 /**
13249 * struct x86_init_irqs - platform specific interrupt setup
13250 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13251 void (*pre_vector_init)(void);
13252 void (*intr_init)(void);
13253 void (*trap_init)(void);
13254 -};
13255 +} __no_const;
13256
13257 /**
13258 * struct x86_init_oem - oem platform specific customizing functions
13259 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13260 struct x86_init_oem {
13261 void (*arch_setup)(void);
13262 void (*banner)(void);
13263 -};
13264 +} __no_const;
13265
13266 /**
13267 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13268 @@ -77,7 +77,7 @@ struct x86_init_oem {
13269 */
13270 struct x86_init_mapping {
13271 void (*pagetable_reserve)(u64 start, u64 end);
13272 -};
13273 +} __no_const;
13274
13275 /**
13276 * struct x86_init_paging - platform specific paging functions
13277 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13278 struct x86_init_paging {
13279 void (*pagetable_setup_start)(pgd_t *base);
13280 void (*pagetable_setup_done)(pgd_t *base);
13281 -};
13282 +} __no_const;
13283
13284 /**
13285 * struct x86_init_timers - platform specific timer setup
13286 @@ -102,7 +102,7 @@ struct x86_init_timers {
13287 void (*tsc_pre_init)(void);
13288 void (*timer_init)(void);
13289 void (*wallclock_init)(void);
13290 -};
13291 +} __no_const;
13292
13293 /**
13294 * struct x86_init_iommu - platform specific iommu setup
13295 @@ -110,7 +110,7 @@ struct x86_init_timers {
13296 */
13297 struct x86_init_iommu {
13298 int (*iommu_init)(void);
13299 -};
13300 +} __no_const;
13301
13302 /**
13303 * struct x86_init_pci - platform specific pci init functions
13304 @@ -124,7 +124,7 @@ struct x86_init_pci {
13305 int (*init)(void);
13306 void (*init_irq)(void);
13307 void (*fixup_irqs)(void);
13308 -};
13309 +} __no_const;
13310
13311 /**
13312 * struct x86_init_ops - functions for platform specific setup
13313 @@ -140,7 +140,7 @@ struct x86_init_ops {
13314 struct x86_init_timers timers;
13315 struct x86_init_iommu iommu;
13316 struct x86_init_pci pci;
13317 -};
13318 +} __no_const;
13319
13320 /**
13321 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13322 @@ -149,7 +149,7 @@ struct x86_init_ops {
13323 struct x86_cpuinit_ops {
13324 void (*setup_percpu_clockev)(void);
13325 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13326 -};
13327 +} __no_const;
13328
13329 /**
13330 * struct x86_platform_ops - platform specific runtime functions
13331 @@ -171,7 +171,7 @@ struct x86_platform_ops {
13332 void (*nmi_init)(void);
13333 unsigned char (*get_nmi_reason)(void);
13334 int (*i8042_detect)(void);
13335 -};
13336 +} __no_const;
13337
13338 struct pci_dev;
13339
13340 @@ -180,7 +180,7 @@ struct x86_msi_ops {
13341 void (*teardown_msi_irq)(unsigned int irq);
13342 void (*teardown_msi_irqs)(struct pci_dev *dev);
13343 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13344 -};
13345 +} __no_const;
13346
13347 extern struct x86_init_ops x86_init;
13348 extern struct x86_cpuinit_ops x86_cpuinit;
13349 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13350 index c6ce245..ffbdab7 100644
13351 --- a/arch/x86/include/asm/xsave.h
13352 +++ b/arch/x86/include/asm/xsave.h
13353 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13354 {
13355 int err;
13356
13357 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13358 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13359 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13360 +#endif
13361 +
13362 /*
13363 * Clear the xsave header first, so that reserved fields are
13364 * initialized to zero.
13365 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13366 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13367 {
13368 int err;
13369 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13370 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13371 u32 lmask = mask;
13372 u32 hmask = mask >> 32;
13373
13374 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13375 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13376 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13377 +#endif
13378 +
13379 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13380 "2:\n"
13381 ".section .fixup,\"ax\"\n"
13382 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13383 index 6a564ac..9b1340c 100644
13384 --- a/arch/x86/kernel/acpi/realmode/Makefile
13385 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13386 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13387 $(call cc-option, -fno-stack-protector) \
13388 $(call cc-option, -mpreferred-stack-boundary=2)
13389 KBUILD_CFLAGS += $(call cc-option, -m32)
13390 +ifdef CONSTIFY_PLUGIN
13391 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13392 +endif
13393 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13394 GCOV_PROFILE := n
13395
13396 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13397 index b4fd836..4358fe3 100644
13398 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13399 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13400 @@ -108,6 +108,9 @@ wakeup_code:
13401 /* Do any other stuff... */
13402
13403 #ifndef CONFIG_64BIT
13404 + /* Recheck NX bit overrides (64bit path does this in trampoline */
13405 + call verify_cpu
13406 +
13407 /* This could also be done in C code... */
13408 movl pmode_cr3, %eax
13409 movl %eax, %cr3
13410 @@ -131,6 +134,7 @@ wakeup_code:
13411 movl pmode_cr0, %eax
13412 movl %eax, %cr0
13413 jmp pmode_return
13414 +# include "../../verify_cpu.S"
13415 #else
13416 pushw $0
13417 pushw trampoline_segment
13418 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13419 index 103b6ab..2004d0a 100644
13420 --- a/arch/x86/kernel/acpi/sleep.c
13421 +++ b/arch/x86/kernel/acpi/sleep.c
13422 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
13423 header->trampoline_segment = trampoline_address() >> 4;
13424 #ifdef CONFIG_SMP
13425 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13426 +
13427 + pax_open_kernel();
13428 early_gdt_descr.address =
13429 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13430 + pax_close_kernel();
13431 +
13432 initial_gs = per_cpu_offset(smp_processor_id());
13433 #endif
13434 initial_code = (unsigned long)wakeup_long64;
13435 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13436 index 13ab720..95d5442 100644
13437 --- a/arch/x86/kernel/acpi/wakeup_32.S
13438 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13439 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13440 # and restore the stack ... but you need gdt for this to work
13441 movl saved_context_esp, %esp
13442
13443 - movl %cs:saved_magic, %eax
13444 - cmpl $0x12345678, %eax
13445 + cmpl $0x12345678, saved_magic
13446 jne bogus_magic
13447
13448 # jump to place where we left off
13449 - movl saved_eip, %eax
13450 - jmp *%eax
13451 + jmp *(saved_eip)
13452
13453 bogus_magic:
13454 jmp bogus_magic
13455 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13456 index 1f84794..e23f862 100644
13457 --- a/arch/x86/kernel/alternative.c
13458 +++ b/arch/x86/kernel/alternative.c
13459 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13460 */
13461 for (a = start; a < end; a++) {
13462 instr = (u8 *)&a->instr_offset + a->instr_offset;
13463 +
13464 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13465 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13466 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13467 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13468 +#endif
13469 +
13470 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13471 BUG_ON(a->replacementlen > a->instrlen);
13472 BUG_ON(a->instrlen > sizeof(insnbuf));
13473 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13474 for (poff = start; poff < end; poff++) {
13475 u8 *ptr = (u8 *)poff + *poff;
13476
13477 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13478 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13479 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13480 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13481 +#endif
13482 +
13483 if (!*poff || ptr < text || ptr >= text_end)
13484 continue;
13485 /* turn DS segment override prefix into lock prefix */
13486 - if (*ptr == 0x3e)
13487 + if (*ktla_ktva(ptr) == 0x3e)
13488 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13489 };
13490 mutex_unlock(&text_mutex);
13491 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13492 for (poff = start; poff < end; poff++) {
13493 u8 *ptr = (u8 *)poff + *poff;
13494
13495 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13496 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13497 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13498 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13499 +#endif
13500 +
13501 if (!*poff || ptr < text || ptr >= text_end)
13502 continue;
13503 /* turn lock prefix into DS segment override prefix */
13504 - if (*ptr == 0xf0)
13505 + if (*ktla_ktva(ptr) == 0xf0)
13506 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13507 };
13508 mutex_unlock(&text_mutex);
13509 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13510
13511 BUG_ON(p->len > MAX_PATCH_LEN);
13512 /* prep the buffer with the original instructions */
13513 - memcpy(insnbuf, p->instr, p->len);
13514 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13515 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13516 (unsigned long)p->instr, p->len);
13517
13518 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13519 if (smp_alt_once)
13520 free_init_pages("SMP alternatives",
13521 (unsigned long)__smp_locks,
13522 - (unsigned long)__smp_locks_end);
13523 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13524
13525 restart_nmi();
13526 }
13527 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13528 * instructions. And on the local CPU you need to be protected again NMI or MCE
13529 * handlers seeing an inconsistent instruction while you patch.
13530 */
13531 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13532 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13533 size_t len)
13534 {
13535 unsigned long flags;
13536 local_irq_save(flags);
13537 - memcpy(addr, opcode, len);
13538 +
13539 + pax_open_kernel();
13540 + memcpy(ktla_ktva(addr), opcode, len);
13541 sync_core();
13542 + pax_close_kernel();
13543 +
13544 local_irq_restore(flags);
13545 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13546 that causes hangs on some VIA CPUs. */
13547 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13548 */
13549 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13550 {
13551 - unsigned long flags;
13552 - char *vaddr;
13553 + unsigned char *vaddr = ktla_ktva(addr);
13554 struct page *pages[2];
13555 - int i;
13556 + size_t i;
13557
13558 if (!core_kernel_text((unsigned long)addr)) {
13559 - pages[0] = vmalloc_to_page(addr);
13560 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13561 + pages[0] = vmalloc_to_page(vaddr);
13562 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13563 } else {
13564 - pages[0] = virt_to_page(addr);
13565 + pages[0] = virt_to_page(vaddr);
13566 WARN_ON(!PageReserved(pages[0]));
13567 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13568 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13569 }
13570 BUG_ON(!pages[0]);
13571 - local_irq_save(flags);
13572 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13573 - if (pages[1])
13574 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13575 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13576 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13577 - clear_fixmap(FIX_TEXT_POKE0);
13578 - if (pages[1])
13579 - clear_fixmap(FIX_TEXT_POKE1);
13580 - local_flush_tlb();
13581 - sync_core();
13582 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13583 - that causes hangs on some VIA CPUs. */
13584 + text_poke_early(addr, opcode, len);
13585 for (i = 0; i < len; i++)
13586 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13587 - local_irq_restore(flags);
13588 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13589 return addr;
13590 }
13591
13592 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13593 index 5b3f88e..61232b4 100644
13594 --- a/arch/x86/kernel/apic/apic.c
13595 +++ b/arch/x86/kernel/apic/apic.c
13596 @@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13597 /*
13598 * Debug level, exported for io_apic.c
13599 */
13600 -unsigned int apic_verbosity;
13601 +int apic_verbosity;
13602
13603 int pic_mode;
13604
13605 @@ -1912,7 +1912,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13606 apic_write(APIC_ESR, 0);
13607 v1 = apic_read(APIC_ESR);
13608 ack_APIC_irq();
13609 - atomic_inc(&irq_err_count);
13610 + atomic_inc_unchecked(&irq_err_count);
13611
13612 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13613 smp_processor_id(), v0 , v1);
13614 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13615 index fb07275..e06bb59 100644
13616 --- a/arch/x86/kernel/apic/io_apic.c
13617 +++ b/arch/x86/kernel/apic/io_apic.c
13618 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13619 }
13620 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13621
13622 -void lock_vector_lock(void)
13623 +void lock_vector_lock(void) __acquires(vector_lock)
13624 {
13625 /* Used to the online set of cpus does not change
13626 * during assign_irq_vector.
13627 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
13628 raw_spin_lock(&vector_lock);
13629 }
13630
13631 -void unlock_vector_lock(void)
13632 +void unlock_vector_lock(void) __releases(vector_lock)
13633 {
13634 raw_spin_unlock(&vector_lock);
13635 }
13636 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
13637 ack_APIC_irq();
13638 }
13639
13640 -atomic_t irq_mis_count;
13641 +atomic_unchecked_t irq_mis_count;
13642
13643 static void ack_apic_level(struct irq_data *data)
13644 {
13645 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
13646 * at the cpu.
13647 */
13648 if (!(v & (1 << (i & 0x1f)))) {
13649 - atomic_inc(&irq_mis_count);
13650 + atomic_inc_unchecked(&irq_mis_count);
13651
13652 eoi_ioapic_irq(irq, cfg);
13653 }
13654 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13655 index f76623c..aab694f 100644
13656 --- a/arch/x86/kernel/apm_32.c
13657 +++ b/arch/x86/kernel/apm_32.c
13658 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
13659 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13660 * even though they are called in protected mode.
13661 */
13662 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13663 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13664 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13665
13666 static const char driver_version[] = "1.16ac"; /* no spaces */
13667 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
13668 BUG_ON(cpu != 0);
13669 gdt = get_cpu_gdt_table(cpu);
13670 save_desc_40 = gdt[0x40 / 8];
13671 +
13672 + pax_open_kernel();
13673 gdt[0x40 / 8] = bad_bios_desc;
13674 + pax_close_kernel();
13675
13676 apm_irq_save(flags);
13677 APM_DO_SAVE_SEGS;
13678 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
13679 &call->esi);
13680 APM_DO_RESTORE_SEGS;
13681 apm_irq_restore(flags);
13682 +
13683 + pax_open_kernel();
13684 gdt[0x40 / 8] = save_desc_40;
13685 + pax_close_kernel();
13686 +
13687 put_cpu();
13688
13689 return call->eax & 0xff;
13690 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
13691 BUG_ON(cpu != 0);
13692 gdt = get_cpu_gdt_table(cpu);
13693 save_desc_40 = gdt[0x40 / 8];
13694 +
13695 + pax_open_kernel();
13696 gdt[0x40 / 8] = bad_bios_desc;
13697 + pax_close_kernel();
13698
13699 apm_irq_save(flags);
13700 APM_DO_SAVE_SEGS;
13701 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
13702 &call->eax);
13703 APM_DO_RESTORE_SEGS;
13704 apm_irq_restore(flags);
13705 +
13706 + pax_open_kernel();
13707 gdt[0x40 / 8] = save_desc_40;
13708 + pax_close_kernel();
13709 +
13710 put_cpu();
13711 return error;
13712 }
13713 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
13714 * code to that CPU.
13715 */
13716 gdt = get_cpu_gdt_table(0);
13717 +
13718 + pax_open_kernel();
13719 set_desc_base(&gdt[APM_CS >> 3],
13720 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13721 set_desc_base(&gdt[APM_CS_16 >> 3],
13722 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13723 set_desc_base(&gdt[APM_DS >> 3],
13724 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13725 + pax_close_kernel();
13726
13727 proc_create("apm", 0, NULL, &apm_file_ops);
13728
13729 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13730 index 68de2dc..1f3c720 100644
13731 --- a/arch/x86/kernel/asm-offsets.c
13732 +++ b/arch/x86/kernel/asm-offsets.c
13733 @@ -33,6 +33,8 @@ void common(void) {
13734 OFFSET(TI_status, thread_info, status);
13735 OFFSET(TI_addr_limit, thread_info, addr_limit);
13736 OFFSET(TI_preempt_count, thread_info, preempt_count);
13737 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13738 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13739
13740 BLANK();
13741 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13742 @@ -53,8 +55,26 @@ void common(void) {
13743 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13744 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13745 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13746 +
13747 +#ifdef CONFIG_PAX_KERNEXEC
13748 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13749 #endif
13750
13751 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13752 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13753 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13754 +#ifdef CONFIG_X86_64
13755 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13756 +#endif
13757 +#endif
13758 +
13759 +#endif
13760 +
13761 + BLANK();
13762 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13763 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13764 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13765 +
13766 #ifdef CONFIG_XEN
13767 BLANK();
13768 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13769 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13770 index 834e897..dacddc8 100644
13771 --- a/arch/x86/kernel/asm-offsets_64.c
13772 +++ b/arch/x86/kernel/asm-offsets_64.c
13773 @@ -70,6 +70,7 @@ int main(void)
13774 BLANK();
13775 #undef ENTRY
13776
13777 + DEFINE(TSS_size, sizeof(struct tss_struct));
13778 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13779 BLANK();
13780
13781 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13782 index 25f24dc..4094a7f 100644
13783 --- a/arch/x86/kernel/cpu/Makefile
13784 +++ b/arch/x86/kernel/cpu/Makefile
13785 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13786 CFLAGS_REMOVE_perf_event.o = -pg
13787 endif
13788
13789 -# Make sure load_percpu_segment has no stackprotector
13790 -nostackp := $(call cc-option, -fno-stack-protector)
13791 -CFLAGS_common.o := $(nostackp)
13792 -
13793 obj-y := intel_cacheinfo.o scattered.o topology.o
13794 obj-y += proc.o capflags.o powerflags.o common.o
13795 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13796 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13797 index 80ab83d..0a7b34e 100644
13798 --- a/arch/x86/kernel/cpu/amd.c
13799 +++ b/arch/x86/kernel/cpu/amd.c
13800 @@ -670,7 +670,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13801 unsigned int size)
13802 {
13803 /* AMD errata T13 (order #21922) */
13804 - if ((c->x86 == 6)) {
13805 + if (c->x86 == 6) {
13806 /* Duron Rev A0 */
13807 if (c->x86_model == 3 && c->x86_mask == 0)
13808 size = 64;
13809 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13810 index 1a810e4..9fa8201 100644
13811 --- a/arch/x86/kernel/cpu/common.c
13812 +++ b/arch/x86/kernel/cpu/common.c
13813 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13814
13815 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13816
13817 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13818 -#ifdef CONFIG_X86_64
13819 - /*
13820 - * We need valid kernel segments for data and code in long mode too
13821 - * IRET will check the segment types kkeil 2000/10/28
13822 - * Also sysret mandates a special GDT layout
13823 - *
13824 - * TLS descriptors are currently at a different place compared to i386.
13825 - * Hopefully nobody expects them at a fixed place (Wine?)
13826 - */
13827 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13828 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13829 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13830 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13831 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13832 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13833 -#else
13834 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13835 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13836 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13837 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13838 - /*
13839 - * Segments used for calling PnP BIOS have byte granularity.
13840 - * They code segments and data segments have fixed 64k limits,
13841 - * the transfer segment sizes are set at run time.
13842 - */
13843 - /* 32-bit code */
13844 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13845 - /* 16-bit code */
13846 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13847 - /* 16-bit data */
13848 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13849 - /* 16-bit data */
13850 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13851 - /* 16-bit data */
13852 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13853 - /*
13854 - * The APM segments have byte granularity and their bases
13855 - * are set at run time. All have 64k limits.
13856 - */
13857 - /* 32-bit code */
13858 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13859 - /* 16-bit code */
13860 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13861 - /* data */
13862 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13863 -
13864 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13865 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13866 - GDT_STACK_CANARY_INIT
13867 -#endif
13868 -} };
13869 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13870 -
13871 static int __init x86_xsave_setup(char *s)
13872 {
13873 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13874 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
13875 {
13876 struct desc_ptr gdt_descr;
13877
13878 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13879 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13880 gdt_descr.size = GDT_SIZE - 1;
13881 load_gdt(&gdt_descr);
13882 /* Reload the per-cpu base */
13883 @@ -839,6 +785,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
13884 /* Filter out anything that depends on CPUID levels we don't have */
13885 filter_cpuid_features(c, true);
13886
13887 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
13888 + setup_clear_cpu_cap(X86_FEATURE_SEP);
13889 +#endif
13890 +
13891 /* If the model name is still unset, do table lookup. */
13892 if (!c->x86_model_id[0]) {
13893 const char *p;
13894 @@ -1019,10 +969,12 @@ static __init int setup_disablecpuid(char *arg)
13895 }
13896 __setup("clearcpuid=", setup_disablecpuid);
13897
13898 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13899 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
13900 +
13901 #ifdef CONFIG_X86_64
13902 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13903 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
13904 - (unsigned long) nmi_idt_table };
13905 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
13906
13907 DEFINE_PER_CPU_FIRST(union irq_stack_union,
13908 irq_stack_union) __aligned(PAGE_SIZE);
13909 @@ -1036,7 +988,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
13910 EXPORT_PER_CPU_SYMBOL(current_task);
13911
13912 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13913 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13914 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13915 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13916
13917 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13918 @@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
13919 {
13920 memset(regs, 0, sizeof(struct pt_regs));
13921 regs->fs = __KERNEL_PERCPU;
13922 - regs->gs = __KERNEL_STACK_CANARY;
13923 + savesegment(gs, regs->gs);
13924
13925 return regs;
13926 }
13927 @@ -1181,7 +1133,7 @@ void __cpuinit cpu_init(void)
13928 int i;
13929
13930 cpu = stack_smp_processor_id();
13931 - t = &per_cpu(init_tss, cpu);
13932 + t = init_tss + cpu;
13933 oist = &per_cpu(orig_ist, cpu);
13934
13935 #ifdef CONFIG_NUMA
13936 @@ -1207,7 +1159,7 @@ void __cpuinit cpu_init(void)
13937 switch_to_new_gdt(cpu);
13938 loadsegment(fs, 0);
13939
13940 - load_idt((const struct desc_ptr *)&idt_descr);
13941 + load_idt(&idt_descr);
13942
13943 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13944 syscall_init();
13945 @@ -1216,7 +1168,6 @@ void __cpuinit cpu_init(void)
13946 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13947 barrier();
13948
13949 - x86_configure_nx();
13950 if (cpu != 0)
13951 enable_x2apic();
13952
13953 @@ -1272,7 +1223,7 @@ void __cpuinit cpu_init(void)
13954 {
13955 int cpu = smp_processor_id();
13956 struct task_struct *curr = current;
13957 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13958 + struct tss_struct *t = init_tss + cpu;
13959 struct thread_struct *thread = &curr->thread;
13960
13961 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13962 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13963 index 3e6ff6c..54b4992 100644
13964 --- a/arch/x86/kernel/cpu/intel.c
13965 +++ b/arch/x86/kernel/cpu/intel.c
13966 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
13967 * Update the IDT descriptor and reload the IDT so that
13968 * it uses the read-only mapped virtual address.
13969 */
13970 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13971 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13972 load_idt(&idt_descr);
13973 }
13974 #endif
13975 diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13976 index fc4beb3..f20a5a7 100644
13977 --- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
13978 +++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13979 @@ -199,6 +199,8 @@ static void raise_mce(struct mce *m)
13980
13981 /* Error injection interface */
13982 static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13983 + size_t usize, loff_t *off) __size_overflow(3);
13984 +static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13985 size_t usize, loff_t *off)
13986 {
13987 struct mce m;
13988 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13989 index 5a11ae2..a1a1c8a 100644
13990 --- a/arch/x86/kernel/cpu/mcheck/mce.c
13991 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
13992 @@ -42,6 +42,7 @@
13993 #include <asm/processor.h>
13994 #include <asm/mce.h>
13995 #include <asm/msr.h>
13996 +#include <asm/local.h>
13997
13998 #include "mce-internal.h"
13999
14000 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14001 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14002 m->cs, m->ip);
14003
14004 - if (m->cs == __KERNEL_CS)
14005 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14006 print_symbol("{%s}", m->ip);
14007 pr_cont("\n");
14008 }
14009 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14010
14011 #define PANIC_TIMEOUT 5 /* 5 seconds */
14012
14013 -static atomic_t mce_paniced;
14014 +static atomic_unchecked_t mce_paniced;
14015
14016 static int fake_panic;
14017 -static atomic_t mce_fake_paniced;
14018 +static atomic_unchecked_t mce_fake_paniced;
14019
14020 /* Panic in progress. Enable interrupts and wait for final IPI */
14021 static void wait_for_panic(void)
14022 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14023 /*
14024 * Make sure only one CPU runs in machine check panic
14025 */
14026 - if (atomic_inc_return(&mce_paniced) > 1)
14027 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14028 wait_for_panic();
14029 barrier();
14030
14031 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14032 console_verbose();
14033 } else {
14034 /* Don't log too much for fake panic */
14035 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14036 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14037 return;
14038 }
14039 /* First print corrected ones that are still unlogged */
14040 @@ -658,7 +659,7 @@ static int mce_timed_out(u64 *t)
14041 * might have been modified by someone else.
14042 */
14043 rmb();
14044 - if (atomic_read(&mce_paniced))
14045 + if (atomic_read_unchecked(&mce_paniced))
14046 wait_for_panic();
14047 if (!monarch_timeout)
14048 goto out;
14049 @@ -1446,7 +1447,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14050 }
14051
14052 /* Call the installed machine check handler for this CPU setup. */
14053 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14054 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14055 unexpected_machine_check;
14056
14057 /*
14058 @@ -1469,7 +1470,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14059 return;
14060 }
14061
14062 + pax_open_kernel();
14063 machine_check_vector = do_machine_check;
14064 + pax_close_kernel();
14065
14066 __mcheck_cpu_init_generic();
14067 __mcheck_cpu_init_vendor(c);
14068 @@ -1483,7 +1486,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14069 */
14070
14071 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14072 -static int mce_chrdev_open_count; /* #times opened */
14073 +static local_t mce_chrdev_open_count; /* #times opened */
14074 static int mce_chrdev_open_exclu; /* already open exclusive? */
14075
14076 static int mce_chrdev_open(struct inode *inode, struct file *file)
14077 @@ -1491,7 +1494,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14078 spin_lock(&mce_chrdev_state_lock);
14079
14080 if (mce_chrdev_open_exclu ||
14081 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14082 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14083 spin_unlock(&mce_chrdev_state_lock);
14084
14085 return -EBUSY;
14086 @@ -1499,7 +1502,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14087
14088 if (file->f_flags & O_EXCL)
14089 mce_chrdev_open_exclu = 1;
14090 - mce_chrdev_open_count++;
14091 + local_inc(&mce_chrdev_open_count);
14092
14093 spin_unlock(&mce_chrdev_state_lock);
14094
14095 @@ -1510,7 +1513,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14096 {
14097 spin_lock(&mce_chrdev_state_lock);
14098
14099 - mce_chrdev_open_count--;
14100 + local_dec(&mce_chrdev_open_count);
14101 mce_chrdev_open_exclu = 0;
14102
14103 spin_unlock(&mce_chrdev_state_lock);
14104 @@ -2229,7 +2232,7 @@ struct dentry *mce_get_debugfs_dir(void)
14105 static void mce_reset(void)
14106 {
14107 cpu_missing = 0;
14108 - atomic_set(&mce_fake_paniced, 0);
14109 + atomic_set_unchecked(&mce_fake_paniced, 0);
14110 atomic_set(&mce_executing, 0);
14111 atomic_set(&mce_callin, 0);
14112 atomic_set(&global_nwo, 0);
14113 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14114 index 5c0e653..0882b0a 100644
14115 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14116 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14117 @@ -12,6 +12,7 @@
14118 #include <asm/system.h>
14119 #include <asm/mce.h>
14120 #include <asm/msr.h>
14121 +#include <asm/pgtable.h>
14122
14123 /* By default disabled */
14124 int mce_p5_enabled __read_mostly;
14125 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14126 if (!cpu_has(c, X86_FEATURE_MCE))
14127 return;
14128
14129 + pax_open_kernel();
14130 machine_check_vector = pentium_machine_check;
14131 + pax_close_kernel();
14132 /* Make sure the vector pointer is visible before we enable MCEs: */
14133 wmb();
14134
14135 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14136 index 54060f5..c1a7577 100644
14137 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14138 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14139 @@ -11,6 +11,7 @@
14140 #include <asm/system.h>
14141 #include <asm/mce.h>
14142 #include <asm/msr.h>
14143 +#include <asm/pgtable.h>
14144
14145 /* Machine check handler for WinChip C6: */
14146 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14147 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14148 {
14149 u32 lo, hi;
14150
14151 + pax_open_kernel();
14152 machine_check_vector = winchip_machine_check;
14153 + pax_close_kernel();
14154 /* Make sure the vector pointer is visible before we enable MCEs: */
14155 wmb();
14156
14157 diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
14158 index 7928963..1b16001 100644
14159 --- a/arch/x86/kernel/cpu/mtrr/if.c
14160 +++ b/arch/x86/kernel/cpu/mtrr/if.c
14161 @@ -91,6 +91,8 @@ mtrr_file_del(unsigned long base, unsigned long size,
14162 * "base=%Lx size=%Lx type=%s" or "disable=%d"
14163 */
14164 static ssize_t
14165 +mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos) __size_overflow(3);
14166 +static ssize_t
14167 mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
14168 {
14169 int i, err;
14170 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14171 index 6b96110..0da73eb 100644
14172 --- a/arch/x86/kernel/cpu/mtrr/main.c
14173 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14174 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14175 u64 size_or_mask, size_and_mask;
14176 static bool mtrr_aps_delayed_init;
14177
14178 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14179 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14180
14181 const struct mtrr_ops *mtrr_if;
14182
14183 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14184 index df5e41f..816c719 100644
14185 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14186 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14187 @@ -25,7 +25,7 @@ struct mtrr_ops {
14188 int (*validate_add_page)(unsigned long base, unsigned long size,
14189 unsigned int type);
14190 int (*have_wrcomb)(void);
14191 -};
14192 +} __do_const;
14193
14194 extern int generic_get_free_region(unsigned long base, unsigned long size,
14195 int replace_reg);
14196 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14197 index 5adce10..99284ec 100644
14198 --- a/arch/x86/kernel/cpu/perf_event.c
14199 +++ b/arch/x86/kernel/cpu/perf_event.c
14200 @@ -1665,7 +1665,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14201 break;
14202
14203 perf_callchain_store(entry, frame.return_address);
14204 - fp = frame.next_frame;
14205 + fp = (const void __force_user *)frame.next_frame;
14206 }
14207 }
14208
14209 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14210 index 13ad899..f642b9a 100644
14211 --- a/arch/x86/kernel/crash.c
14212 +++ b/arch/x86/kernel/crash.c
14213 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14214 {
14215 #ifdef CONFIG_X86_32
14216 struct pt_regs fixed_regs;
14217 -#endif
14218
14219 -#ifdef CONFIG_X86_32
14220 - if (!user_mode_vm(regs)) {
14221 + if (!user_mode(regs)) {
14222 crash_fixup_ss_esp(&fixed_regs, regs);
14223 regs = &fixed_regs;
14224 }
14225 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14226 index 37250fe..bf2ec74 100644
14227 --- a/arch/x86/kernel/doublefault_32.c
14228 +++ b/arch/x86/kernel/doublefault_32.c
14229 @@ -11,7 +11,7 @@
14230
14231 #define DOUBLEFAULT_STACKSIZE (1024)
14232 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14233 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14234 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14235
14236 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14237
14238 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14239 unsigned long gdt, tss;
14240
14241 store_gdt(&gdt_desc);
14242 - gdt = gdt_desc.address;
14243 + gdt = (unsigned long)gdt_desc.address;
14244
14245 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14246
14247 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14248 /* 0x2 bit is always set */
14249 .flags = X86_EFLAGS_SF | 0x2,
14250 .sp = STACK_START,
14251 - .es = __USER_DS,
14252 + .es = __KERNEL_DS,
14253 .cs = __KERNEL_CS,
14254 .ss = __KERNEL_DS,
14255 - .ds = __USER_DS,
14256 + .ds = __KERNEL_DS,
14257 .fs = __KERNEL_PERCPU,
14258
14259 .__cr3 = __pa_nodebug(swapper_pg_dir),
14260 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14261 index 4025fe4..d8451c6 100644
14262 --- a/arch/x86/kernel/dumpstack.c
14263 +++ b/arch/x86/kernel/dumpstack.c
14264 @@ -2,6 +2,9 @@
14265 * Copyright (C) 1991, 1992 Linus Torvalds
14266 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14267 */
14268 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14269 +#define __INCLUDED_BY_HIDESYM 1
14270 +#endif
14271 #include <linux/kallsyms.h>
14272 #include <linux/kprobes.h>
14273 #include <linux/uaccess.h>
14274 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
14275 static void
14276 print_ftrace_graph_addr(unsigned long addr, void *data,
14277 const struct stacktrace_ops *ops,
14278 - struct thread_info *tinfo, int *graph)
14279 + struct task_struct *task, int *graph)
14280 {
14281 - struct task_struct *task = tinfo->task;
14282 unsigned long ret_addr;
14283 int index = task->curr_ret_stack;
14284
14285 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14286 static inline void
14287 print_ftrace_graph_addr(unsigned long addr, void *data,
14288 const struct stacktrace_ops *ops,
14289 - struct thread_info *tinfo, int *graph)
14290 + struct task_struct *task, int *graph)
14291 { }
14292 #endif
14293
14294 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14295 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14296 */
14297
14298 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14299 - void *p, unsigned int size, void *end)
14300 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14301 {
14302 - void *t = tinfo;
14303 if (end) {
14304 if (p < end && p >= (end-THREAD_SIZE))
14305 return 1;
14306 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14307 }
14308
14309 unsigned long
14310 -print_context_stack(struct thread_info *tinfo,
14311 +print_context_stack(struct task_struct *task, void *stack_start,
14312 unsigned long *stack, unsigned long bp,
14313 const struct stacktrace_ops *ops, void *data,
14314 unsigned long *end, int *graph)
14315 {
14316 struct stack_frame *frame = (struct stack_frame *)bp;
14317
14318 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14319 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14320 unsigned long addr;
14321
14322 addr = *stack;
14323 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
14324 } else {
14325 ops->address(data, addr, 0);
14326 }
14327 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14328 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14329 }
14330 stack++;
14331 }
14332 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
14333 EXPORT_SYMBOL_GPL(print_context_stack);
14334
14335 unsigned long
14336 -print_context_stack_bp(struct thread_info *tinfo,
14337 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14338 unsigned long *stack, unsigned long bp,
14339 const struct stacktrace_ops *ops, void *data,
14340 unsigned long *end, int *graph)
14341 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14342 struct stack_frame *frame = (struct stack_frame *)bp;
14343 unsigned long *ret_addr = &frame->return_address;
14344
14345 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14346 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14347 unsigned long addr = *ret_addr;
14348
14349 if (!__kernel_text_address(addr))
14350 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14351 ops->address(data, addr, 1);
14352 frame = frame->next_frame;
14353 ret_addr = &frame->return_address;
14354 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14355 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14356 }
14357
14358 return (unsigned long)frame;
14359 @@ -186,7 +186,7 @@ void dump_stack(void)
14360
14361 bp = stack_frame(current, NULL);
14362 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14363 - current->pid, current->comm, print_tainted(),
14364 + task_pid_nr(current), current->comm, print_tainted(),
14365 init_utsname()->release,
14366 (int)strcspn(init_utsname()->version, " "),
14367 init_utsname()->version);
14368 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
14369 }
14370 EXPORT_SYMBOL_GPL(oops_begin);
14371
14372 +extern void gr_handle_kernel_exploit(void);
14373 +
14374 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14375 {
14376 if (regs && kexec_should_crash(current))
14377 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14378 panic("Fatal exception in interrupt");
14379 if (panic_on_oops)
14380 panic("Fatal exception");
14381 - do_exit(signr);
14382 +
14383 + gr_handle_kernel_exploit();
14384 +
14385 + do_group_exit(signr);
14386 }
14387
14388 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14389 @@ -270,7 +275,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14390
14391 show_registers(regs);
14392 #ifdef CONFIG_X86_32
14393 - if (user_mode_vm(regs)) {
14394 + if (user_mode(regs)) {
14395 sp = regs->sp;
14396 ss = regs->ss & 0xffff;
14397 } else {
14398 @@ -298,7 +303,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14399 unsigned long flags = oops_begin();
14400 int sig = SIGSEGV;
14401
14402 - if (!user_mode_vm(regs))
14403 + if (!user_mode(regs))
14404 report_bug(regs->ip, regs);
14405
14406 if (__die(str, regs, err))
14407 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14408 index c99f9ed..2a15d80 100644
14409 --- a/arch/x86/kernel/dumpstack_32.c
14410 +++ b/arch/x86/kernel/dumpstack_32.c
14411 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14412 bp = stack_frame(task, regs);
14413
14414 for (;;) {
14415 - struct thread_info *context;
14416 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14417
14418 - context = (struct thread_info *)
14419 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14420 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14421 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14422
14423 - stack = (unsigned long *)context->previous_esp;
14424 - if (!stack)
14425 + if (stack_start == task_stack_page(task))
14426 break;
14427 + stack = *(unsigned long **)stack_start;
14428 if (ops->stack(data, "IRQ") < 0)
14429 break;
14430 touch_nmi_watchdog();
14431 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14432 * When in-kernel, we also print out the stack and code at the
14433 * time of the fault..
14434 */
14435 - if (!user_mode_vm(regs)) {
14436 + if (!user_mode(regs)) {
14437 unsigned int code_prologue = code_bytes * 43 / 64;
14438 unsigned int code_len = code_bytes;
14439 unsigned char c;
14440 u8 *ip;
14441 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14442
14443 printk(KERN_EMERG "Stack:\n");
14444 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14445
14446 printk(KERN_EMERG "Code: ");
14447
14448 - ip = (u8 *)regs->ip - code_prologue;
14449 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14450 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14451 /* try starting at IP */
14452 - ip = (u8 *)regs->ip;
14453 + ip = (u8 *)regs->ip + cs_base;
14454 code_len = code_len - code_prologue + 1;
14455 }
14456 for (i = 0; i < code_len; i++, ip++) {
14457 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14458 printk(KERN_CONT " Bad EIP value.");
14459 break;
14460 }
14461 - if (ip == (u8 *)regs->ip)
14462 + if (ip == (u8 *)regs->ip + cs_base)
14463 printk(KERN_CONT "<%02x> ", c);
14464 else
14465 printk(KERN_CONT "%02x ", c);
14466 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14467 {
14468 unsigned short ud2;
14469
14470 + ip = ktla_ktva(ip);
14471 if (ip < PAGE_OFFSET)
14472 return 0;
14473 if (probe_kernel_address((unsigned short *)ip, ud2))
14474 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14475
14476 return ud2 == 0x0b0f;
14477 }
14478 +
14479 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14480 +void pax_check_alloca(unsigned long size)
14481 +{
14482 + unsigned long sp = (unsigned long)&sp, stack_left;
14483 +
14484 + /* all kernel stacks are of the same size */
14485 + stack_left = sp & (THREAD_SIZE - 1);
14486 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14487 +}
14488 +EXPORT_SYMBOL(pax_check_alloca);
14489 +#endif
14490 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14491 index 17107bd..b2deecf 100644
14492 --- a/arch/x86/kernel/dumpstack_64.c
14493 +++ b/arch/x86/kernel/dumpstack_64.c
14494 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14495 unsigned long *irq_stack_end =
14496 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14497 unsigned used = 0;
14498 - struct thread_info *tinfo;
14499 int graph = 0;
14500 unsigned long dummy;
14501 + void *stack_start;
14502
14503 if (!task)
14504 task = current;
14505 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14506 * current stack address. If the stacks consist of nested
14507 * exceptions
14508 */
14509 - tinfo = task_thread_info(task);
14510 for (;;) {
14511 char *id;
14512 unsigned long *estack_end;
14513 +
14514 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14515 &used, &id);
14516
14517 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14518 if (ops->stack(data, id) < 0)
14519 break;
14520
14521 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14522 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14523 data, estack_end, &graph);
14524 ops->stack(data, "<EOE>");
14525 /*
14526 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14527 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14528 if (ops->stack(data, "IRQ") < 0)
14529 break;
14530 - bp = ops->walk_stack(tinfo, stack, bp,
14531 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14532 ops, data, irq_stack_end, &graph);
14533 /*
14534 * We link to the next stack (which would be
14535 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14536 /*
14537 * This handles the process stack:
14538 */
14539 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14540 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14541 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14542 put_cpu();
14543 }
14544 EXPORT_SYMBOL(dump_trace);
14545 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
14546
14547 return ud2 == 0x0b0f;
14548 }
14549 +
14550 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14551 +void pax_check_alloca(unsigned long size)
14552 +{
14553 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14554 + unsigned cpu, used;
14555 + char *id;
14556 +
14557 + /* check the process stack first */
14558 + stack_start = (unsigned long)task_stack_page(current);
14559 + stack_end = stack_start + THREAD_SIZE;
14560 + if (likely(stack_start <= sp && sp < stack_end)) {
14561 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14562 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14563 + return;
14564 + }
14565 +
14566 + cpu = get_cpu();
14567 +
14568 + /* check the irq stacks */
14569 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14570 + stack_start = stack_end - IRQ_STACK_SIZE;
14571 + if (stack_start <= sp && sp < stack_end) {
14572 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14573 + put_cpu();
14574 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14575 + return;
14576 + }
14577 +
14578 + /* check the exception stacks */
14579 + used = 0;
14580 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14581 + stack_start = stack_end - EXCEPTION_STKSZ;
14582 + if (stack_end && stack_start <= sp && sp < stack_end) {
14583 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14584 + put_cpu();
14585 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14586 + return;
14587 + }
14588 +
14589 + put_cpu();
14590 +
14591 + /* unknown stack */
14592 + BUG();
14593 +}
14594 +EXPORT_SYMBOL(pax_check_alloca);
14595 +#endif
14596 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14597 index 9b9f18b..9fcaa04 100644
14598 --- a/arch/x86/kernel/early_printk.c
14599 +++ b/arch/x86/kernel/early_printk.c
14600 @@ -7,6 +7,7 @@
14601 #include <linux/pci_regs.h>
14602 #include <linux/pci_ids.h>
14603 #include <linux/errno.h>
14604 +#include <linux/sched.h>
14605 #include <asm/io.h>
14606 #include <asm/processor.h>
14607 #include <asm/fcntl.h>
14608 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14609 index 7b784f4..76aaad7 100644
14610 --- a/arch/x86/kernel/entry_32.S
14611 +++ b/arch/x86/kernel/entry_32.S
14612 @@ -179,13 +179,146 @@
14613 /*CFI_REL_OFFSET gs, PT_GS*/
14614 .endm
14615 .macro SET_KERNEL_GS reg
14616 +
14617 +#ifdef CONFIG_CC_STACKPROTECTOR
14618 movl $(__KERNEL_STACK_CANARY), \reg
14619 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14620 + movl $(__USER_DS), \reg
14621 +#else
14622 + xorl \reg, \reg
14623 +#endif
14624 +
14625 movl \reg, %gs
14626 .endm
14627
14628 #endif /* CONFIG_X86_32_LAZY_GS */
14629
14630 -.macro SAVE_ALL
14631 +.macro pax_enter_kernel
14632 +#ifdef CONFIG_PAX_KERNEXEC
14633 + call pax_enter_kernel
14634 +#endif
14635 +.endm
14636 +
14637 +.macro pax_exit_kernel
14638 +#ifdef CONFIG_PAX_KERNEXEC
14639 + call pax_exit_kernel
14640 +#endif
14641 +.endm
14642 +
14643 +#ifdef CONFIG_PAX_KERNEXEC
14644 +ENTRY(pax_enter_kernel)
14645 +#ifdef CONFIG_PARAVIRT
14646 + pushl %eax
14647 + pushl %ecx
14648 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14649 + mov %eax, %esi
14650 +#else
14651 + mov %cr0, %esi
14652 +#endif
14653 + bts $16, %esi
14654 + jnc 1f
14655 + mov %cs, %esi
14656 + cmp $__KERNEL_CS, %esi
14657 + jz 3f
14658 + ljmp $__KERNEL_CS, $3f
14659 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14660 +2:
14661 +#ifdef CONFIG_PARAVIRT
14662 + mov %esi, %eax
14663 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14664 +#else
14665 + mov %esi, %cr0
14666 +#endif
14667 +3:
14668 +#ifdef CONFIG_PARAVIRT
14669 + popl %ecx
14670 + popl %eax
14671 +#endif
14672 + ret
14673 +ENDPROC(pax_enter_kernel)
14674 +
14675 +ENTRY(pax_exit_kernel)
14676 +#ifdef CONFIG_PARAVIRT
14677 + pushl %eax
14678 + pushl %ecx
14679 +#endif
14680 + mov %cs, %esi
14681 + cmp $__KERNEXEC_KERNEL_CS, %esi
14682 + jnz 2f
14683 +#ifdef CONFIG_PARAVIRT
14684 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14685 + mov %eax, %esi
14686 +#else
14687 + mov %cr0, %esi
14688 +#endif
14689 + btr $16, %esi
14690 + ljmp $__KERNEL_CS, $1f
14691 +1:
14692 +#ifdef CONFIG_PARAVIRT
14693 + mov %esi, %eax
14694 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14695 +#else
14696 + mov %esi, %cr0
14697 +#endif
14698 +2:
14699 +#ifdef CONFIG_PARAVIRT
14700 + popl %ecx
14701 + popl %eax
14702 +#endif
14703 + ret
14704 +ENDPROC(pax_exit_kernel)
14705 +#endif
14706 +
14707 +.macro pax_erase_kstack
14708 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14709 + call pax_erase_kstack
14710 +#endif
14711 +.endm
14712 +
14713 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14714 +/*
14715 + * ebp: thread_info
14716 + * ecx, edx: can be clobbered
14717 + */
14718 +ENTRY(pax_erase_kstack)
14719 + pushl %edi
14720 + pushl %eax
14721 +
14722 + mov TI_lowest_stack(%ebp), %edi
14723 + mov $-0xBEEF, %eax
14724 + std
14725 +
14726 +1: mov %edi, %ecx
14727 + and $THREAD_SIZE_asm - 1, %ecx
14728 + shr $2, %ecx
14729 + repne scasl
14730 + jecxz 2f
14731 +
14732 + cmp $2*16, %ecx
14733 + jc 2f
14734 +
14735 + mov $2*16, %ecx
14736 + repe scasl
14737 + jecxz 2f
14738 + jne 1b
14739 +
14740 +2: cld
14741 + mov %esp, %ecx
14742 + sub %edi, %ecx
14743 + shr $2, %ecx
14744 + rep stosl
14745 +
14746 + mov TI_task_thread_sp0(%ebp), %edi
14747 + sub $128, %edi
14748 + mov %edi, TI_lowest_stack(%ebp)
14749 +
14750 + popl %eax
14751 + popl %edi
14752 + ret
14753 +ENDPROC(pax_erase_kstack)
14754 +#endif
14755 +
14756 +.macro __SAVE_ALL _DS
14757 cld
14758 PUSH_GS
14759 pushl_cfi %fs
14760 @@ -208,7 +341,7 @@
14761 CFI_REL_OFFSET ecx, 0
14762 pushl_cfi %ebx
14763 CFI_REL_OFFSET ebx, 0
14764 - movl $(__USER_DS), %edx
14765 + movl $\_DS, %edx
14766 movl %edx, %ds
14767 movl %edx, %es
14768 movl $(__KERNEL_PERCPU), %edx
14769 @@ -216,6 +349,15 @@
14770 SET_KERNEL_GS %edx
14771 .endm
14772
14773 +.macro SAVE_ALL
14774 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14775 + __SAVE_ALL __KERNEL_DS
14776 + pax_enter_kernel
14777 +#else
14778 + __SAVE_ALL __USER_DS
14779 +#endif
14780 +.endm
14781 +
14782 .macro RESTORE_INT_REGS
14783 popl_cfi %ebx
14784 CFI_RESTORE ebx
14785 @@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
14786 popfl_cfi
14787 jmp syscall_exit
14788 CFI_ENDPROC
14789 -END(ret_from_fork)
14790 +ENDPROC(ret_from_fork)
14791
14792 /*
14793 * Interrupt exit functions should be protected against kprobes
14794 @@ -335,7 +477,15 @@ resume_userspace_sig:
14795 andl $SEGMENT_RPL_MASK, %eax
14796 #endif
14797 cmpl $USER_RPL, %eax
14798 +
14799 +#ifdef CONFIG_PAX_KERNEXEC
14800 + jae resume_userspace
14801 +
14802 + PAX_EXIT_KERNEL
14803 + jmp resume_kernel
14804 +#else
14805 jb resume_kernel # not returning to v8086 or userspace
14806 +#endif
14807
14808 ENTRY(resume_userspace)
14809 LOCKDEP_SYS_EXIT
14810 @@ -347,8 +497,8 @@ ENTRY(resume_userspace)
14811 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
14812 # int/exception return?
14813 jne work_pending
14814 - jmp restore_all
14815 -END(ret_from_exception)
14816 + jmp restore_all_pax
14817 +ENDPROC(ret_from_exception)
14818
14819 #ifdef CONFIG_PREEMPT
14820 ENTRY(resume_kernel)
14821 @@ -363,7 +513,7 @@ need_resched:
14822 jz restore_all
14823 call preempt_schedule_irq
14824 jmp need_resched
14825 -END(resume_kernel)
14826 +ENDPROC(resume_kernel)
14827 #endif
14828 CFI_ENDPROC
14829 /*
14830 @@ -397,23 +547,34 @@ sysenter_past_esp:
14831 /*CFI_REL_OFFSET cs, 0*/
14832 /*
14833 * Push current_thread_info()->sysenter_return to the stack.
14834 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
14835 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
14836 */
14837 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
14838 + pushl_cfi $0
14839 CFI_REL_OFFSET eip, 0
14840
14841 pushl_cfi %eax
14842 SAVE_ALL
14843 + GET_THREAD_INFO(%ebp)
14844 + movl TI_sysenter_return(%ebp),%ebp
14845 + movl %ebp,PT_EIP(%esp)
14846 ENABLE_INTERRUPTS(CLBR_NONE)
14847
14848 /*
14849 * Load the potential sixth argument from user stack.
14850 * Careful about security.
14851 */
14852 + movl PT_OLDESP(%esp),%ebp
14853 +
14854 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14855 + mov PT_OLDSS(%esp),%ds
14856 +1: movl %ds:(%ebp),%ebp
14857 + push %ss
14858 + pop %ds
14859 +#else
14860 cmpl $__PAGE_OFFSET-3,%ebp
14861 jae syscall_fault
14862 1: movl (%ebp),%ebp
14863 +#endif
14864 +
14865 movl %ebp,PT_EBP(%esp)
14866 .section __ex_table,"a"
14867 .align 4
14868 @@ -436,12 +597,24 @@ sysenter_do_call:
14869 testl $_TIF_ALLWORK_MASK, %ecx
14870 jne sysexit_audit
14871 sysenter_exit:
14872 +
14873 +#ifdef CONFIG_PAX_RANDKSTACK
14874 + pushl_cfi %eax
14875 + movl %esp, %eax
14876 + call pax_randomize_kstack
14877 + popl_cfi %eax
14878 +#endif
14879 +
14880 + pax_erase_kstack
14881 +
14882 /* if something modifies registers it must also disable sysexit */
14883 movl PT_EIP(%esp), %edx
14884 movl PT_OLDESP(%esp), %ecx
14885 xorl %ebp,%ebp
14886 TRACE_IRQS_ON
14887 1: mov PT_FS(%esp), %fs
14888 +2: mov PT_DS(%esp), %ds
14889 +3: mov PT_ES(%esp), %es
14890 PTGS_TO_GS
14891 ENABLE_INTERRUPTS_SYSEXIT
14892
14893 @@ -458,6 +631,9 @@ sysenter_audit:
14894 movl %eax,%edx /* 2nd arg: syscall number */
14895 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
14896 call __audit_syscall_entry
14897 +
14898 + pax_erase_kstack
14899 +
14900 pushl_cfi %ebx
14901 movl PT_EAX(%esp),%eax /* reload syscall number */
14902 jmp sysenter_do_call
14903 @@ -483,11 +659,17 @@ sysexit_audit:
14904
14905 CFI_ENDPROC
14906 .pushsection .fixup,"ax"
14907 -2: movl $0,PT_FS(%esp)
14908 +4: movl $0,PT_FS(%esp)
14909 + jmp 1b
14910 +5: movl $0,PT_DS(%esp)
14911 + jmp 1b
14912 +6: movl $0,PT_ES(%esp)
14913 jmp 1b
14914 .section __ex_table,"a"
14915 .align 4
14916 - .long 1b,2b
14917 + .long 1b,4b
14918 + .long 2b,5b
14919 + .long 3b,6b
14920 .popsection
14921 PTGS_TO_GS_EX
14922 ENDPROC(ia32_sysenter_target)
14923 @@ -520,6 +702,15 @@ syscall_exit:
14924 testl $_TIF_ALLWORK_MASK, %ecx # current->work
14925 jne syscall_exit_work
14926
14927 +restore_all_pax:
14928 +
14929 +#ifdef CONFIG_PAX_RANDKSTACK
14930 + movl %esp, %eax
14931 + call pax_randomize_kstack
14932 +#endif
14933 +
14934 + pax_erase_kstack
14935 +
14936 restore_all:
14937 TRACE_IRQS_IRET
14938 restore_all_notrace:
14939 @@ -579,14 +770,34 @@ ldt_ss:
14940 * compensating for the offset by changing to the ESPFIX segment with
14941 * a base address that matches for the difference.
14942 */
14943 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
14944 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
14945 mov %esp, %edx /* load kernel esp */
14946 mov PT_OLDESP(%esp), %eax /* load userspace esp */
14947 mov %dx, %ax /* eax: new kernel esp */
14948 sub %eax, %edx /* offset (low word is 0) */
14949 +#ifdef CONFIG_SMP
14950 + movl PER_CPU_VAR(cpu_number), %ebx
14951 + shll $PAGE_SHIFT_asm, %ebx
14952 + addl $cpu_gdt_table, %ebx
14953 +#else
14954 + movl $cpu_gdt_table, %ebx
14955 +#endif
14956 shr $16, %edx
14957 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
14958 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
14959 +
14960 +#ifdef CONFIG_PAX_KERNEXEC
14961 + mov %cr0, %esi
14962 + btr $16, %esi
14963 + mov %esi, %cr0
14964 +#endif
14965 +
14966 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
14967 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
14968 +
14969 +#ifdef CONFIG_PAX_KERNEXEC
14970 + bts $16, %esi
14971 + mov %esi, %cr0
14972 +#endif
14973 +
14974 pushl_cfi $__ESPFIX_SS
14975 pushl_cfi %eax /* new kernel esp */
14976 /* Disable interrupts, but do not irqtrace this section: we
14977 @@ -615,38 +826,30 @@ work_resched:
14978 movl TI_flags(%ebp), %ecx
14979 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
14980 # than syscall tracing?
14981 - jz restore_all
14982 + jz restore_all_pax
14983 testb $_TIF_NEED_RESCHED, %cl
14984 jnz work_resched
14985
14986 work_notifysig: # deal with pending signals and
14987 # notify-resume requests
14988 + movl %esp, %eax
14989 #ifdef CONFIG_VM86
14990 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
14991 - movl %esp, %eax
14992 - jne work_notifysig_v86 # returning to kernel-space or
14993 + jz 1f # returning to kernel-space or
14994 # vm86-space
14995 - TRACE_IRQS_ON
14996 - ENABLE_INTERRUPTS(CLBR_NONE)
14997 - xorl %edx, %edx
14998 - call do_notify_resume
14999 - jmp resume_userspace_sig
15000
15001 - ALIGN
15002 -work_notifysig_v86:
15003 pushl_cfi %ecx # save ti_flags for do_notify_resume
15004 call save_v86_state # %eax contains pt_regs pointer
15005 popl_cfi %ecx
15006 movl %eax, %esp
15007 -#else
15008 - movl %esp, %eax
15009 +1:
15010 #endif
15011 TRACE_IRQS_ON
15012 ENABLE_INTERRUPTS(CLBR_NONE)
15013 xorl %edx, %edx
15014 call do_notify_resume
15015 jmp resume_userspace_sig
15016 -END(work_pending)
15017 +ENDPROC(work_pending)
15018
15019 # perform syscall exit tracing
15020 ALIGN
15021 @@ -654,11 +857,14 @@ syscall_trace_entry:
15022 movl $-ENOSYS,PT_EAX(%esp)
15023 movl %esp, %eax
15024 call syscall_trace_enter
15025 +
15026 + pax_erase_kstack
15027 +
15028 /* What it returned is what we'll actually use. */
15029 cmpl $(NR_syscalls), %eax
15030 jnae syscall_call
15031 jmp syscall_exit
15032 -END(syscall_trace_entry)
15033 +ENDPROC(syscall_trace_entry)
15034
15035 # perform syscall exit tracing
15036 ALIGN
15037 @@ -671,20 +877,24 @@ syscall_exit_work:
15038 movl %esp, %eax
15039 call syscall_trace_leave
15040 jmp resume_userspace
15041 -END(syscall_exit_work)
15042 +ENDPROC(syscall_exit_work)
15043 CFI_ENDPROC
15044
15045 RING0_INT_FRAME # can't unwind into user space anyway
15046 syscall_fault:
15047 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15048 + push %ss
15049 + pop %ds
15050 +#endif
15051 GET_THREAD_INFO(%ebp)
15052 movl $-EFAULT,PT_EAX(%esp)
15053 jmp resume_userspace
15054 -END(syscall_fault)
15055 +ENDPROC(syscall_fault)
15056
15057 syscall_badsys:
15058 movl $-ENOSYS,PT_EAX(%esp)
15059 jmp resume_userspace
15060 -END(syscall_badsys)
15061 +ENDPROC(syscall_badsys)
15062 CFI_ENDPROC
15063 /*
15064 * End of kprobes section
15065 @@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
15066 CFI_ENDPROC
15067 ENDPROC(ptregs_clone)
15068
15069 + ALIGN;
15070 +ENTRY(kernel_execve)
15071 + CFI_STARTPROC
15072 + pushl_cfi %ebp
15073 + sub $PT_OLDSS+4,%esp
15074 + pushl_cfi %edi
15075 + pushl_cfi %ecx
15076 + pushl_cfi %eax
15077 + lea 3*4(%esp),%edi
15078 + mov $PT_OLDSS/4+1,%ecx
15079 + xorl %eax,%eax
15080 + rep stosl
15081 + popl_cfi %eax
15082 + popl_cfi %ecx
15083 + popl_cfi %edi
15084 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15085 + pushl_cfi %esp
15086 + call sys_execve
15087 + add $4,%esp
15088 + CFI_ADJUST_CFA_OFFSET -4
15089 + GET_THREAD_INFO(%ebp)
15090 + test %eax,%eax
15091 + jz syscall_exit
15092 + add $PT_OLDSS+4,%esp
15093 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15094 + popl_cfi %ebp
15095 + ret
15096 + CFI_ENDPROC
15097 +ENDPROC(kernel_execve)
15098 +
15099 .macro FIXUP_ESPFIX_STACK
15100 /*
15101 * Switch back for ESPFIX stack to the normal zerobased stack
15102 @@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
15103 * normal stack and adjusts ESP with the matching offset.
15104 */
15105 /* fixup the stack */
15106 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15107 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15108 +#ifdef CONFIG_SMP
15109 + movl PER_CPU_VAR(cpu_number), %ebx
15110 + shll $PAGE_SHIFT_asm, %ebx
15111 + addl $cpu_gdt_table, %ebx
15112 +#else
15113 + movl $cpu_gdt_table, %ebx
15114 +#endif
15115 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15116 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15117 shl $16, %eax
15118 addl %esp, %eax /* the adjusted stack pointer */
15119 pushl_cfi $__KERNEL_DS
15120 @@ -819,7 +1066,7 @@ vector=vector+1
15121 .endr
15122 2: jmp common_interrupt
15123 .endr
15124 -END(irq_entries_start)
15125 +ENDPROC(irq_entries_start)
15126
15127 .previous
15128 END(interrupt)
15129 @@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
15130 pushl_cfi $do_coprocessor_error
15131 jmp error_code
15132 CFI_ENDPROC
15133 -END(coprocessor_error)
15134 +ENDPROC(coprocessor_error)
15135
15136 ENTRY(simd_coprocessor_error)
15137 RING0_INT_FRAME
15138 @@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
15139 #endif
15140 jmp error_code
15141 CFI_ENDPROC
15142 -END(simd_coprocessor_error)
15143 +ENDPROC(simd_coprocessor_error)
15144
15145 ENTRY(device_not_available)
15146 RING0_INT_FRAME
15147 @@ -896,7 +1143,7 @@ ENTRY(device_not_available)
15148 pushl_cfi $do_device_not_available
15149 jmp error_code
15150 CFI_ENDPROC
15151 -END(device_not_available)
15152 +ENDPROC(device_not_available)
15153
15154 #ifdef CONFIG_PARAVIRT
15155 ENTRY(native_iret)
15156 @@ -905,12 +1152,12 @@ ENTRY(native_iret)
15157 .align 4
15158 .long native_iret, iret_exc
15159 .previous
15160 -END(native_iret)
15161 +ENDPROC(native_iret)
15162
15163 ENTRY(native_irq_enable_sysexit)
15164 sti
15165 sysexit
15166 -END(native_irq_enable_sysexit)
15167 +ENDPROC(native_irq_enable_sysexit)
15168 #endif
15169
15170 ENTRY(overflow)
15171 @@ -919,7 +1166,7 @@ ENTRY(overflow)
15172 pushl_cfi $do_overflow
15173 jmp error_code
15174 CFI_ENDPROC
15175 -END(overflow)
15176 +ENDPROC(overflow)
15177
15178 ENTRY(bounds)
15179 RING0_INT_FRAME
15180 @@ -927,7 +1174,7 @@ ENTRY(bounds)
15181 pushl_cfi $do_bounds
15182 jmp error_code
15183 CFI_ENDPROC
15184 -END(bounds)
15185 +ENDPROC(bounds)
15186
15187 ENTRY(invalid_op)
15188 RING0_INT_FRAME
15189 @@ -935,7 +1182,7 @@ ENTRY(invalid_op)
15190 pushl_cfi $do_invalid_op
15191 jmp error_code
15192 CFI_ENDPROC
15193 -END(invalid_op)
15194 +ENDPROC(invalid_op)
15195
15196 ENTRY(coprocessor_segment_overrun)
15197 RING0_INT_FRAME
15198 @@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
15199 pushl_cfi $do_coprocessor_segment_overrun
15200 jmp error_code
15201 CFI_ENDPROC
15202 -END(coprocessor_segment_overrun)
15203 +ENDPROC(coprocessor_segment_overrun)
15204
15205 ENTRY(invalid_TSS)
15206 RING0_EC_FRAME
15207 pushl_cfi $do_invalid_TSS
15208 jmp error_code
15209 CFI_ENDPROC
15210 -END(invalid_TSS)
15211 +ENDPROC(invalid_TSS)
15212
15213 ENTRY(segment_not_present)
15214 RING0_EC_FRAME
15215 pushl_cfi $do_segment_not_present
15216 jmp error_code
15217 CFI_ENDPROC
15218 -END(segment_not_present)
15219 +ENDPROC(segment_not_present)
15220
15221 ENTRY(stack_segment)
15222 RING0_EC_FRAME
15223 pushl_cfi $do_stack_segment
15224 jmp error_code
15225 CFI_ENDPROC
15226 -END(stack_segment)
15227 +ENDPROC(stack_segment)
15228
15229 ENTRY(alignment_check)
15230 RING0_EC_FRAME
15231 pushl_cfi $do_alignment_check
15232 jmp error_code
15233 CFI_ENDPROC
15234 -END(alignment_check)
15235 +ENDPROC(alignment_check)
15236
15237 ENTRY(divide_error)
15238 RING0_INT_FRAME
15239 @@ -979,7 +1226,7 @@ ENTRY(divide_error)
15240 pushl_cfi $do_divide_error
15241 jmp error_code
15242 CFI_ENDPROC
15243 -END(divide_error)
15244 +ENDPROC(divide_error)
15245
15246 #ifdef CONFIG_X86_MCE
15247 ENTRY(machine_check)
15248 @@ -988,7 +1235,7 @@ ENTRY(machine_check)
15249 pushl_cfi machine_check_vector
15250 jmp error_code
15251 CFI_ENDPROC
15252 -END(machine_check)
15253 +ENDPROC(machine_check)
15254 #endif
15255
15256 ENTRY(spurious_interrupt_bug)
15257 @@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15258 pushl_cfi $do_spurious_interrupt_bug
15259 jmp error_code
15260 CFI_ENDPROC
15261 -END(spurious_interrupt_bug)
15262 +ENDPROC(spurious_interrupt_bug)
15263 /*
15264 * End of kprobes section
15265 */
15266 @@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15267
15268 ENTRY(mcount)
15269 ret
15270 -END(mcount)
15271 +ENDPROC(mcount)
15272
15273 ENTRY(ftrace_caller)
15274 cmpl $0, function_trace_stop
15275 @@ -1141,7 +1388,7 @@ ftrace_graph_call:
15276 .globl ftrace_stub
15277 ftrace_stub:
15278 ret
15279 -END(ftrace_caller)
15280 +ENDPROC(ftrace_caller)
15281
15282 #else /* ! CONFIG_DYNAMIC_FTRACE */
15283
15284 @@ -1177,7 +1424,7 @@ trace:
15285 popl %ecx
15286 popl %eax
15287 jmp ftrace_stub
15288 -END(mcount)
15289 +ENDPROC(mcount)
15290 #endif /* CONFIG_DYNAMIC_FTRACE */
15291 #endif /* CONFIG_FUNCTION_TRACER */
15292
15293 @@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15294 popl %ecx
15295 popl %eax
15296 ret
15297 -END(ftrace_graph_caller)
15298 +ENDPROC(ftrace_graph_caller)
15299
15300 .globl return_to_handler
15301 return_to_handler:
15302 @@ -1253,15 +1500,18 @@ error_code:
15303 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15304 REG_TO_PTGS %ecx
15305 SET_KERNEL_GS %ecx
15306 - movl $(__USER_DS), %ecx
15307 + movl $(__KERNEL_DS), %ecx
15308 movl %ecx, %ds
15309 movl %ecx, %es
15310 +
15311 + pax_enter_kernel
15312 +
15313 TRACE_IRQS_OFF
15314 movl %esp,%eax # pt_regs pointer
15315 call *%edi
15316 jmp ret_from_exception
15317 CFI_ENDPROC
15318 -END(page_fault)
15319 +ENDPROC(page_fault)
15320
15321 /*
15322 * Debug traps and NMI can happen at the one SYSENTER instruction
15323 @@ -1303,7 +1553,7 @@ debug_stack_correct:
15324 call do_debug
15325 jmp ret_from_exception
15326 CFI_ENDPROC
15327 -END(debug)
15328 +ENDPROC(debug)
15329
15330 /*
15331 * NMI is doubly nasty. It can happen _while_ we're handling
15332 @@ -1340,6 +1590,9 @@ nmi_stack_correct:
15333 xorl %edx,%edx # zero error code
15334 movl %esp,%eax # pt_regs pointer
15335 call do_nmi
15336 +
15337 + pax_exit_kernel
15338 +
15339 jmp restore_all_notrace
15340 CFI_ENDPROC
15341
15342 @@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15343 FIXUP_ESPFIX_STACK # %eax == %esp
15344 xorl %edx,%edx # zero error code
15345 call do_nmi
15346 +
15347 + pax_exit_kernel
15348 +
15349 RESTORE_REGS
15350 lss 12+4(%esp), %esp # back to espfix stack
15351 CFI_ADJUST_CFA_OFFSET -24
15352 jmp irq_return
15353 CFI_ENDPROC
15354 -END(nmi)
15355 +ENDPROC(nmi)
15356
15357 ENTRY(int3)
15358 RING0_INT_FRAME
15359 @@ -1393,14 +1649,14 @@ ENTRY(int3)
15360 call do_int3
15361 jmp ret_from_exception
15362 CFI_ENDPROC
15363 -END(int3)
15364 +ENDPROC(int3)
15365
15366 ENTRY(general_protection)
15367 RING0_EC_FRAME
15368 pushl_cfi $do_general_protection
15369 jmp error_code
15370 CFI_ENDPROC
15371 -END(general_protection)
15372 +ENDPROC(general_protection)
15373
15374 #ifdef CONFIG_KVM_GUEST
15375 ENTRY(async_page_fault)
15376 @@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15377 pushl_cfi $do_async_page_fault
15378 jmp error_code
15379 CFI_ENDPROC
15380 -END(async_page_fault)
15381 +ENDPROC(async_page_fault)
15382 #endif
15383
15384 /*
15385 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15386 index 1333d98..b340ca2 100644
15387 --- a/arch/x86/kernel/entry_64.S
15388 +++ b/arch/x86/kernel/entry_64.S
15389 @@ -56,6 +56,8 @@
15390 #include <asm/ftrace.h>
15391 #include <asm/percpu.h>
15392 #include <linux/err.h>
15393 +#include <asm/pgtable.h>
15394 +#include <asm/alternative-asm.h>
15395
15396 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15397 #include <linux/elf-em.h>
15398 @@ -69,8 +71,9 @@
15399 #ifdef CONFIG_FUNCTION_TRACER
15400 #ifdef CONFIG_DYNAMIC_FTRACE
15401 ENTRY(mcount)
15402 + pax_force_retaddr
15403 retq
15404 -END(mcount)
15405 +ENDPROC(mcount)
15406
15407 ENTRY(ftrace_caller)
15408 cmpl $0, function_trace_stop
15409 @@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15410 #endif
15411
15412 GLOBAL(ftrace_stub)
15413 + pax_force_retaddr
15414 retq
15415 -END(ftrace_caller)
15416 +ENDPROC(ftrace_caller)
15417
15418 #else /* ! CONFIG_DYNAMIC_FTRACE */
15419 ENTRY(mcount)
15420 @@ -113,6 +117,7 @@ ENTRY(mcount)
15421 #endif
15422
15423 GLOBAL(ftrace_stub)
15424 + pax_force_retaddr
15425 retq
15426
15427 trace:
15428 @@ -122,12 +127,13 @@ trace:
15429 movq 8(%rbp), %rsi
15430 subq $MCOUNT_INSN_SIZE, %rdi
15431
15432 + pax_force_fptr ftrace_trace_function
15433 call *ftrace_trace_function
15434
15435 MCOUNT_RESTORE_FRAME
15436
15437 jmp ftrace_stub
15438 -END(mcount)
15439 +ENDPROC(mcount)
15440 #endif /* CONFIG_DYNAMIC_FTRACE */
15441 #endif /* CONFIG_FUNCTION_TRACER */
15442
15443 @@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15444
15445 MCOUNT_RESTORE_FRAME
15446
15447 + pax_force_retaddr
15448 retq
15449 -END(ftrace_graph_caller)
15450 +ENDPROC(ftrace_graph_caller)
15451
15452 GLOBAL(return_to_handler)
15453 subq $24, %rsp
15454 @@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15455 movq 8(%rsp), %rdx
15456 movq (%rsp), %rax
15457 addq $24, %rsp
15458 + pax_force_fptr %rdi
15459 jmp *%rdi
15460 #endif
15461
15462 @@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15463 ENDPROC(native_usergs_sysret64)
15464 #endif /* CONFIG_PARAVIRT */
15465
15466 + .macro ljmpq sel, off
15467 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15468 + .byte 0x48; ljmp *1234f(%rip)
15469 + .pushsection .rodata
15470 + .align 16
15471 + 1234: .quad \off; .word \sel
15472 + .popsection
15473 +#else
15474 + pushq $\sel
15475 + pushq $\off
15476 + lretq
15477 +#endif
15478 + .endm
15479 +
15480 + .macro pax_enter_kernel
15481 + pax_set_fptr_mask
15482 +#ifdef CONFIG_PAX_KERNEXEC
15483 + call pax_enter_kernel
15484 +#endif
15485 + .endm
15486 +
15487 + .macro pax_exit_kernel
15488 +#ifdef CONFIG_PAX_KERNEXEC
15489 + call pax_exit_kernel
15490 +#endif
15491 + .endm
15492 +
15493 +#ifdef CONFIG_PAX_KERNEXEC
15494 +ENTRY(pax_enter_kernel)
15495 + pushq %rdi
15496 +
15497 +#ifdef CONFIG_PARAVIRT
15498 + PV_SAVE_REGS(CLBR_RDI)
15499 +#endif
15500 +
15501 + GET_CR0_INTO_RDI
15502 + bts $16,%rdi
15503 + jnc 3f
15504 + mov %cs,%edi
15505 + cmp $__KERNEL_CS,%edi
15506 + jnz 2f
15507 +1:
15508 +
15509 +#ifdef CONFIG_PARAVIRT
15510 + PV_RESTORE_REGS(CLBR_RDI)
15511 +#endif
15512 +
15513 + popq %rdi
15514 + pax_force_retaddr
15515 + retq
15516 +
15517 +2: ljmpq __KERNEL_CS,1f
15518 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15519 +4: SET_RDI_INTO_CR0
15520 + jmp 1b
15521 +ENDPROC(pax_enter_kernel)
15522 +
15523 +ENTRY(pax_exit_kernel)
15524 + pushq %rdi
15525 +
15526 +#ifdef CONFIG_PARAVIRT
15527 + PV_SAVE_REGS(CLBR_RDI)
15528 +#endif
15529 +
15530 + mov %cs,%rdi
15531 + cmp $__KERNEXEC_KERNEL_CS,%edi
15532 + jz 2f
15533 +1:
15534 +
15535 +#ifdef CONFIG_PARAVIRT
15536 + PV_RESTORE_REGS(CLBR_RDI);
15537 +#endif
15538 +
15539 + popq %rdi
15540 + pax_force_retaddr
15541 + retq
15542 +
15543 +2: GET_CR0_INTO_RDI
15544 + btr $16,%rdi
15545 + ljmpq __KERNEL_CS,3f
15546 +3: SET_RDI_INTO_CR0
15547 + jmp 1b
15548 +#ifdef CONFIG_PARAVIRT
15549 + PV_RESTORE_REGS(CLBR_RDI);
15550 +#endif
15551 +
15552 + popq %rdi
15553 + pax_force_retaddr
15554 + retq
15555 +ENDPROC(pax_exit_kernel)
15556 +#endif
15557 +
15558 + .macro pax_enter_kernel_user
15559 + pax_set_fptr_mask
15560 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15561 + call pax_enter_kernel_user
15562 +#endif
15563 + .endm
15564 +
15565 + .macro pax_exit_kernel_user
15566 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15567 + call pax_exit_kernel_user
15568 +#endif
15569 +#ifdef CONFIG_PAX_RANDKSTACK
15570 + pushq %rax
15571 + call pax_randomize_kstack
15572 + popq %rax
15573 +#endif
15574 + .endm
15575 +
15576 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15577 +ENTRY(pax_enter_kernel_user)
15578 + pushq %rdi
15579 + pushq %rbx
15580 +
15581 +#ifdef CONFIG_PARAVIRT
15582 + PV_SAVE_REGS(CLBR_RDI)
15583 +#endif
15584 +
15585 + GET_CR3_INTO_RDI
15586 + mov %rdi,%rbx
15587 + add $__START_KERNEL_map,%rbx
15588 + sub phys_base(%rip),%rbx
15589 +
15590 +#ifdef CONFIG_PARAVIRT
15591 + pushq %rdi
15592 + cmpl $0, pv_info+PARAVIRT_enabled
15593 + jz 1f
15594 + i = 0
15595 + .rept USER_PGD_PTRS
15596 + mov i*8(%rbx),%rsi
15597 + mov $0,%sil
15598 + lea i*8(%rbx),%rdi
15599 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15600 + i = i + 1
15601 + .endr
15602 + jmp 2f
15603 +1:
15604 +#endif
15605 +
15606 + i = 0
15607 + .rept USER_PGD_PTRS
15608 + movb $0,i*8(%rbx)
15609 + i = i + 1
15610 + .endr
15611 +
15612 +#ifdef CONFIG_PARAVIRT
15613 +2: popq %rdi
15614 +#endif
15615 + SET_RDI_INTO_CR3
15616 +
15617 +#ifdef CONFIG_PAX_KERNEXEC
15618 + GET_CR0_INTO_RDI
15619 + bts $16,%rdi
15620 + SET_RDI_INTO_CR0
15621 +#endif
15622 +
15623 +#ifdef CONFIG_PARAVIRT
15624 + PV_RESTORE_REGS(CLBR_RDI)
15625 +#endif
15626 +
15627 + popq %rbx
15628 + popq %rdi
15629 + pax_force_retaddr
15630 + retq
15631 +ENDPROC(pax_enter_kernel_user)
15632 +
15633 +ENTRY(pax_exit_kernel_user)
15634 + push %rdi
15635 +
15636 +#ifdef CONFIG_PARAVIRT
15637 + pushq %rbx
15638 + PV_SAVE_REGS(CLBR_RDI)
15639 +#endif
15640 +
15641 +#ifdef CONFIG_PAX_KERNEXEC
15642 + GET_CR0_INTO_RDI
15643 + btr $16,%rdi
15644 + SET_RDI_INTO_CR0
15645 +#endif
15646 +
15647 + GET_CR3_INTO_RDI
15648 + add $__START_KERNEL_map,%rdi
15649 + sub phys_base(%rip),%rdi
15650 +
15651 +#ifdef CONFIG_PARAVIRT
15652 + cmpl $0, pv_info+PARAVIRT_enabled
15653 + jz 1f
15654 + mov %rdi,%rbx
15655 + i = 0
15656 + .rept USER_PGD_PTRS
15657 + mov i*8(%rbx),%rsi
15658 + mov $0x67,%sil
15659 + lea i*8(%rbx),%rdi
15660 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15661 + i = i + 1
15662 + .endr
15663 + jmp 2f
15664 +1:
15665 +#endif
15666 +
15667 + i = 0
15668 + .rept USER_PGD_PTRS
15669 + movb $0x67,i*8(%rdi)
15670 + i = i + 1
15671 + .endr
15672 +
15673 +#ifdef CONFIG_PARAVIRT
15674 +2: PV_RESTORE_REGS(CLBR_RDI)
15675 + popq %rbx
15676 +#endif
15677 +
15678 + popq %rdi
15679 + pax_force_retaddr
15680 + retq
15681 +ENDPROC(pax_exit_kernel_user)
15682 +#endif
15683 +
15684 +.macro pax_erase_kstack
15685 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15686 + call pax_erase_kstack
15687 +#endif
15688 +.endm
15689 +
15690 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15691 +/*
15692 + * r11: thread_info
15693 + * rcx, rdx: can be clobbered
15694 + */
15695 +ENTRY(pax_erase_kstack)
15696 + pushq %rdi
15697 + pushq %rax
15698 + pushq %r11
15699 +
15700 + GET_THREAD_INFO(%r11)
15701 + mov TI_lowest_stack(%r11), %rdi
15702 + mov $-0xBEEF, %rax
15703 + std
15704 +
15705 +1: mov %edi, %ecx
15706 + and $THREAD_SIZE_asm - 1, %ecx
15707 + shr $3, %ecx
15708 + repne scasq
15709 + jecxz 2f
15710 +
15711 + cmp $2*8, %ecx
15712 + jc 2f
15713 +
15714 + mov $2*8, %ecx
15715 + repe scasq
15716 + jecxz 2f
15717 + jne 1b
15718 +
15719 +2: cld
15720 + mov %esp, %ecx
15721 + sub %edi, %ecx
15722 +
15723 + cmp $THREAD_SIZE_asm, %rcx
15724 + jb 3f
15725 + ud2
15726 +3:
15727 +
15728 + shr $3, %ecx
15729 + rep stosq
15730 +
15731 + mov TI_task_thread_sp0(%r11), %rdi
15732 + sub $256, %rdi
15733 + mov %rdi, TI_lowest_stack(%r11)
15734 +
15735 + popq %r11
15736 + popq %rax
15737 + popq %rdi
15738 + pax_force_retaddr
15739 + ret
15740 +ENDPROC(pax_erase_kstack)
15741 +#endif
15742
15743 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15744 #ifdef CONFIG_TRACE_IRQFLAGS
15745 @@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
15746 .endm
15747
15748 .macro UNFAKE_STACK_FRAME
15749 - addq $8*6, %rsp
15750 - CFI_ADJUST_CFA_OFFSET -(6*8)
15751 + addq $8*6 + ARG_SKIP, %rsp
15752 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15753 .endm
15754
15755 /*
15756 @@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
15757 movq %rsp, %rsi
15758
15759 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15760 - testl $3, CS(%rdi)
15761 + testb $3, CS(%rdi)
15762 je 1f
15763 SWAPGS
15764 /*
15765 @@ -356,9 +640,10 @@ ENTRY(save_rest)
15766 movq_cfi r15, R15+16
15767 movq %r11, 8(%rsp) /* return address */
15768 FIXUP_TOP_OF_STACK %r11, 16
15769 + pax_force_retaddr
15770 ret
15771 CFI_ENDPROC
15772 -END(save_rest)
15773 +ENDPROC(save_rest)
15774
15775 /* save complete stack frame */
15776 .pushsection .kprobes.text, "ax"
15777 @@ -387,9 +672,10 @@ ENTRY(save_paranoid)
15778 js 1f /* negative -> in kernel */
15779 SWAPGS
15780 xorl %ebx,%ebx
15781 -1: ret
15782 +1: pax_force_retaddr_bts
15783 + ret
15784 CFI_ENDPROC
15785 -END(save_paranoid)
15786 +ENDPROC(save_paranoid)
15787 .popsection
15788
15789 /*
15790 @@ -411,7 +697,7 @@ ENTRY(ret_from_fork)
15791
15792 RESTORE_REST
15793
15794 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15795 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15796 jz retint_restore_args
15797
15798 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
15799 @@ -421,7 +707,7 @@ ENTRY(ret_from_fork)
15800 jmp ret_from_sys_call # go to the SYSRET fastpath
15801
15802 CFI_ENDPROC
15803 -END(ret_from_fork)
15804 +ENDPROC(ret_from_fork)
15805
15806 /*
15807 * System call entry. Up to 6 arguments in registers are supported.
15808 @@ -457,7 +743,7 @@ END(ret_from_fork)
15809 ENTRY(system_call)
15810 CFI_STARTPROC simple
15811 CFI_SIGNAL_FRAME
15812 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15813 + CFI_DEF_CFA rsp,0
15814 CFI_REGISTER rip,rcx
15815 /*CFI_REGISTER rflags,r11*/
15816 SWAPGS_UNSAFE_STACK
15817 @@ -470,21 +756,23 @@ GLOBAL(system_call_after_swapgs)
15818
15819 movq %rsp,PER_CPU_VAR(old_rsp)
15820 movq PER_CPU_VAR(kernel_stack),%rsp
15821 + SAVE_ARGS 8*6,0
15822 + pax_enter_kernel_user
15823 /*
15824 * No need to follow this irqs off/on section - it's straight
15825 * and short:
15826 */
15827 ENABLE_INTERRUPTS(CLBR_NONE)
15828 - SAVE_ARGS 8,0
15829 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15830 movq %rcx,RIP-ARGOFFSET(%rsp)
15831 CFI_REL_OFFSET rip,RIP-ARGOFFSET
15832 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15833 + GET_THREAD_INFO(%rcx)
15834 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
15835 jnz tracesys
15836 system_call_fastpath:
15837 cmpq $__NR_syscall_max,%rax
15838 ja badsys
15839 - movq %r10,%rcx
15840 + movq R10-ARGOFFSET(%rsp),%rcx
15841 call *sys_call_table(,%rax,8) # XXX: rip relative
15842 movq %rax,RAX-ARGOFFSET(%rsp)
15843 /*
15844 @@ -498,10 +786,13 @@ sysret_check:
15845 LOCKDEP_SYS_EXIT
15846 DISABLE_INTERRUPTS(CLBR_NONE)
15847 TRACE_IRQS_OFF
15848 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
15849 + GET_THREAD_INFO(%rcx)
15850 + movl TI_flags(%rcx),%edx
15851 andl %edi,%edx
15852 jnz sysret_careful
15853 CFI_REMEMBER_STATE
15854 + pax_exit_kernel_user
15855 + pax_erase_kstack
15856 /*
15857 * sysretq will re-enable interrupts:
15858 */
15859 @@ -553,14 +844,18 @@ badsys:
15860 * jump back to the normal fast path.
15861 */
15862 auditsys:
15863 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
15864 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
15865 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
15866 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
15867 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
15868 movq %rax,%rsi /* 2nd arg: syscall number */
15869 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
15870 call __audit_syscall_entry
15871 +
15872 + pax_erase_kstack
15873 +
15874 LOAD_ARGS 0 /* reload call-clobbered registers */
15875 + pax_set_fptr_mask
15876 jmp system_call_fastpath
15877
15878 /*
15879 @@ -581,7 +876,7 @@ sysret_audit:
15880 /* Do syscall tracing */
15881 tracesys:
15882 #ifdef CONFIG_AUDITSYSCALL
15883 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15884 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
15885 jz auditsys
15886 #endif
15887 SAVE_REST
15888 @@ -589,16 +884,20 @@ tracesys:
15889 FIXUP_TOP_OF_STACK %rdi
15890 movq %rsp,%rdi
15891 call syscall_trace_enter
15892 +
15893 + pax_erase_kstack
15894 +
15895 /*
15896 * Reload arg registers from stack in case ptrace changed them.
15897 * We don't reload %rax because syscall_trace_enter() returned
15898 * the value it wants us to use in the table lookup.
15899 */
15900 LOAD_ARGS ARGOFFSET, 1
15901 + pax_set_fptr_mask
15902 RESTORE_REST
15903 cmpq $__NR_syscall_max,%rax
15904 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
15905 - movq %r10,%rcx /* fixup for C */
15906 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
15907 call *sys_call_table(,%rax,8)
15908 movq %rax,RAX-ARGOFFSET(%rsp)
15909 /* Use IRET because user could have changed frame */
15910 @@ -619,6 +918,7 @@ GLOBAL(int_with_check)
15911 andl %edi,%edx
15912 jnz int_careful
15913 andl $~TS_COMPAT,TI_status(%rcx)
15914 + pax_erase_kstack
15915 jmp retint_swapgs
15916
15917 /* Either reschedule or signal or syscall exit tracking needed. */
15918 @@ -665,7 +965,7 @@ int_restore_rest:
15919 TRACE_IRQS_OFF
15920 jmp int_with_check
15921 CFI_ENDPROC
15922 -END(system_call)
15923 +ENDPROC(system_call)
15924
15925 /*
15926 * Certain special system calls that need to save a complete full stack frame.
15927 @@ -681,7 +981,7 @@ ENTRY(\label)
15928 call \func
15929 jmp ptregscall_common
15930 CFI_ENDPROC
15931 -END(\label)
15932 +ENDPROC(\label)
15933 .endm
15934
15935 PTREGSCALL stub_clone, sys_clone, %r8
15936 @@ -699,9 +999,10 @@ ENTRY(ptregscall_common)
15937 movq_cfi_restore R12+8, r12
15938 movq_cfi_restore RBP+8, rbp
15939 movq_cfi_restore RBX+8, rbx
15940 + pax_force_retaddr
15941 ret $REST_SKIP /* pop extended registers */
15942 CFI_ENDPROC
15943 -END(ptregscall_common)
15944 +ENDPROC(ptregscall_common)
15945
15946 ENTRY(stub_execve)
15947 CFI_STARTPROC
15948 @@ -716,7 +1017,7 @@ ENTRY(stub_execve)
15949 RESTORE_REST
15950 jmp int_ret_from_sys_call
15951 CFI_ENDPROC
15952 -END(stub_execve)
15953 +ENDPROC(stub_execve)
15954
15955 /*
15956 * sigreturn is special because it needs to restore all registers on return.
15957 @@ -734,7 +1035,7 @@ ENTRY(stub_rt_sigreturn)
15958 RESTORE_REST
15959 jmp int_ret_from_sys_call
15960 CFI_ENDPROC
15961 -END(stub_rt_sigreturn)
15962 +ENDPROC(stub_rt_sigreturn)
15963
15964 /*
15965 * Build the entry stubs and pointer table with some assembler magic.
15966 @@ -769,7 +1070,7 @@ vector=vector+1
15967 2: jmp common_interrupt
15968 .endr
15969 CFI_ENDPROC
15970 -END(irq_entries_start)
15971 +ENDPROC(irq_entries_start)
15972
15973 .previous
15974 END(interrupt)
15975 @@ -789,6 +1090,16 @@ END(interrupt)
15976 subq $ORIG_RAX-RBP, %rsp
15977 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
15978 SAVE_ARGS_IRQ
15979 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15980 + testb $3, CS(%rdi)
15981 + jnz 1f
15982 + pax_enter_kernel
15983 + jmp 2f
15984 +1: pax_enter_kernel_user
15985 +2:
15986 +#else
15987 + pax_enter_kernel
15988 +#endif
15989 call \func
15990 .endm
15991
15992 @@ -820,7 +1131,7 @@ ret_from_intr:
15993
15994 exit_intr:
15995 GET_THREAD_INFO(%rcx)
15996 - testl $3,CS-ARGOFFSET(%rsp)
15997 + testb $3,CS-ARGOFFSET(%rsp)
15998 je retint_kernel
15999
16000 /* Interrupt came from user space */
16001 @@ -842,12 +1153,15 @@ retint_swapgs: /* return to user-space */
16002 * The iretq could re-enable interrupts:
16003 */
16004 DISABLE_INTERRUPTS(CLBR_ANY)
16005 + pax_exit_kernel_user
16006 TRACE_IRQS_IRETQ
16007 SWAPGS
16008 jmp restore_args
16009
16010 retint_restore_args: /* return to kernel space */
16011 DISABLE_INTERRUPTS(CLBR_ANY)
16012 + pax_exit_kernel
16013 + pax_force_retaddr RIP-ARGOFFSET
16014 /*
16015 * The iretq could re-enable interrupts:
16016 */
16017 @@ -936,7 +1250,7 @@ ENTRY(retint_kernel)
16018 #endif
16019
16020 CFI_ENDPROC
16021 -END(common_interrupt)
16022 +ENDPROC(common_interrupt)
16023 /*
16024 * End of kprobes section
16025 */
16026 @@ -953,7 +1267,7 @@ ENTRY(\sym)
16027 interrupt \do_sym
16028 jmp ret_from_intr
16029 CFI_ENDPROC
16030 -END(\sym)
16031 +ENDPROC(\sym)
16032 .endm
16033
16034 #ifdef CONFIG_SMP
16035 @@ -1026,12 +1340,22 @@ ENTRY(\sym)
16036 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16037 call error_entry
16038 DEFAULT_FRAME 0
16039 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16040 + testb $3, CS(%rsp)
16041 + jnz 1f
16042 + pax_enter_kernel
16043 + jmp 2f
16044 +1: pax_enter_kernel_user
16045 +2:
16046 +#else
16047 + pax_enter_kernel
16048 +#endif
16049 movq %rsp,%rdi /* pt_regs pointer */
16050 xorl %esi,%esi /* no error code */
16051 call \do_sym
16052 jmp error_exit /* %ebx: no swapgs flag */
16053 CFI_ENDPROC
16054 -END(\sym)
16055 +ENDPROC(\sym)
16056 .endm
16057
16058 .macro paranoidzeroentry sym do_sym
16059 @@ -1043,15 +1367,25 @@ ENTRY(\sym)
16060 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16061 call save_paranoid
16062 TRACE_IRQS_OFF
16063 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16064 + testb $3, CS(%rsp)
16065 + jnz 1f
16066 + pax_enter_kernel
16067 + jmp 2f
16068 +1: pax_enter_kernel_user
16069 +2:
16070 +#else
16071 + pax_enter_kernel
16072 +#endif
16073 movq %rsp,%rdi /* pt_regs pointer */
16074 xorl %esi,%esi /* no error code */
16075 call \do_sym
16076 jmp paranoid_exit /* %ebx: no swapgs flag */
16077 CFI_ENDPROC
16078 -END(\sym)
16079 +ENDPROC(\sym)
16080 .endm
16081
16082 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16083 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16084 .macro paranoidzeroentry_ist sym do_sym ist
16085 ENTRY(\sym)
16086 INTR_FRAME
16087 @@ -1061,14 +1395,30 @@ ENTRY(\sym)
16088 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16089 call save_paranoid
16090 TRACE_IRQS_OFF
16091 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16092 + testb $3, CS(%rsp)
16093 + jnz 1f
16094 + pax_enter_kernel
16095 + jmp 2f
16096 +1: pax_enter_kernel_user
16097 +2:
16098 +#else
16099 + pax_enter_kernel
16100 +#endif
16101 movq %rsp,%rdi /* pt_regs pointer */
16102 xorl %esi,%esi /* no error code */
16103 +#ifdef CONFIG_SMP
16104 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16105 + lea init_tss(%r12), %r12
16106 +#else
16107 + lea init_tss(%rip), %r12
16108 +#endif
16109 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16110 call \do_sym
16111 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16112 jmp paranoid_exit /* %ebx: no swapgs flag */
16113 CFI_ENDPROC
16114 -END(\sym)
16115 +ENDPROC(\sym)
16116 .endm
16117
16118 .macro errorentry sym do_sym
16119 @@ -1079,13 +1429,23 @@ ENTRY(\sym)
16120 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16121 call error_entry
16122 DEFAULT_FRAME 0
16123 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16124 + testb $3, CS(%rsp)
16125 + jnz 1f
16126 + pax_enter_kernel
16127 + jmp 2f
16128 +1: pax_enter_kernel_user
16129 +2:
16130 +#else
16131 + pax_enter_kernel
16132 +#endif
16133 movq %rsp,%rdi /* pt_regs pointer */
16134 movq ORIG_RAX(%rsp),%rsi /* get error code */
16135 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16136 call \do_sym
16137 jmp error_exit /* %ebx: no swapgs flag */
16138 CFI_ENDPROC
16139 -END(\sym)
16140 +ENDPROC(\sym)
16141 .endm
16142
16143 /* error code is on the stack already */
16144 @@ -1098,13 +1458,23 @@ ENTRY(\sym)
16145 call save_paranoid
16146 DEFAULT_FRAME 0
16147 TRACE_IRQS_OFF
16148 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16149 + testb $3, CS(%rsp)
16150 + jnz 1f
16151 + pax_enter_kernel
16152 + jmp 2f
16153 +1: pax_enter_kernel_user
16154 +2:
16155 +#else
16156 + pax_enter_kernel
16157 +#endif
16158 movq %rsp,%rdi /* pt_regs pointer */
16159 movq ORIG_RAX(%rsp),%rsi /* get error code */
16160 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16161 call \do_sym
16162 jmp paranoid_exit /* %ebx: no swapgs flag */
16163 CFI_ENDPROC
16164 -END(\sym)
16165 +ENDPROC(\sym)
16166 .endm
16167
16168 zeroentry divide_error do_divide_error
16169 @@ -1134,9 +1504,10 @@ gs_change:
16170 2: mfence /* workaround */
16171 SWAPGS
16172 popfq_cfi
16173 + pax_force_retaddr
16174 ret
16175 CFI_ENDPROC
16176 -END(native_load_gs_index)
16177 +ENDPROC(native_load_gs_index)
16178
16179 .section __ex_table,"a"
16180 .align 8
16181 @@ -1158,13 +1529,14 @@ ENTRY(kernel_thread_helper)
16182 * Here we are in the child and the registers are set as they were
16183 * at kernel_thread() invocation in the parent.
16184 */
16185 + pax_force_fptr %rsi
16186 call *%rsi
16187 # exit
16188 mov %eax, %edi
16189 call do_exit
16190 ud2 # padding for call trace
16191 CFI_ENDPROC
16192 -END(kernel_thread_helper)
16193 +ENDPROC(kernel_thread_helper)
16194
16195 /*
16196 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16197 @@ -1191,11 +1563,11 @@ ENTRY(kernel_execve)
16198 RESTORE_REST
16199 testq %rax,%rax
16200 je int_ret_from_sys_call
16201 - RESTORE_ARGS
16202 UNFAKE_STACK_FRAME
16203 + pax_force_retaddr
16204 ret
16205 CFI_ENDPROC
16206 -END(kernel_execve)
16207 +ENDPROC(kernel_execve)
16208
16209 /* Call softirq on interrupt stack. Interrupts are off. */
16210 ENTRY(call_softirq)
16211 @@ -1213,9 +1585,10 @@ ENTRY(call_softirq)
16212 CFI_DEF_CFA_REGISTER rsp
16213 CFI_ADJUST_CFA_OFFSET -8
16214 decl PER_CPU_VAR(irq_count)
16215 + pax_force_retaddr
16216 ret
16217 CFI_ENDPROC
16218 -END(call_softirq)
16219 +ENDPROC(call_softirq)
16220
16221 #ifdef CONFIG_XEN
16222 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16223 @@ -1253,7 +1626,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16224 decl PER_CPU_VAR(irq_count)
16225 jmp error_exit
16226 CFI_ENDPROC
16227 -END(xen_do_hypervisor_callback)
16228 +ENDPROC(xen_do_hypervisor_callback)
16229
16230 /*
16231 * Hypervisor uses this for application faults while it executes.
16232 @@ -1312,7 +1685,7 @@ ENTRY(xen_failsafe_callback)
16233 SAVE_ALL
16234 jmp error_exit
16235 CFI_ENDPROC
16236 -END(xen_failsafe_callback)
16237 +ENDPROC(xen_failsafe_callback)
16238
16239 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16240 xen_hvm_callback_vector xen_evtchn_do_upcall
16241 @@ -1361,16 +1734,31 @@ ENTRY(paranoid_exit)
16242 TRACE_IRQS_OFF
16243 testl %ebx,%ebx /* swapgs needed? */
16244 jnz paranoid_restore
16245 - testl $3,CS(%rsp)
16246 + testb $3,CS(%rsp)
16247 jnz paranoid_userspace
16248 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16249 + pax_exit_kernel
16250 + TRACE_IRQS_IRETQ 0
16251 + SWAPGS_UNSAFE_STACK
16252 + RESTORE_ALL 8
16253 + pax_force_retaddr_bts
16254 + jmp irq_return
16255 +#endif
16256 paranoid_swapgs:
16257 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16258 + pax_exit_kernel_user
16259 +#else
16260 + pax_exit_kernel
16261 +#endif
16262 TRACE_IRQS_IRETQ 0
16263 SWAPGS_UNSAFE_STACK
16264 RESTORE_ALL 8
16265 jmp irq_return
16266 paranoid_restore:
16267 + pax_exit_kernel
16268 TRACE_IRQS_IRETQ 0
16269 RESTORE_ALL 8
16270 + pax_force_retaddr_bts
16271 jmp irq_return
16272 paranoid_userspace:
16273 GET_THREAD_INFO(%rcx)
16274 @@ -1399,7 +1787,7 @@ paranoid_schedule:
16275 TRACE_IRQS_OFF
16276 jmp paranoid_userspace
16277 CFI_ENDPROC
16278 -END(paranoid_exit)
16279 +ENDPROC(paranoid_exit)
16280
16281 /*
16282 * Exception entry point. This expects an error code/orig_rax on the stack.
16283 @@ -1426,12 +1814,13 @@ ENTRY(error_entry)
16284 movq_cfi r14, R14+8
16285 movq_cfi r15, R15+8
16286 xorl %ebx,%ebx
16287 - testl $3,CS+8(%rsp)
16288 + testb $3,CS+8(%rsp)
16289 je error_kernelspace
16290 error_swapgs:
16291 SWAPGS
16292 error_sti:
16293 TRACE_IRQS_OFF
16294 + pax_force_retaddr_bts
16295 ret
16296
16297 /*
16298 @@ -1458,7 +1847,7 @@ bstep_iret:
16299 movq %rcx,RIP+8(%rsp)
16300 jmp error_swapgs
16301 CFI_ENDPROC
16302 -END(error_entry)
16303 +ENDPROC(error_entry)
16304
16305
16306 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16307 @@ -1478,7 +1867,7 @@ ENTRY(error_exit)
16308 jnz retint_careful
16309 jmp retint_swapgs
16310 CFI_ENDPROC
16311 -END(error_exit)
16312 +ENDPROC(error_exit)
16313
16314 /*
16315 * Test if a given stack is an NMI stack or not.
16316 @@ -1535,9 +1924,11 @@ ENTRY(nmi)
16317 * If %cs was not the kernel segment, then the NMI triggered in user
16318 * space, which means it is definitely not nested.
16319 */
16320 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16321 + je 1f
16322 cmpl $__KERNEL_CS, 16(%rsp)
16323 jne first_nmi
16324 -
16325 +1:
16326 /*
16327 * Check the special variable on the stack to see if NMIs are
16328 * executing.
16329 @@ -1659,6 +2050,16 @@ restart_nmi:
16330 */
16331 call save_paranoid
16332 DEFAULT_FRAME 0
16333 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16334 + testb $3, CS(%rsp)
16335 + jnz 1f
16336 + pax_enter_kernel
16337 + jmp 2f
16338 +1: pax_enter_kernel_user
16339 +2:
16340 +#else
16341 + pax_enter_kernel
16342 +#endif
16343 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16344 movq %rsp,%rdi
16345 movq $-1,%rsi
16346 @@ -1666,14 +2067,25 @@ restart_nmi:
16347 testl %ebx,%ebx /* swapgs needed? */
16348 jnz nmi_restore
16349 nmi_swapgs:
16350 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16351 + pax_exit_kernel_user
16352 +#else
16353 + pax_exit_kernel
16354 +#endif
16355 SWAPGS_UNSAFE_STACK
16356 + RESTORE_ALL 8
16357 + /* Clear the NMI executing stack variable */
16358 + movq $0, 10*8(%rsp)
16359 + jmp irq_return
16360 nmi_restore:
16361 + pax_exit_kernel
16362 RESTORE_ALL 8
16363 + pax_force_retaddr_bts
16364 /* Clear the NMI executing stack variable */
16365 movq $0, 10*8(%rsp)
16366 jmp irq_return
16367 CFI_ENDPROC
16368 -END(nmi)
16369 +ENDPROC(nmi)
16370
16371 /*
16372 * If an NMI hit an iret because of an exception or breakpoint,
16373 @@ -1700,7 +2112,7 @@ ENTRY(ignore_sysret)
16374 mov $-ENOSYS,%eax
16375 sysret
16376 CFI_ENDPROC
16377 -END(ignore_sysret)
16378 +ENDPROC(ignore_sysret)
16379
16380 /*
16381 * End of kprobes section
16382 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16383 index c9a281f..ce2f317 100644
16384 --- a/arch/x86/kernel/ftrace.c
16385 +++ b/arch/x86/kernel/ftrace.c
16386 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16387 static const void *mod_code_newcode; /* holds the text to write to the IP */
16388
16389 static unsigned nmi_wait_count;
16390 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
16391 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16392
16393 int ftrace_arch_read_dyn_info(char *buf, int size)
16394 {
16395 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16396
16397 r = snprintf(buf, size, "%u %u",
16398 nmi_wait_count,
16399 - atomic_read(&nmi_update_count));
16400 + atomic_read_unchecked(&nmi_update_count));
16401 return r;
16402 }
16403
16404 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16405
16406 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16407 smp_rmb();
16408 + pax_open_kernel();
16409 ftrace_mod_code();
16410 - atomic_inc(&nmi_update_count);
16411 + pax_close_kernel();
16412 + atomic_inc_unchecked(&nmi_update_count);
16413 }
16414 /* Must have previous changes seen before executions */
16415 smp_mb();
16416 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16417 {
16418 unsigned char replaced[MCOUNT_INSN_SIZE];
16419
16420 + ip = ktla_ktva(ip);
16421 +
16422 /*
16423 * Note: Due to modules and __init, code can
16424 * disappear and change, we need to protect against faulting
16425 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16426 unsigned char old[MCOUNT_INSN_SIZE], *new;
16427 int ret;
16428
16429 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16430 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16431 new = ftrace_call_replace(ip, (unsigned long)func);
16432 ret = ftrace_modify_code(ip, old, new);
16433
16434 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16435 {
16436 unsigned char code[MCOUNT_INSN_SIZE];
16437
16438 + ip = ktla_ktva(ip);
16439 +
16440 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16441 return -EFAULT;
16442
16443 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16444 index 51ff186..9e77418 100644
16445 --- a/arch/x86/kernel/head32.c
16446 +++ b/arch/x86/kernel/head32.c
16447 @@ -19,6 +19,7 @@
16448 #include <asm/io_apic.h>
16449 #include <asm/bios_ebda.h>
16450 #include <asm/tlbflush.h>
16451 +#include <asm/boot.h>
16452
16453 static void __init i386_default_early_setup(void)
16454 {
16455 @@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16456
16457 void __init i386_start_kernel(void)
16458 {
16459 - memblock_reserve(__pa_symbol(&_text),
16460 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16461 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16462
16463 #ifdef CONFIG_BLK_DEV_INITRD
16464 /* Reserve INITRD */
16465 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16466 index ce0be7c..c41476e 100644
16467 --- a/arch/x86/kernel/head_32.S
16468 +++ b/arch/x86/kernel/head_32.S
16469 @@ -25,6 +25,12 @@
16470 /* Physical address */
16471 #define pa(X) ((X) - __PAGE_OFFSET)
16472
16473 +#ifdef CONFIG_PAX_KERNEXEC
16474 +#define ta(X) (X)
16475 +#else
16476 +#define ta(X) ((X) - __PAGE_OFFSET)
16477 +#endif
16478 +
16479 /*
16480 * References to members of the new_cpu_data structure.
16481 */
16482 @@ -54,11 +60,7 @@
16483 * and small than max_low_pfn, otherwise will waste some page table entries
16484 */
16485
16486 -#if PTRS_PER_PMD > 1
16487 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16488 -#else
16489 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16490 -#endif
16491 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16492
16493 /* Number of possible pages in the lowmem region */
16494 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16495 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16496 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16497
16498 /*
16499 + * Real beginning of normal "text" segment
16500 + */
16501 +ENTRY(stext)
16502 +ENTRY(_stext)
16503 +
16504 +/*
16505 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16506 * %esi points to the real-mode code as a 32-bit pointer.
16507 * CS and DS must be 4 GB flat segments, but we don't depend on
16508 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16509 * can.
16510 */
16511 __HEAD
16512 +
16513 +#ifdef CONFIG_PAX_KERNEXEC
16514 + jmp startup_32
16515 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16516 +.fill PAGE_SIZE-5,1,0xcc
16517 +#endif
16518 +
16519 ENTRY(startup_32)
16520 movl pa(stack_start),%ecx
16521
16522 @@ -105,6 +120,57 @@ ENTRY(startup_32)
16523 2:
16524 leal -__PAGE_OFFSET(%ecx),%esp
16525
16526 +#ifdef CONFIG_SMP
16527 + movl $pa(cpu_gdt_table),%edi
16528 + movl $__per_cpu_load,%eax
16529 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16530 + rorl $16,%eax
16531 + movb %al,__KERNEL_PERCPU + 4(%edi)
16532 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16533 + movl $__per_cpu_end - 1,%eax
16534 + subl $__per_cpu_start,%eax
16535 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16536 +#endif
16537 +
16538 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16539 + movl $NR_CPUS,%ecx
16540 + movl $pa(cpu_gdt_table),%edi
16541 +1:
16542 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16543 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16544 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16545 + addl $PAGE_SIZE_asm,%edi
16546 + loop 1b
16547 +#endif
16548 +
16549 +#ifdef CONFIG_PAX_KERNEXEC
16550 + movl $pa(boot_gdt),%edi
16551 + movl $__LOAD_PHYSICAL_ADDR,%eax
16552 + movw %ax,__BOOT_CS + 2(%edi)
16553 + rorl $16,%eax
16554 + movb %al,__BOOT_CS + 4(%edi)
16555 + movb %ah,__BOOT_CS + 7(%edi)
16556 + rorl $16,%eax
16557 +
16558 + ljmp $(__BOOT_CS),$1f
16559 +1:
16560 +
16561 + movl $NR_CPUS,%ecx
16562 + movl $pa(cpu_gdt_table),%edi
16563 + addl $__PAGE_OFFSET,%eax
16564 +1:
16565 + movw %ax,__KERNEL_CS + 2(%edi)
16566 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16567 + rorl $16,%eax
16568 + movb %al,__KERNEL_CS + 4(%edi)
16569 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16570 + movb %ah,__KERNEL_CS + 7(%edi)
16571 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16572 + rorl $16,%eax
16573 + addl $PAGE_SIZE_asm,%edi
16574 + loop 1b
16575 +#endif
16576 +
16577 /*
16578 * Clear BSS first so that there are no surprises...
16579 */
16580 @@ -195,8 +261,11 @@ ENTRY(startup_32)
16581 movl %eax, pa(max_pfn_mapped)
16582
16583 /* Do early initialization of the fixmap area */
16584 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16585 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16586 +#ifdef CONFIG_COMPAT_VDSO
16587 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16588 +#else
16589 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16590 +#endif
16591 #else /* Not PAE */
16592
16593 page_pde_offset = (__PAGE_OFFSET >> 20);
16594 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16595 movl %eax, pa(max_pfn_mapped)
16596
16597 /* Do early initialization of the fixmap area */
16598 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16599 - movl %eax,pa(initial_page_table+0xffc)
16600 +#ifdef CONFIG_COMPAT_VDSO
16601 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16602 +#else
16603 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16604 +#endif
16605 #endif
16606
16607 #ifdef CONFIG_PARAVIRT
16608 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16609 cmpl $num_subarch_entries, %eax
16610 jae bad_subarch
16611
16612 - movl pa(subarch_entries)(,%eax,4), %eax
16613 - subl $__PAGE_OFFSET, %eax
16614 - jmp *%eax
16615 + jmp *pa(subarch_entries)(,%eax,4)
16616
16617 bad_subarch:
16618 WEAK(lguest_entry)
16619 @@ -255,10 +325,10 @@ WEAK(xen_entry)
16620 __INITDATA
16621
16622 subarch_entries:
16623 - .long default_entry /* normal x86/PC */
16624 - .long lguest_entry /* lguest hypervisor */
16625 - .long xen_entry /* Xen hypervisor */
16626 - .long default_entry /* Moorestown MID */
16627 + .long ta(default_entry) /* normal x86/PC */
16628 + .long ta(lguest_entry) /* lguest hypervisor */
16629 + .long ta(xen_entry) /* Xen hypervisor */
16630 + .long ta(default_entry) /* Moorestown MID */
16631 num_subarch_entries = (. - subarch_entries) / 4
16632 .previous
16633 #else
16634 @@ -312,6 +382,7 @@ default_entry:
16635 orl %edx,%eax
16636 movl %eax,%cr4
16637
16638 +#ifdef CONFIG_X86_PAE
16639 testb $X86_CR4_PAE, %al # check if PAE is enabled
16640 jz 6f
16641
16642 @@ -340,6 +411,9 @@ default_entry:
16643 /* Make changes effective */
16644 wrmsr
16645
16646 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16647 +#endif
16648 +
16649 6:
16650
16651 /*
16652 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16653 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16654 movl %eax,%ss # after changing gdt.
16655
16656 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16657 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16658 movl %eax,%ds
16659 movl %eax,%es
16660
16661 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16662 */
16663 cmpb $0,ready
16664 jne 1f
16665 - movl $gdt_page,%eax
16666 + movl $cpu_gdt_table,%eax
16667 movl $stack_canary,%ecx
16668 +#ifdef CONFIG_SMP
16669 + addl $__per_cpu_load,%ecx
16670 +#endif
16671 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16672 shrl $16, %ecx
16673 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16674 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16675 1:
16676 -#endif
16677 movl $(__KERNEL_STACK_CANARY),%eax
16678 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16679 + movl $(__USER_DS),%eax
16680 +#else
16681 + xorl %eax,%eax
16682 +#endif
16683 movl %eax,%gs
16684
16685 xorl %eax,%eax # Clear LDT
16686 @@ -558,22 +639,22 @@ early_page_fault:
16687 jmp early_fault
16688
16689 early_fault:
16690 - cld
16691 #ifdef CONFIG_PRINTK
16692 + cmpl $1,%ss:early_recursion_flag
16693 + je hlt_loop
16694 + incl %ss:early_recursion_flag
16695 + cld
16696 pusha
16697 movl $(__KERNEL_DS),%eax
16698 movl %eax,%ds
16699 movl %eax,%es
16700 - cmpl $2,early_recursion_flag
16701 - je hlt_loop
16702 - incl early_recursion_flag
16703 movl %cr2,%eax
16704 pushl %eax
16705 pushl %edx /* trapno */
16706 pushl $fault_msg
16707 call printk
16708 +; call dump_stack
16709 #endif
16710 - call dump_stack
16711 hlt_loop:
16712 hlt
16713 jmp hlt_loop
16714 @@ -581,8 +662,11 @@ hlt_loop:
16715 /* This is the default interrupt "handler" :-) */
16716 ALIGN
16717 ignore_int:
16718 - cld
16719 #ifdef CONFIG_PRINTK
16720 + cmpl $2,%ss:early_recursion_flag
16721 + je hlt_loop
16722 + incl %ss:early_recursion_flag
16723 + cld
16724 pushl %eax
16725 pushl %ecx
16726 pushl %edx
16727 @@ -591,9 +675,6 @@ ignore_int:
16728 movl $(__KERNEL_DS),%eax
16729 movl %eax,%ds
16730 movl %eax,%es
16731 - cmpl $2,early_recursion_flag
16732 - je hlt_loop
16733 - incl early_recursion_flag
16734 pushl 16(%esp)
16735 pushl 24(%esp)
16736 pushl 32(%esp)
16737 @@ -622,29 +703,43 @@ ENTRY(initial_code)
16738 /*
16739 * BSS section
16740 */
16741 -__PAGE_ALIGNED_BSS
16742 - .align PAGE_SIZE
16743 #ifdef CONFIG_X86_PAE
16744 +.section .initial_pg_pmd,"a",@progbits
16745 initial_pg_pmd:
16746 .fill 1024*KPMDS,4,0
16747 #else
16748 +.section .initial_page_table,"a",@progbits
16749 ENTRY(initial_page_table)
16750 .fill 1024,4,0
16751 #endif
16752 +.section .initial_pg_fixmap,"a",@progbits
16753 initial_pg_fixmap:
16754 .fill 1024,4,0
16755 +.section .empty_zero_page,"a",@progbits
16756 ENTRY(empty_zero_page)
16757 .fill 4096,1,0
16758 +.section .swapper_pg_dir,"a",@progbits
16759 ENTRY(swapper_pg_dir)
16760 +#ifdef CONFIG_X86_PAE
16761 + .fill 4,8,0
16762 +#else
16763 .fill 1024,4,0
16764 +#endif
16765 +
16766 +/*
16767 + * The IDT has to be page-aligned to simplify the Pentium
16768 + * F0 0F bug workaround.. We have a special link segment
16769 + * for this.
16770 + */
16771 +.section .idt,"a",@progbits
16772 +ENTRY(idt_table)
16773 + .fill 256,8,0
16774
16775 /*
16776 * This starts the data section.
16777 */
16778 #ifdef CONFIG_X86_PAE
16779 -__PAGE_ALIGNED_DATA
16780 - /* Page-aligned for the benefit of paravirt? */
16781 - .align PAGE_SIZE
16782 +.section .initial_page_table,"a",@progbits
16783 ENTRY(initial_page_table)
16784 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16785 # if KPMDS == 3
16786 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
16787 # error "Kernel PMDs should be 1, 2 or 3"
16788 # endif
16789 .align PAGE_SIZE /* needs to be page-sized too */
16790 +
16791 +#ifdef CONFIG_PAX_PER_CPU_PGD
16792 +ENTRY(cpu_pgd)
16793 + .rept NR_CPUS
16794 + .fill 4,8,0
16795 + .endr
16796 +#endif
16797 +
16798 #endif
16799
16800 .data
16801 .balign 4
16802 ENTRY(stack_start)
16803 - .long init_thread_union+THREAD_SIZE
16804 + .long init_thread_union+THREAD_SIZE-8
16805
16806 +ready: .byte 0
16807 +
16808 +.section .rodata,"a",@progbits
16809 early_recursion_flag:
16810 .long 0
16811
16812 -ready: .byte 0
16813 -
16814 int_msg:
16815 .asciz "Unknown interrupt or fault at: %p %p %p\n"
16816
16817 @@ -707,7 +811,7 @@ fault_msg:
16818 .word 0 # 32 bit align gdt_desc.address
16819 boot_gdt_descr:
16820 .word __BOOT_DS+7
16821 - .long boot_gdt - __PAGE_OFFSET
16822 + .long pa(boot_gdt)
16823
16824 .word 0 # 32-bit align idt_desc.address
16825 idt_descr:
16826 @@ -718,7 +822,7 @@ idt_descr:
16827 .word 0 # 32 bit align gdt_desc.address
16828 ENTRY(early_gdt_descr)
16829 .word GDT_ENTRIES*8-1
16830 - .long gdt_page /* Overwritten for secondary CPUs */
16831 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
16832
16833 /*
16834 * The boot_gdt must mirror the equivalent in setup.S and is
16835 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
16836 .align L1_CACHE_BYTES
16837 ENTRY(boot_gdt)
16838 .fill GDT_ENTRY_BOOT_CS,8,0
16839 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
16840 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
16841 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
16842 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
16843 +
16844 + .align PAGE_SIZE_asm
16845 +ENTRY(cpu_gdt_table)
16846 + .rept NR_CPUS
16847 + .quad 0x0000000000000000 /* NULL descriptor */
16848 + .quad 0x0000000000000000 /* 0x0b reserved */
16849 + .quad 0x0000000000000000 /* 0x13 reserved */
16850 + .quad 0x0000000000000000 /* 0x1b reserved */
16851 +
16852 +#ifdef CONFIG_PAX_KERNEXEC
16853 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
16854 +#else
16855 + .quad 0x0000000000000000 /* 0x20 unused */
16856 +#endif
16857 +
16858 + .quad 0x0000000000000000 /* 0x28 unused */
16859 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
16860 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
16861 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
16862 + .quad 0x0000000000000000 /* 0x4b reserved */
16863 + .quad 0x0000000000000000 /* 0x53 reserved */
16864 + .quad 0x0000000000000000 /* 0x5b reserved */
16865 +
16866 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
16867 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
16868 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
16869 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
16870 +
16871 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
16872 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
16873 +
16874 + /*
16875 + * Segments used for calling PnP BIOS have byte granularity.
16876 + * The code segments and data segments have fixed 64k limits,
16877 + * the transfer segment sizes are set at run time.
16878 + */
16879 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
16880 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
16881 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
16882 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
16883 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
16884 +
16885 + /*
16886 + * The APM segments have byte granularity and their bases
16887 + * are set at run time. All have 64k limits.
16888 + */
16889 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
16890 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
16891 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
16892 +
16893 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
16894 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
16895 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
16896 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
16897 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
16898 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
16899 +
16900 + /* Be sure this is zeroed to avoid false validations in Xen */
16901 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
16902 + .endr
16903 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
16904 index 40f4eb3..6d24d9d 100644
16905 --- a/arch/x86/kernel/head_64.S
16906 +++ b/arch/x86/kernel/head_64.S
16907 @@ -19,6 +19,8 @@
16908 #include <asm/cache.h>
16909 #include <asm/processor-flags.h>
16910 #include <asm/percpu.h>
16911 +#include <asm/cpufeature.h>
16912 +#include <asm/alternative-asm.h>
16913
16914 #ifdef CONFIG_PARAVIRT
16915 #include <asm/asm-offsets.h>
16916 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
16917 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
16918 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
16919 L3_START_KERNEL = pud_index(__START_KERNEL_map)
16920 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
16921 +L3_VMALLOC_START = pud_index(VMALLOC_START)
16922 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
16923 +L3_VMALLOC_END = pud_index(VMALLOC_END)
16924 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
16925 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
16926
16927 .text
16928 __HEAD
16929 @@ -85,35 +93,23 @@ startup_64:
16930 */
16931 addq %rbp, init_level4_pgt + 0(%rip)
16932 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
16933 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
16934 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
16935 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
16936 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
16937
16938 addq %rbp, level3_ident_pgt + 0(%rip)
16939 +#ifndef CONFIG_XEN
16940 + addq %rbp, level3_ident_pgt + 8(%rip)
16941 +#endif
16942
16943 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
16944 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
16945 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
16946 +
16947 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
16948 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
16949
16950 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
16951 -
16952 - /* Add an Identity mapping if I am above 1G */
16953 - leaq _text(%rip), %rdi
16954 - andq $PMD_PAGE_MASK, %rdi
16955 -
16956 - movq %rdi, %rax
16957 - shrq $PUD_SHIFT, %rax
16958 - andq $(PTRS_PER_PUD - 1), %rax
16959 - jz ident_complete
16960 -
16961 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
16962 - leaq level3_ident_pgt(%rip), %rbx
16963 - movq %rdx, 0(%rbx, %rax, 8)
16964 -
16965 - movq %rdi, %rax
16966 - shrq $PMD_SHIFT, %rax
16967 - andq $(PTRS_PER_PMD - 1), %rax
16968 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
16969 - leaq level2_spare_pgt(%rip), %rbx
16970 - movq %rdx, 0(%rbx, %rax, 8)
16971 -ident_complete:
16972 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
16973
16974 /*
16975 * Fixup the kernel text+data virtual addresses. Note that
16976 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
16977 * after the boot processor executes this code.
16978 */
16979
16980 - /* Enable PAE mode and PGE */
16981 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
16982 + /* Enable PAE mode and PSE/PGE */
16983 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
16984 movq %rax, %cr4
16985
16986 /* Setup early boot stage 4 level pagetables. */
16987 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
16988 movl $MSR_EFER, %ecx
16989 rdmsr
16990 btsl $_EFER_SCE, %eax /* Enable System Call */
16991 - btl $20,%edi /* No Execute supported? */
16992 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
16993 jnc 1f
16994 btsl $_EFER_NX, %eax
16995 + leaq init_level4_pgt(%rip), %rdi
16996 +#ifndef CONFIG_EFI
16997 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
16998 +#endif
16999 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17000 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17001 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17002 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17003 1: wrmsr /* Make changes effective */
17004
17005 /* Setup cr0 */
17006 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
17007 * jump. In addition we need to ensure %cs is set so we make this
17008 * a far return.
17009 */
17010 + pax_set_fptr_mask
17011 movq initial_code(%rip),%rax
17012 pushq $0 # fake return address to stop unwinder
17013 pushq $__KERNEL_CS # set correct cs
17014 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
17015 bad_address:
17016 jmp bad_address
17017
17018 - .section ".init.text","ax"
17019 + __INIT
17020 #ifdef CONFIG_EARLY_PRINTK
17021 .globl early_idt_handlers
17022 early_idt_handlers:
17023 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
17024 #endif /* EARLY_PRINTK */
17025 1: hlt
17026 jmp 1b
17027 + .previous
17028
17029 #ifdef CONFIG_EARLY_PRINTK
17030 + __INITDATA
17031 early_recursion_flag:
17032 .long 0
17033 + .previous
17034
17035 + .section .rodata,"a",@progbits
17036 early_idt_msg:
17037 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17038 early_idt_ripmsg:
17039 .asciz "RIP %s\n"
17040 + .previous
17041 #endif /* CONFIG_EARLY_PRINTK */
17042 - .previous
17043
17044 + .section .rodata,"a",@progbits
17045 #define NEXT_PAGE(name) \
17046 .balign PAGE_SIZE; \
17047 ENTRY(name)
17048 @@ -338,7 +348,6 @@ ENTRY(name)
17049 i = i + 1 ; \
17050 .endr
17051
17052 - .data
17053 /*
17054 * This default setting generates an ident mapping at address 0x100000
17055 * and a mapping for the kernel that precisely maps virtual address
17056 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
17057 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17058 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17059 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17060 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17061 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17062 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17063 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17064 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17065 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17066 .org init_level4_pgt + L4_START_KERNEL*8, 0
17067 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17068 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17069
17070 +#ifdef CONFIG_PAX_PER_CPU_PGD
17071 +NEXT_PAGE(cpu_pgd)
17072 + .rept NR_CPUS
17073 + .fill 512,8,0
17074 + .endr
17075 +#endif
17076 +
17077 NEXT_PAGE(level3_ident_pgt)
17078 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17079 +#ifdef CONFIG_XEN
17080 .fill 511,8,0
17081 +#else
17082 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17083 + .fill 510,8,0
17084 +#endif
17085 +
17086 +NEXT_PAGE(level3_vmalloc_start_pgt)
17087 + .fill 512,8,0
17088 +
17089 +NEXT_PAGE(level3_vmalloc_end_pgt)
17090 + .fill 512,8,0
17091 +
17092 +NEXT_PAGE(level3_vmemmap_pgt)
17093 + .fill L3_VMEMMAP_START,8,0
17094 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17095
17096 NEXT_PAGE(level3_kernel_pgt)
17097 .fill L3_START_KERNEL,8,0
17098 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
17099 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17100 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17101
17102 +NEXT_PAGE(level2_vmemmap_pgt)
17103 + .fill 512,8,0
17104 +
17105 NEXT_PAGE(level2_fixmap_pgt)
17106 - .fill 506,8,0
17107 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17108 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17109 - .fill 5,8,0
17110 + .fill 507,8,0
17111 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17112 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17113 + .fill 4,8,0
17114
17115 -NEXT_PAGE(level1_fixmap_pgt)
17116 +NEXT_PAGE(level1_vsyscall_pgt)
17117 .fill 512,8,0
17118
17119 -NEXT_PAGE(level2_ident_pgt)
17120 - /* Since I easily can, map the first 1G.
17121 + /* Since I easily can, map the first 2G.
17122 * Don't set NX because code runs from these pages.
17123 */
17124 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17125 +NEXT_PAGE(level2_ident_pgt)
17126 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17127
17128 NEXT_PAGE(level2_kernel_pgt)
17129 /*
17130 @@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
17131 * If you want to increase this then increase MODULES_VADDR
17132 * too.)
17133 */
17134 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17135 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17136 -
17137 -NEXT_PAGE(level2_spare_pgt)
17138 - .fill 512, 8, 0
17139 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17140
17141 #undef PMDS
17142 #undef NEXT_PAGE
17143
17144 - .data
17145 + .align PAGE_SIZE
17146 +ENTRY(cpu_gdt_table)
17147 + .rept NR_CPUS
17148 + .quad 0x0000000000000000 /* NULL descriptor */
17149 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17150 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17151 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17152 + .quad 0x00cffb000000ffff /* __USER32_CS */
17153 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17154 + .quad 0x00affb000000ffff /* __USER_CS */
17155 +
17156 +#ifdef CONFIG_PAX_KERNEXEC
17157 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17158 +#else
17159 + .quad 0x0 /* unused */
17160 +#endif
17161 +
17162 + .quad 0,0 /* TSS */
17163 + .quad 0,0 /* LDT */
17164 + .quad 0,0,0 /* three TLS descriptors */
17165 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17166 + /* asm/segment.h:GDT_ENTRIES must match this */
17167 +
17168 + /* zero the remaining page */
17169 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17170 + .endr
17171 +
17172 .align 16
17173 .globl early_gdt_descr
17174 early_gdt_descr:
17175 .word GDT_ENTRIES*8-1
17176 early_gdt_descr_base:
17177 - .quad INIT_PER_CPU_VAR(gdt_page)
17178 + .quad cpu_gdt_table
17179
17180 ENTRY(phys_base)
17181 /* This must match the first entry in level2_kernel_pgt */
17182 .quad 0x0000000000000000
17183
17184 #include "../../x86/xen/xen-head.S"
17185 -
17186 - .section .bss, "aw", @nobits
17187 +
17188 + .section .rodata,"a",@progbits
17189 .align L1_CACHE_BYTES
17190 ENTRY(idt_table)
17191 - .skip IDT_ENTRIES * 16
17192 + .fill 512,8,0
17193
17194 .align L1_CACHE_BYTES
17195 ENTRY(nmi_idt_table)
17196 - .skip IDT_ENTRIES * 16
17197 + .fill 512,8,0
17198
17199 __PAGE_ALIGNED_BSS
17200 .align PAGE_SIZE
17201 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17202 index 9c3bd4a..e1d9b35 100644
17203 --- a/arch/x86/kernel/i386_ksyms_32.c
17204 +++ b/arch/x86/kernel/i386_ksyms_32.c
17205 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17206 EXPORT_SYMBOL(cmpxchg8b_emu);
17207 #endif
17208
17209 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17210 +
17211 /* Networking helper routines. */
17212 EXPORT_SYMBOL(csum_partial_copy_generic);
17213 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17214 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17215
17216 EXPORT_SYMBOL(__get_user_1);
17217 EXPORT_SYMBOL(__get_user_2);
17218 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17219
17220 EXPORT_SYMBOL(csum_partial);
17221 EXPORT_SYMBOL(empty_zero_page);
17222 +
17223 +#ifdef CONFIG_PAX_KERNEXEC
17224 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17225 +#endif
17226 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17227 index f239f30..aab2a58 100644
17228 --- a/arch/x86/kernel/i387.c
17229 +++ b/arch/x86/kernel/i387.c
17230 @@ -189,6 +189,9 @@ int xfpregs_active(struct task_struct *target, const struct user_regset *regset)
17231
17232 int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17233 unsigned int pos, unsigned int count,
17234 + void *kbuf, void __user *ubuf) __size_overflow(4);
17235 +int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17236 + unsigned int pos, unsigned int count,
17237 void *kbuf, void __user *ubuf)
17238 {
17239 int ret;
17240 @@ -208,6 +211,9 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17241
17242 int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17243 unsigned int pos, unsigned int count,
17244 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17245 +int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17246 + unsigned int pos, unsigned int count,
17247 const void *kbuf, const void __user *ubuf)
17248 {
17249 int ret;
17250 @@ -241,6 +247,9 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17251
17252 int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17253 unsigned int pos, unsigned int count,
17254 + void *kbuf, void __user *ubuf) __size_overflow(4);
17255 +int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17256 + unsigned int pos, unsigned int count,
17257 void *kbuf, void __user *ubuf)
17258 {
17259 int ret;
17260 @@ -270,6 +279,9 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17261
17262 int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
17263 unsigned int pos, unsigned int count,
17264 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17265 +int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
17266 + unsigned int pos, unsigned int count,
17267 const void *kbuf, const void __user *ubuf)
17268 {
17269 int ret;
17270 @@ -440,6 +452,9 @@ static void convert_to_fxsr(struct task_struct *tsk,
17271
17272 int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17273 unsigned int pos, unsigned int count,
17274 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
17275 +int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17276 + unsigned int pos, unsigned int count,
17277 void *kbuf, void __user *ubuf)
17278 {
17279 struct user_i387_ia32_struct env;
17280 @@ -472,6 +487,9 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17281
17282 int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17283 unsigned int pos, unsigned int count,
17284 + const void *kbuf, const void __user *ubuf) __size_overflow(3,4);
17285 +int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17286 + unsigned int pos, unsigned int count,
17287 const void *kbuf, const void __user *ubuf)
17288 {
17289 struct user_i387_ia32_struct env;
17290 @@ -620,6 +638,8 @@ static inline int restore_i387_fsave(struct _fpstate_ia32 __user *buf)
17291 }
17292
17293 static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17294 + unsigned int size) __size_overflow(2);
17295 +static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17296 unsigned int size)
17297 {
17298 struct task_struct *tsk = current;
17299 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17300 index 6104852..6114160 100644
17301 --- a/arch/x86/kernel/i8259.c
17302 +++ b/arch/x86/kernel/i8259.c
17303 @@ -210,7 +210,7 @@ spurious_8259A_irq:
17304 "spurious 8259A interrupt: IRQ%d.\n", irq);
17305 spurious_irq_mask |= irqmask;
17306 }
17307 - atomic_inc(&irq_err_count);
17308 + atomic_inc_unchecked(&irq_err_count);
17309 /*
17310 * Theoretically we do not have to handle this IRQ,
17311 * but in Linux this does not cause problems and is
17312 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17313 index 43e9ccf..44ccf6f 100644
17314 --- a/arch/x86/kernel/init_task.c
17315 +++ b/arch/x86/kernel/init_task.c
17316 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17317 * way process stacks are handled. This is done by having a special
17318 * "init_task" linker map entry..
17319 */
17320 -union thread_union init_thread_union __init_task_data =
17321 - { INIT_THREAD_INFO(init_task) };
17322 +union thread_union init_thread_union __init_task_data;
17323
17324 /*
17325 * Initial task structure.
17326 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17327 * section. Since TSS's are completely CPU-local, we want them
17328 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17329 */
17330 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17331 -
17332 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17333 +EXPORT_SYMBOL(init_tss);
17334 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17335 index 8c96897..be66bfa 100644
17336 --- a/arch/x86/kernel/ioport.c
17337 +++ b/arch/x86/kernel/ioport.c
17338 @@ -6,6 +6,7 @@
17339 #include <linux/sched.h>
17340 #include <linux/kernel.h>
17341 #include <linux/capability.h>
17342 +#include <linux/security.h>
17343 #include <linux/errno.h>
17344 #include <linux/types.h>
17345 #include <linux/ioport.h>
17346 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17347
17348 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17349 return -EINVAL;
17350 +#ifdef CONFIG_GRKERNSEC_IO
17351 + if (turn_on && grsec_disable_privio) {
17352 + gr_handle_ioperm();
17353 + return -EPERM;
17354 + }
17355 +#endif
17356 if (turn_on && !capable(CAP_SYS_RAWIO))
17357 return -EPERM;
17358
17359 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17360 * because the ->io_bitmap_max value must match the bitmap
17361 * contents:
17362 */
17363 - tss = &per_cpu(init_tss, get_cpu());
17364 + tss = init_tss + get_cpu();
17365
17366 if (turn_on)
17367 bitmap_clear(t->io_bitmap_ptr, from, num);
17368 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17369 return -EINVAL;
17370 /* Trying to gain more privileges? */
17371 if (level > old) {
17372 +#ifdef CONFIG_GRKERNSEC_IO
17373 + if (grsec_disable_privio) {
17374 + gr_handle_iopl();
17375 + return -EPERM;
17376 + }
17377 +#endif
17378 if (!capable(CAP_SYS_RAWIO))
17379 return -EPERM;
17380 }
17381 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17382 index 7943e0c..dd32c5c 100644
17383 --- a/arch/x86/kernel/irq.c
17384 +++ b/arch/x86/kernel/irq.c
17385 @@ -18,7 +18,7 @@
17386 #include <asm/mce.h>
17387 #include <asm/hw_irq.h>
17388
17389 -atomic_t irq_err_count;
17390 +atomic_unchecked_t irq_err_count;
17391
17392 /* Function pointer for generic interrupt vector handling */
17393 void (*x86_platform_ipi_callback)(void) = NULL;
17394 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17395 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17396 seq_printf(p, " Machine check polls\n");
17397 #endif
17398 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17399 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17400 #if defined(CONFIG_X86_IO_APIC)
17401 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17402 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17403 #endif
17404 return 0;
17405 }
17406 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17407
17408 u64 arch_irq_stat(void)
17409 {
17410 - u64 sum = atomic_read(&irq_err_count);
17411 + u64 sum = atomic_read_unchecked(&irq_err_count);
17412
17413 #ifdef CONFIG_X86_IO_APIC
17414 - sum += atomic_read(&irq_mis_count);
17415 + sum += atomic_read_unchecked(&irq_mis_count);
17416 #endif
17417 return sum;
17418 }
17419 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17420 index 40fc861..9b8739b 100644
17421 --- a/arch/x86/kernel/irq_32.c
17422 +++ b/arch/x86/kernel/irq_32.c
17423 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17424 __asm__ __volatile__("andl %%esp,%0" :
17425 "=r" (sp) : "0" (THREAD_SIZE - 1));
17426
17427 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17428 + return sp < STACK_WARN;
17429 }
17430
17431 static void print_stack_overflow(void)
17432 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17433 * per-CPU IRQ handling contexts (thread information and stack)
17434 */
17435 union irq_ctx {
17436 - struct thread_info tinfo;
17437 - u32 stack[THREAD_SIZE/sizeof(u32)];
17438 + unsigned long previous_esp;
17439 + u32 stack[THREAD_SIZE/sizeof(u32)];
17440 } __attribute__((aligned(THREAD_SIZE)));
17441
17442 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17443 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17444 static inline int
17445 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17446 {
17447 - union irq_ctx *curctx, *irqctx;
17448 + union irq_ctx *irqctx;
17449 u32 *isp, arg1, arg2;
17450
17451 - curctx = (union irq_ctx *) current_thread_info();
17452 irqctx = __this_cpu_read(hardirq_ctx);
17453
17454 /*
17455 @@ -92,21 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17456 * handler) we can't do that and just have to keep using the
17457 * current stack (which is the irq stack already after all)
17458 */
17459 - if (unlikely(curctx == irqctx))
17460 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17461 return 0;
17462
17463 /* build the stack frame on the IRQ stack */
17464 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17465 - irqctx->tinfo.task = curctx->tinfo.task;
17466 - irqctx->tinfo.previous_esp = current_stack_pointer;
17467 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17468 + irqctx->previous_esp = current_stack_pointer;
17469
17470 - /*
17471 - * Copy the softirq bits in preempt_count so that the
17472 - * softirq checks work in the hardirq context.
17473 - */
17474 - irqctx->tinfo.preempt_count =
17475 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17476 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17477 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17478 + __set_fs(MAKE_MM_SEG(0));
17479 +#endif
17480
17481 if (unlikely(overflow))
17482 call_on_stack(print_stack_overflow, isp);
17483 @@ -118,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17484 : "0" (irq), "1" (desc), "2" (isp),
17485 "D" (desc->handle_irq)
17486 : "memory", "cc", "ecx");
17487 +
17488 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17489 + __set_fs(current_thread_info()->addr_limit);
17490 +#endif
17491 +
17492 return 1;
17493 }
17494
17495 @@ -126,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17496 */
17497 void __cpuinit irq_ctx_init(int cpu)
17498 {
17499 - union irq_ctx *irqctx;
17500 -
17501 if (per_cpu(hardirq_ctx, cpu))
17502 return;
17503
17504 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17505 - THREAD_FLAGS,
17506 - THREAD_ORDER));
17507 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17508 - irqctx->tinfo.cpu = cpu;
17509 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17510 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17511 -
17512 - per_cpu(hardirq_ctx, cpu) = irqctx;
17513 -
17514 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17515 - THREAD_FLAGS,
17516 - THREAD_ORDER));
17517 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17518 - irqctx->tinfo.cpu = cpu;
17519 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17520 -
17521 - per_cpu(softirq_ctx, cpu) = irqctx;
17522 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17523 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17524
17525 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17526 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17527 @@ -157,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17528 asmlinkage void do_softirq(void)
17529 {
17530 unsigned long flags;
17531 - struct thread_info *curctx;
17532 union irq_ctx *irqctx;
17533 u32 *isp;
17534
17535 @@ -167,15 +147,22 @@ asmlinkage void do_softirq(void)
17536 local_irq_save(flags);
17537
17538 if (local_softirq_pending()) {
17539 - curctx = current_thread_info();
17540 irqctx = __this_cpu_read(softirq_ctx);
17541 - irqctx->tinfo.task = curctx->task;
17542 - irqctx->tinfo.previous_esp = current_stack_pointer;
17543 + irqctx->previous_esp = current_stack_pointer;
17544
17545 /* build the stack frame on the softirq stack */
17546 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17547 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17548 +
17549 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17550 + __set_fs(MAKE_MM_SEG(0));
17551 +#endif
17552
17553 call_on_stack(__do_softirq, isp);
17554 +
17555 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17556 + __set_fs(current_thread_info()->addr_limit);
17557 +#endif
17558 +
17559 /*
17560 * Shouldn't happen, we returned above if in_interrupt():
17561 */
17562 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17563 index d04d3ec..ea4b374 100644
17564 --- a/arch/x86/kernel/irq_64.c
17565 +++ b/arch/x86/kernel/irq_64.c
17566 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17567 u64 estack_top, estack_bottom;
17568 u64 curbase = (u64)task_stack_page(current);
17569
17570 - if (user_mode_vm(regs))
17571 + if (user_mode(regs))
17572 return;
17573
17574 if (regs->sp >= curbase + sizeof(struct thread_info) +
17575 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17576 index 90fcf62..e682cdd 100644
17577 --- a/arch/x86/kernel/kdebugfs.c
17578 +++ b/arch/x86/kernel/kdebugfs.c
17579 @@ -28,6 +28,8 @@ struct setup_data_node {
17580 };
17581
17582 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17583 + size_t count, loff_t *ppos) __size_overflow(3);
17584 +static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17585 size_t count, loff_t *ppos)
17586 {
17587 struct setup_data_node *node = file->private_data;
17588 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17589 index 2f45c4c..d95504f 100644
17590 --- a/arch/x86/kernel/kgdb.c
17591 +++ b/arch/x86/kernel/kgdb.c
17592 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17593 #ifdef CONFIG_X86_32
17594 switch (regno) {
17595 case GDB_SS:
17596 - if (!user_mode_vm(regs))
17597 + if (!user_mode(regs))
17598 *(unsigned long *)mem = __KERNEL_DS;
17599 break;
17600 case GDB_SP:
17601 - if (!user_mode_vm(regs))
17602 + if (!user_mode(regs))
17603 *(unsigned long *)mem = kernel_stack_pointer(regs);
17604 break;
17605 case GDB_GS:
17606 @@ -475,12 +475,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17607 case 'k':
17608 /* clear the trace bit */
17609 linux_regs->flags &= ~X86_EFLAGS_TF;
17610 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17611 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17612
17613 /* set the trace bit if we're stepping */
17614 if (remcomInBuffer[0] == 's') {
17615 linux_regs->flags |= X86_EFLAGS_TF;
17616 - atomic_set(&kgdb_cpu_doing_single_step,
17617 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17618 raw_smp_processor_id());
17619 }
17620
17621 @@ -545,7 +545,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17622
17623 switch (cmd) {
17624 case DIE_DEBUG:
17625 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17626 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17627 if (user_mode(regs))
17628 return single_step_cont(regs, args);
17629 break;
17630 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17631 index 7da647d..56fe348 100644
17632 --- a/arch/x86/kernel/kprobes.c
17633 +++ b/arch/x86/kernel/kprobes.c
17634 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17635 } __attribute__((packed)) *insn;
17636
17637 insn = (struct __arch_relative_insn *)from;
17638 +
17639 + pax_open_kernel();
17640 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17641 insn->op = op;
17642 + pax_close_kernel();
17643 }
17644
17645 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17646 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17647 kprobe_opcode_t opcode;
17648 kprobe_opcode_t *orig_opcodes = opcodes;
17649
17650 - if (search_exception_tables((unsigned long)opcodes))
17651 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17652 return 0; /* Page fault may occur on this address. */
17653
17654 retry:
17655 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17656 }
17657 }
17658 insn_get_length(&insn);
17659 + pax_open_kernel();
17660 memcpy(dest, insn.kaddr, insn.length);
17661 + pax_close_kernel();
17662
17663 #ifdef CONFIG_X86_64
17664 if (insn_rip_relative(&insn)) {
17665 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17666 (u8 *) dest;
17667 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17668 disp = (u8 *) dest + insn_offset_displacement(&insn);
17669 + pax_open_kernel();
17670 *(s32 *) disp = (s32) newdisp;
17671 + pax_close_kernel();
17672 }
17673 #endif
17674 return insn.length;
17675 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
17676 */
17677 __copy_instruction(p->ainsn.insn, p->addr, 0);
17678
17679 - if (can_boost(p->addr))
17680 + if (can_boost(ktla_ktva(p->addr)))
17681 p->ainsn.boostable = 0;
17682 else
17683 p->ainsn.boostable = -1;
17684
17685 - p->opcode = *p->addr;
17686 + p->opcode = *(ktla_ktva(p->addr));
17687 }
17688
17689 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17690 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17691 * nor set current_kprobe, because it doesn't use single
17692 * stepping.
17693 */
17694 - regs->ip = (unsigned long)p->ainsn.insn;
17695 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17696 preempt_enable_no_resched();
17697 return;
17698 }
17699 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17700 if (p->opcode == BREAKPOINT_INSTRUCTION)
17701 regs->ip = (unsigned long)p->addr;
17702 else
17703 - regs->ip = (unsigned long)p->ainsn.insn;
17704 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17705 }
17706
17707 /*
17708 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17709 setup_singlestep(p, regs, kcb, 0);
17710 return 1;
17711 }
17712 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17713 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17714 /*
17715 * The breakpoint instruction was removed right
17716 * after we hit it. Another cpu has removed
17717 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17718 " movq %rax, 152(%rsp)\n"
17719 RESTORE_REGS_STRING
17720 " popfq\n"
17721 +#ifdef KERNEXEC_PLUGIN
17722 + " btsq $63,(%rsp)\n"
17723 +#endif
17724 #else
17725 " pushf\n"
17726 SAVE_REGS_STRING
17727 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
17728 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17729 {
17730 unsigned long *tos = stack_addr(regs);
17731 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17732 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17733 unsigned long orig_ip = (unsigned long)p->addr;
17734 kprobe_opcode_t *insn = p->ainsn.insn;
17735
17736 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
17737 struct die_args *args = data;
17738 int ret = NOTIFY_DONE;
17739
17740 - if (args->regs && user_mode_vm(args->regs))
17741 + if (args->regs && user_mode(args->regs))
17742 return ret;
17743
17744 switch (val) {
17745 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17746 * Verify if the address gap is in 2GB range, because this uses
17747 * a relative jump.
17748 */
17749 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17750 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17751 if (abs(rel) > 0x7fffffff)
17752 return -ERANGE;
17753
17754 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17755 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17756
17757 /* Set probe function call */
17758 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17759 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17760
17761 /* Set returning jmp instruction at the tail of out-of-line buffer */
17762 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17763 - (u8 *)op->kp.addr + op->optinsn.size);
17764 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17765
17766 flush_icache_range((unsigned long) buf,
17767 (unsigned long) buf + TMPL_END_IDX +
17768 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17769 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17770
17771 /* Backup instructions which will be replaced by jump address */
17772 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17773 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17774 RELATIVE_ADDR_SIZE);
17775
17776 insn_buf[0] = RELATIVEJUMP_OPCODE;
17777 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17778 index ea69726..a305f16 100644
17779 --- a/arch/x86/kernel/ldt.c
17780 +++ b/arch/x86/kernel/ldt.c
17781 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17782 if (reload) {
17783 #ifdef CONFIG_SMP
17784 preempt_disable();
17785 - load_LDT(pc);
17786 + load_LDT_nolock(pc);
17787 if (!cpumask_equal(mm_cpumask(current->mm),
17788 cpumask_of(smp_processor_id())))
17789 smp_call_function(flush_ldt, current->mm, 1);
17790 preempt_enable();
17791 #else
17792 - load_LDT(pc);
17793 + load_LDT_nolock(pc);
17794 #endif
17795 }
17796 if (oldsize) {
17797 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17798 return err;
17799
17800 for (i = 0; i < old->size; i++)
17801 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17802 + write_ldt_entry(new->ldt, i, old->ldt + i);
17803 return 0;
17804 }
17805
17806 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17807 retval = copy_ldt(&mm->context, &old_mm->context);
17808 mutex_unlock(&old_mm->context.lock);
17809 }
17810 +
17811 + if (tsk == current) {
17812 + mm->context.vdso = 0;
17813 +
17814 +#ifdef CONFIG_X86_32
17815 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17816 + mm->context.user_cs_base = 0UL;
17817 + mm->context.user_cs_limit = ~0UL;
17818 +
17819 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17820 + cpus_clear(mm->context.cpu_user_cs_mask);
17821 +#endif
17822 +
17823 +#endif
17824 +#endif
17825 +
17826 + }
17827 +
17828 return retval;
17829 }
17830
17831 @@ -141,6 +159,7 @@ void destroy_context(struct mm_struct *mm)
17832 }
17833 }
17834
17835 +static int read_ldt(void __user *ptr, unsigned long bytecount) __size_overflow(2);
17836 static int read_ldt(void __user *ptr, unsigned long bytecount)
17837 {
17838 int err;
17839 @@ -175,6 +194,7 @@ error_return:
17840 return err;
17841 }
17842
17843 +static int read_default_ldt(void __user *ptr, unsigned long bytecount) __size_overflow(2);
17844 static int read_default_ldt(void __user *ptr, unsigned long bytecount)
17845 {
17846 /* CHECKME: Can we use _one_ random number ? */
17847 @@ -230,6 +250,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17848 }
17849 }
17850
17851 +#ifdef CONFIG_PAX_SEGMEXEC
17852 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17853 + error = -EINVAL;
17854 + goto out_unlock;
17855 + }
17856 +#endif
17857 +
17858 fill_ldt(&ldt, &ldt_info);
17859 if (oldmode)
17860 ldt.avl = 0;
17861 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17862 index a3fa43b..8966f4c 100644
17863 --- a/arch/x86/kernel/machine_kexec_32.c
17864 +++ b/arch/x86/kernel/machine_kexec_32.c
17865 @@ -27,7 +27,7 @@
17866 #include <asm/cacheflush.h>
17867 #include <asm/debugreg.h>
17868
17869 -static void set_idt(void *newidt, __u16 limit)
17870 +static void set_idt(struct desc_struct *newidt, __u16 limit)
17871 {
17872 struct desc_ptr curidt;
17873
17874 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
17875 }
17876
17877
17878 -static void set_gdt(void *newgdt, __u16 limit)
17879 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17880 {
17881 struct desc_ptr curgdt;
17882
17883 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
17884 }
17885
17886 control_page = page_address(image->control_code_page);
17887 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17888 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17889
17890 relocate_kernel_ptr = control_page;
17891 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17892 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17893 index 3ca42d0..79d24cd 100644
17894 --- a/arch/x86/kernel/microcode_intel.c
17895 +++ b/arch/x86/kernel/microcode_intel.c
17896 @@ -434,15 +434,16 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17897 return ret;
17898 }
17899
17900 +static int get_ucode_user(void *to, const void *from, size_t n) __size_overflow(3);
17901 static int get_ucode_user(void *to, const void *from, size_t n)
17902 {
17903 - return copy_from_user(to, from, n);
17904 + return copy_from_user(to, (const void __force_user *)from, n);
17905 }
17906
17907 static enum ucode_state
17908 request_microcode_user(int cpu, const void __user *buf, size_t size)
17909 {
17910 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17911 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17912 }
17913
17914 static void microcode_fini_cpu(int cpu)
17915 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17916 index 925179f..1f0d561 100644
17917 --- a/arch/x86/kernel/module.c
17918 +++ b/arch/x86/kernel/module.c
17919 @@ -36,15 +36,61 @@
17920 #define DEBUGP(fmt...)
17921 #endif
17922
17923 -void *module_alloc(unsigned long size)
17924 +static inline void *__module_alloc(unsigned long size, pgprot_t prot) __size_overflow(1);
17925 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17926 {
17927 - if (PAGE_ALIGN(size) > MODULES_LEN)
17928 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17929 return NULL;
17930 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
17931 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
17932 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
17933 -1, __builtin_return_address(0));
17934 }
17935
17936 +void *module_alloc(unsigned long size)
17937 +{
17938 +
17939 +#ifdef CONFIG_PAX_KERNEXEC
17940 + return __module_alloc(size, PAGE_KERNEL);
17941 +#else
17942 + return __module_alloc(size, PAGE_KERNEL_EXEC);
17943 +#endif
17944 +
17945 +}
17946 +
17947 +#ifdef CONFIG_PAX_KERNEXEC
17948 +#ifdef CONFIG_X86_32
17949 +void *module_alloc_exec(unsigned long size)
17950 +{
17951 + struct vm_struct *area;
17952 +
17953 + if (size == 0)
17954 + return NULL;
17955 +
17956 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
17957 + return area ? area->addr : NULL;
17958 +}
17959 +EXPORT_SYMBOL(module_alloc_exec);
17960 +
17961 +void module_free_exec(struct module *mod, void *module_region)
17962 +{
17963 + vunmap(module_region);
17964 +}
17965 +EXPORT_SYMBOL(module_free_exec);
17966 +#else
17967 +void module_free_exec(struct module *mod, void *module_region)
17968 +{
17969 + module_free(mod, module_region);
17970 +}
17971 +EXPORT_SYMBOL(module_free_exec);
17972 +
17973 +void *module_alloc_exec(unsigned long size)
17974 +{
17975 + return __module_alloc(size, PAGE_KERNEL_RX);
17976 +}
17977 +EXPORT_SYMBOL(module_alloc_exec);
17978 +#endif
17979 +#endif
17980 +
17981 #ifdef CONFIG_X86_32
17982 int apply_relocate(Elf32_Shdr *sechdrs,
17983 const char *strtab,
17984 @@ -55,14 +101,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17985 unsigned int i;
17986 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
17987 Elf32_Sym *sym;
17988 - uint32_t *location;
17989 + uint32_t *plocation, location;
17990
17991 DEBUGP("Applying relocate section %u to %u\n", relsec,
17992 sechdrs[relsec].sh_info);
17993 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
17994 /* This is where to make the change */
17995 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
17996 - + rel[i].r_offset;
17997 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
17998 + location = (uint32_t)plocation;
17999 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18000 + plocation = ktla_ktva((void *)plocation);
18001 /* This is the symbol it is referring to. Note that all
18002 undefined symbols have been resolved. */
18003 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18004 @@ -71,11 +119,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18005 switch (ELF32_R_TYPE(rel[i].r_info)) {
18006 case R_386_32:
18007 /* We add the value into the location given */
18008 - *location += sym->st_value;
18009 + pax_open_kernel();
18010 + *plocation += sym->st_value;
18011 + pax_close_kernel();
18012 break;
18013 case R_386_PC32:
18014 /* Add the value, subtract its postition */
18015 - *location += sym->st_value - (uint32_t)location;
18016 + pax_open_kernel();
18017 + *plocation += sym->st_value - location;
18018 + pax_close_kernel();
18019 break;
18020 default:
18021 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18022 @@ -120,21 +172,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18023 case R_X86_64_NONE:
18024 break;
18025 case R_X86_64_64:
18026 + pax_open_kernel();
18027 *(u64 *)loc = val;
18028 + pax_close_kernel();
18029 break;
18030 case R_X86_64_32:
18031 + pax_open_kernel();
18032 *(u32 *)loc = val;
18033 + pax_close_kernel();
18034 if (val != *(u32 *)loc)
18035 goto overflow;
18036 break;
18037 case R_X86_64_32S:
18038 + pax_open_kernel();
18039 *(s32 *)loc = val;
18040 + pax_close_kernel();
18041 if ((s64)val != *(s32 *)loc)
18042 goto overflow;
18043 break;
18044 case R_X86_64_PC32:
18045 val -= (u64)loc;
18046 + pax_open_kernel();
18047 *(u32 *)loc = val;
18048 + pax_close_kernel();
18049 +
18050 #if 0
18051 if ((s64)val != *(s32 *)loc)
18052 goto overflow;
18053 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18054 index 47acaf3..ec48ab6 100644
18055 --- a/arch/x86/kernel/nmi.c
18056 +++ b/arch/x86/kernel/nmi.c
18057 @@ -505,6 +505,17 @@ static inline void nmi_nesting_postprocess(void)
18058 dotraplinkage notrace __kprobes void
18059 do_nmi(struct pt_regs *regs, long error_code)
18060 {
18061 +
18062 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18063 + if (!user_mode(regs)) {
18064 + unsigned long cs = regs->cs & 0xFFFF;
18065 + unsigned long ip = ktva_ktla(regs->ip);
18066 +
18067 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18068 + regs->ip = ip;
18069 + }
18070 +#endif
18071 +
18072 nmi_nesting_preprocess(regs);
18073
18074 nmi_enter();
18075 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18076 index 676b8c7..870ba04 100644
18077 --- a/arch/x86/kernel/paravirt-spinlocks.c
18078 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18079 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18080 arch_spin_lock(lock);
18081 }
18082
18083 -struct pv_lock_ops pv_lock_ops = {
18084 +struct pv_lock_ops pv_lock_ops __read_only = {
18085 #ifdef CONFIG_SMP
18086 .spin_is_locked = __ticket_spin_is_locked,
18087 .spin_is_contended = __ticket_spin_is_contended,
18088 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18089 index d90272e..6bb013b 100644
18090 --- a/arch/x86/kernel/paravirt.c
18091 +++ b/arch/x86/kernel/paravirt.c
18092 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
18093 {
18094 return x;
18095 }
18096 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18097 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18098 +#endif
18099
18100 void __init default_banner(void)
18101 {
18102 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18103 if (opfunc == NULL)
18104 /* If there's no function, patch it with a ud2a (BUG) */
18105 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18106 - else if (opfunc == _paravirt_nop)
18107 + else if (opfunc == (void *)_paravirt_nop)
18108 /* If the operation is a nop, then nop the callsite */
18109 ret = paravirt_patch_nop();
18110
18111 /* identity functions just return their single argument */
18112 - else if (opfunc == _paravirt_ident_32)
18113 + else if (opfunc == (void *)_paravirt_ident_32)
18114 ret = paravirt_patch_ident_32(insnbuf, len);
18115 - else if (opfunc == _paravirt_ident_64)
18116 + else if (opfunc == (void *)_paravirt_ident_64)
18117 ret = paravirt_patch_ident_64(insnbuf, len);
18118 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18119 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18120 + ret = paravirt_patch_ident_64(insnbuf, len);
18121 +#endif
18122
18123 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18124 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18125 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18126 if (insn_len > len || start == NULL)
18127 insn_len = len;
18128 else
18129 - memcpy(insnbuf, start, insn_len);
18130 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18131
18132 return insn_len;
18133 }
18134 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
18135 preempt_enable();
18136 }
18137
18138 -struct pv_info pv_info = {
18139 +struct pv_info pv_info __read_only = {
18140 .name = "bare hardware",
18141 .paravirt_enabled = 0,
18142 .kernel_rpl = 0,
18143 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
18144 #endif
18145 };
18146
18147 -struct pv_init_ops pv_init_ops = {
18148 +struct pv_init_ops pv_init_ops __read_only = {
18149 .patch = native_patch,
18150 };
18151
18152 -struct pv_time_ops pv_time_ops = {
18153 +struct pv_time_ops pv_time_ops __read_only = {
18154 .sched_clock = native_sched_clock,
18155 .steal_clock = native_steal_clock,
18156 };
18157
18158 -struct pv_irq_ops pv_irq_ops = {
18159 +struct pv_irq_ops pv_irq_ops __read_only = {
18160 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18161 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18162 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18163 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
18164 #endif
18165 };
18166
18167 -struct pv_cpu_ops pv_cpu_ops = {
18168 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18169 .cpuid = native_cpuid,
18170 .get_debugreg = native_get_debugreg,
18171 .set_debugreg = native_set_debugreg,
18172 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18173 .end_context_switch = paravirt_nop,
18174 };
18175
18176 -struct pv_apic_ops pv_apic_ops = {
18177 +struct pv_apic_ops pv_apic_ops __read_only = {
18178 #ifdef CONFIG_X86_LOCAL_APIC
18179 .startup_ipi_hook = paravirt_nop,
18180 #endif
18181 };
18182
18183 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18184 +#ifdef CONFIG_X86_32
18185 +#ifdef CONFIG_X86_PAE
18186 +/* 64-bit pagetable entries */
18187 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18188 +#else
18189 /* 32-bit pagetable entries */
18190 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18191 +#endif
18192 #else
18193 /* 64-bit pagetable entries */
18194 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18195 #endif
18196
18197 -struct pv_mmu_ops pv_mmu_ops = {
18198 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18199
18200 .read_cr2 = native_read_cr2,
18201 .write_cr2 = native_write_cr2,
18202 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18203 .make_pud = PTE_IDENT,
18204
18205 .set_pgd = native_set_pgd,
18206 + .set_pgd_batched = native_set_pgd_batched,
18207 #endif
18208 #endif /* PAGETABLE_LEVELS >= 3 */
18209
18210 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18211 },
18212
18213 .set_fixmap = native_set_fixmap,
18214 +
18215 +#ifdef CONFIG_PAX_KERNEXEC
18216 + .pax_open_kernel = native_pax_open_kernel,
18217 + .pax_close_kernel = native_pax_close_kernel,
18218 +#endif
18219 +
18220 };
18221
18222 EXPORT_SYMBOL_GPL(pv_time_ops);
18223 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18224 index 35ccf75..7a15747 100644
18225 --- a/arch/x86/kernel/pci-iommu_table.c
18226 +++ b/arch/x86/kernel/pci-iommu_table.c
18227 @@ -2,7 +2,7 @@
18228 #include <asm/iommu_table.h>
18229 #include <linux/string.h>
18230 #include <linux/kallsyms.h>
18231 -
18232 +#include <linux/sched.h>
18233
18234 #define DEBUG 1
18235
18236 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18237 index 15763af..da59ada 100644
18238 --- a/arch/x86/kernel/process.c
18239 +++ b/arch/x86/kernel/process.c
18240 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
18241
18242 void free_thread_info(struct thread_info *ti)
18243 {
18244 - free_thread_xstate(ti->task);
18245 free_pages((unsigned long)ti, THREAD_ORDER);
18246 }
18247
18248 +static struct kmem_cache *task_struct_cachep;
18249 +
18250 void arch_task_cache_init(void)
18251 {
18252 - task_xstate_cachep =
18253 - kmem_cache_create("task_xstate", xstate_size,
18254 + /* create a slab on which task_structs can be allocated */
18255 + task_struct_cachep =
18256 + kmem_cache_create("task_struct", sizeof(struct task_struct),
18257 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18258 +
18259 + task_xstate_cachep =
18260 + kmem_cache_create("task_xstate", xstate_size,
18261 __alignof__(union thread_xstate),
18262 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18263 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18264 +}
18265 +
18266 +struct task_struct *alloc_task_struct_node(int node)
18267 +{
18268 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18269 +}
18270 +
18271 +void free_task_struct(struct task_struct *task)
18272 +{
18273 + free_thread_xstate(task);
18274 + kmem_cache_free(task_struct_cachep, task);
18275 }
18276
18277 /*
18278 @@ -70,7 +87,7 @@ void exit_thread(void)
18279 unsigned long *bp = t->io_bitmap_ptr;
18280
18281 if (bp) {
18282 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18283 + struct tss_struct *tss = init_tss + get_cpu();
18284
18285 t->io_bitmap_ptr = NULL;
18286 clear_thread_flag(TIF_IO_BITMAP);
18287 @@ -106,7 +123,7 @@ void show_regs_common(void)
18288
18289 printk(KERN_CONT "\n");
18290 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18291 - current->pid, current->comm, print_tainted(),
18292 + task_pid_nr(current), current->comm, print_tainted(),
18293 init_utsname()->release,
18294 (int)strcspn(init_utsname()->version, " "),
18295 init_utsname()->version);
18296 @@ -120,6 +137,9 @@ void flush_thread(void)
18297 {
18298 struct task_struct *tsk = current;
18299
18300 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18301 + loadsegment(gs, 0);
18302 +#endif
18303 flush_ptrace_hw_breakpoint(tsk);
18304 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18305 /*
18306 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18307 regs.di = (unsigned long) arg;
18308
18309 #ifdef CONFIG_X86_32
18310 - regs.ds = __USER_DS;
18311 - regs.es = __USER_DS;
18312 + regs.ds = __KERNEL_DS;
18313 + regs.es = __KERNEL_DS;
18314 regs.fs = __KERNEL_PERCPU;
18315 - regs.gs = __KERNEL_STACK_CANARY;
18316 + savesegment(gs, regs.gs);
18317 #else
18318 regs.ss = __KERNEL_DS;
18319 #endif
18320 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
18321
18322 return ret;
18323 }
18324 -void stop_this_cpu(void *dummy)
18325 +__noreturn void stop_this_cpu(void *dummy)
18326 {
18327 local_irq_disable();
18328 /*
18329 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
18330 }
18331 early_param("idle", idle_setup);
18332
18333 -unsigned long arch_align_stack(unsigned long sp)
18334 +#ifdef CONFIG_PAX_RANDKSTACK
18335 +void pax_randomize_kstack(struct pt_regs *regs)
18336 {
18337 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18338 - sp -= get_random_int() % 8192;
18339 - return sp & ~0xf;
18340 -}
18341 + struct thread_struct *thread = &current->thread;
18342 + unsigned long time;
18343
18344 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18345 -{
18346 - unsigned long range_end = mm->brk + 0x02000000;
18347 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18348 -}
18349 + if (!randomize_va_space)
18350 + return;
18351 +
18352 + if (v8086_mode(regs))
18353 + return;
18354
18355 + rdtscl(time);
18356 +
18357 + /* P4 seems to return a 0 LSB, ignore it */
18358 +#ifdef CONFIG_MPENTIUM4
18359 + time &= 0x3EUL;
18360 + time <<= 2;
18361 +#elif defined(CONFIG_X86_64)
18362 + time &= 0xFUL;
18363 + time <<= 4;
18364 +#else
18365 + time &= 0x1FUL;
18366 + time <<= 3;
18367 +#endif
18368 +
18369 + thread->sp0 ^= time;
18370 + load_sp0(init_tss + smp_processor_id(), thread);
18371 +
18372 +#ifdef CONFIG_X86_64
18373 + percpu_write(kernel_stack, thread->sp0);
18374 +#endif
18375 +}
18376 +#endif
18377 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18378 index c08d1ff..6ae1c81 100644
18379 --- a/arch/x86/kernel/process_32.c
18380 +++ b/arch/x86/kernel/process_32.c
18381 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18382 unsigned long thread_saved_pc(struct task_struct *tsk)
18383 {
18384 return ((unsigned long *)tsk->thread.sp)[3];
18385 +//XXX return tsk->thread.eip;
18386 }
18387
18388 #ifndef CONFIG_SMP
18389 @@ -132,15 +133,14 @@ void __show_regs(struct pt_regs *regs, int all)
18390 unsigned long sp;
18391 unsigned short ss, gs;
18392
18393 - if (user_mode_vm(regs)) {
18394 + if (user_mode(regs)) {
18395 sp = regs->sp;
18396 ss = regs->ss & 0xffff;
18397 - gs = get_user_gs(regs);
18398 } else {
18399 sp = kernel_stack_pointer(regs);
18400 savesegment(ss, ss);
18401 - savesegment(gs, gs);
18402 }
18403 + gs = get_user_gs(regs);
18404
18405 show_regs_common();
18406
18407 @@ -202,13 +202,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18408 struct task_struct *tsk;
18409 int err;
18410
18411 - childregs = task_pt_regs(p);
18412 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18413 *childregs = *regs;
18414 childregs->ax = 0;
18415 childregs->sp = sp;
18416
18417 p->thread.sp = (unsigned long) childregs;
18418 p->thread.sp0 = (unsigned long) (childregs+1);
18419 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18420
18421 p->thread.ip = (unsigned long) ret_from_fork;
18422
18423 @@ -299,7 +300,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18424 struct thread_struct *prev = &prev_p->thread,
18425 *next = &next_p->thread;
18426 int cpu = smp_processor_id();
18427 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18428 + struct tss_struct *tss = init_tss + cpu;
18429 fpu_switch_t fpu;
18430
18431 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18432 @@ -323,6 +324,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18433 */
18434 lazy_save_gs(prev->gs);
18435
18436 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18437 + __set_fs(task_thread_info(next_p)->addr_limit);
18438 +#endif
18439 +
18440 /*
18441 * Load the per-thread Thread-Local Storage descriptor.
18442 */
18443 @@ -353,6 +358,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18444 */
18445 arch_end_context_switch(next_p);
18446
18447 + percpu_write(current_task, next_p);
18448 + percpu_write(current_tinfo, &next_p->tinfo);
18449 +
18450 /*
18451 * Restore %gs if needed (which is common)
18452 */
18453 @@ -361,8 +369,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18454
18455 switch_fpu_finish(next_p, fpu);
18456
18457 - percpu_write(current_task, next_p);
18458 -
18459 return prev_p;
18460 }
18461
18462 @@ -392,4 +398,3 @@ unsigned long get_wchan(struct task_struct *p)
18463 } while (count++ < 16);
18464 return 0;
18465 }
18466 -
18467 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18468 index cfa5c90..4facd28 100644
18469 --- a/arch/x86/kernel/process_64.c
18470 +++ b/arch/x86/kernel/process_64.c
18471 @@ -89,7 +89,7 @@ static void __exit_idle(void)
18472 void exit_idle(void)
18473 {
18474 /* idle loop has pid 0 */
18475 - if (current->pid)
18476 + if (task_pid_nr(current))
18477 return;
18478 __exit_idle();
18479 }
18480 @@ -270,8 +270,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18481 struct pt_regs *childregs;
18482 struct task_struct *me = current;
18483
18484 - childregs = ((struct pt_regs *)
18485 - (THREAD_SIZE + task_stack_page(p))) - 1;
18486 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18487 *childregs = *regs;
18488
18489 childregs->ax = 0;
18490 @@ -283,6 +282,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18491 p->thread.sp = (unsigned long) childregs;
18492 p->thread.sp0 = (unsigned long) (childregs+1);
18493 p->thread.usersp = me->thread.usersp;
18494 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18495
18496 set_tsk_thread_flag(p, TIF_FORK);
18497
18498 @@ -385,7 +385,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18499 struct thread_struct *prev = &prev_p->thread;
18500 struct thread_struct *next = &next_p->thread;
18501 int cpu = smp_processor_id();
18502 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18503 + struct tss_struct *tss = init_tss + cpu;
18504 unsigned fsindex, gsindex;
18505 fpu_switch_t fpu;
18506
18507 @@ -467,10 +467,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18508 prev->usersp = percpu_read(old_rsp);
18509 percpu_write(old_rsp, next->usersp);
18510 percpu_write(current_task, next_p);
18511 + percpu_write(current_tinfo, &next_p->tinfo);
18512
18513 - percpu_write(kernel_stack,
18514 - (unsigned long)task_stack_page(next_p) +
18515 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18516 + percpu_write(kernel_stack, next->sp0);
18517
18518 /*
18519 * Now maybe reload the debug registers and handle I/O bitmaps
18520 @@ -525,12 +524,11 @@ unsigned long get_wchan(struct task_struct *p)
18521 if (!p || p == current || p->state == TASK_RUNNING)
18522 return 0;
18523 stack = (unsigned long)task_stack_page(p);
18524 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18525 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18526 return 0;
18527 fp = *(u64 *)(p->thread.sp);
18528 do {
18529 - if (fp < (unsigned long)stack ||
18530 - fp >= (unsigned long)stack+THREAD_SIZE)
18531 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18532 return 0;
18533 ip = *(u64 *)(fp+8);
18534 if (!in_sched_functions(ip))
18535 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18536 index 5026738..e1b5aa8 100644
18537 --- a/arch/x86/kernel/ptrace.c
18538 +++ b/arch/x86/kernel/ptrace.c
18539 @@ -792,6 +792,10 @@ static int ioperm_active(struct task_struct *target,
18540 static int ioperm_get(struct task_struct *target,
18541 const struct user_regset *regset,
18542 unsigned int pos, unsigned int count,
18543 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
18544 +static int ioperm_get(struct task_struct *target,
18545 + const struct user_regset *regset,
18546 + unsigned int pos, unsigned int count,
18547 void *kbuf, void __user *ubuf)
18548 {
18549 if (!target->thread.io_bitmap_ptr)
18550 @@ -823,7 +827,7 @@ long arch_ptrace(struct task_struct *child, long request,
18551 unsigned long addr, unsigned long data)
18552 {
18553 int ret;
18554 - unsigned long __user *datap = (unsigned long __user *)data;
18555 + unsigned long __user *datap = (__force unsigned long __user *)data;
18556
18557 switch (request) {
18558 /* read the word at location addr in the USER area. */
18559 @@ -908,14 +912,14 @@ long arch_ptrace(struct task_struct *child, long request,
18560 if ((int) addr < 0)
18561 return -EIO;
18562 ret = do_get_thread_area(child, addr,
18563 - (struct user_desc __user *)data);
18564 + (__force struct user_desc __user *) data);
18565 break;
18566
18567 case PTRACE_SET_THREAD_AREA:
18568 if ((int) addr < 0)
18569 return -EIO;
18570 ret = do_set_thread_area(child, addr,
18571 - (struct user_desc __user *)data, 0);
18572 + (__force struct user_desc __user *) data, 0);
18573 break;
18574 #endif
18575
18576 @@ -1332,7 +1336,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18577 memset(info, 0, sizeof(*info));
18578 info->si_signo = SIGTRAP;
18579 info->si_code = si_code;
18580 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18581 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18582 }
18583
18584 void user_single_step_siginfo(struct task_struct *tsk,
18585 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18586 index 42eb330..139955c 100644
18587 --- a/arch/x86/kernel/pvclock.c
18588 +++ b/arch/x86/kernel/pvclock.c
18589 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18590 return pv_tsc_khz;
18591 }
18592
18593 -static atomic64_t last_value = ATOMIC64_INIT(0);
18594 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18595
18596 void pvclock_resume(void)
18597 {
18598 - atomic64_set(&last_value, 0);
18599 + atomic64_set_unchecked(&last_value, 0);
18600 }
18601
18602 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18603 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18604 * updating at the same time, and one of them could be slightly behind,
18605 * making the assumption that last_value always go forward fail to hold.
18606 */
18607 - last = atomic64_read(&last_value);
18608 + last = atomic64_read_unchecked(&last_value);
18609 do {
18610 if (ret < last)
18611 return last;
18612 - last = atomic64_cmpxchg(&last_value, last, ret);
18613 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18614 } while (unlikely(last != ret));
18615
18616 return ret;
18617 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18618 index d840e69..98e9581 100644
18619 --- a/arch/x86/kernel/reboot.c
18620 +++ b/arch/x86/kernel/reboot.c
18621 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18622 EXPORT_SYMBOL(pm_power_off);
18623
18624 static const struct desc_ptr no_idt = {};
18625 -static int reboot_mode;
18626 +static unsigned short reboot_mode;
18627 enum reboot_type reboot_type = BOOT_ACPI;
18628 int reboot_force;
18629
18630 @@ -335,13 +335,17 @@ core_initcall(reboot_init);
18631 extern const unsigned char machine_real_restart_asm[];
18632 extern const u64 machine_real_restart_gdt[3];
18633
18634 -void machine_real_restart(unsigned int type)
18635 +__noreturn void machine_real_restart(unsigned int type)
18636 {
18637 void *restart_va;
18638 unsigned long restart_pa;
18639 - void (*restart_lowmem)(unsigned int);
18640 + void (* __noreturn restart_lowmem)(unsigned int);
18641 u64 *lowmem_gdt;
18642
18643 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18644 + struct desc_struct *gdt;
18645 +#endif
18646 +
18647 local_irq_disable();
18648
18649 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18650 @@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18651 boot)". This seems like a fairly standard thing that gets set by
18652 REBOOT.COM programs, and the previous reset routine did this
18653 too. */
18654 - *((unsigned short *)0x472) = reboot_mode;
18655 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18656
18657 /* Patch the GDT in the low memory trampoline */
18658 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18659
18660 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18661 restart_pa = virt_to_phys(restart_va);
18662 - restart_lowmem = (void (*)(unsigned int))restart_pa;
18663 + restart_lowmem = (void *)restart_pa;
18664
18665 /* GDT[0]: GDT self-pointer */
18666 lowmem_gdt[0] =
18667 @@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18668 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18669
18670 /* Jump to the identity-mapped low memory code */
18671 +
18672 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18673 + gdt = get_cpu_gdt_table(smp_processor_id());
18674 + pax_open_kernel();
18675 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18676 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18677 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18678 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18679 +#endif
18680 +#ifdef CONFIG_PAX_KERNEXEC
18681 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18682 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18683 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18684 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18685 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18686 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18687 +#endif
18688 + pax_close_kernel();
18689 +#endif
18690 +
18691 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18692 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18693 + unreachable();
18694 +#else
18695 restart_lowmem(type);
18696 +#endif
18697 +
18698 }
18699 #ifdef CONFIG_APM_MODULE
18700 EXPORT_SYMBOL(machine_real_restart);
18701 @@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18702 * try to force a triple fault and then cycle between hitting the keyboard
18703 * controller and doing that
18704 */
18705 -static void native_machine_emergency_restart(void)
18706 +__noreturn static void native_machine_emergency_restart(void)
18707 {
18708 int i;
18709 int attempt = 0;
18710 @@ -680,13 +710,13 @@ void native_machine_shutdown(void)
18711 #endif
18712 }
18713
18714 -static void __machine_emergency_restart(int emergency)
18715 +static __noreturn void __machine_emergency_restart(int emergency)
18716 {
18717 reboot_emergency = emergency;
18718 machine_ops.emergency_restart();
18719 }
18720
18721 -static void native_machine_restart(char *__unused)
18722 +static __noreturn void native_machine_restart(char *__unused)
18723 {
18724 printk("machine restart\n");
18725
18726 @@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
18727 __machine_emergency_restart(0);
18728 }
18729
18730 -static void native_machine_halt(void)
18731 +static __noreturn void native_machine_halt(void)
18732 {
18733 /* stop other cpus and apics */
18734 machine_shutdown();
18735 @@ -706,7 +736,7 @@ static void native_machine_halt(void)
18736 stop_this_cpu(NULL);
18737 }
18738
18739 -static void native_machine_power_off(void)
18740 +__noreturn static void native_machine_power_off(void)
18741 {
18742 if (pm_power_off) {
18743 if (!reboot_force)
18744 @@ -715,6 +745,7 @@ static void native_machine_power_off(void)
18745 }
18746 /* a fallback in case there is no PM info available */
18747 tboot_shutdown(TB_SHUTDOWN_HALT);
18748 + unreachable();
18749 }
18750
18751 struct machine_ops machine_ops = {
18752 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18753 index 7a6f3b3..bed145d7 100644
18754 --- a/arch/x86/kernel/relocate_kernel_64.S
18755 +++ b/arch/x86/kernel/relocate_kernel_64.S
18756 @@ -11,6 +11,7 @@
18757 #include <asm/kexec.h>
18758 #include <asm/processor-flags.h>
18759 #include <asm/pgtable_types.h>
18760 +#include <asm/alternative-asm.h>
18761
18762 /*
18763 * Must be relocatable PIC code callable as a C function
18764 @@ -160,13 +161,14 @@ identity_mapped:
18765 xorq %rbp, %rbp
18766 xorq %r8, %r8
18767 xorq %r9, %r9
18768 - xorq %r10, %r9
18769 + xorq %r10, %r10
18770 xorq %r11, %r11
18771 xorq %r12, %r12
18772 xorq %r13, %r13
18773 xorq %r14, %r14
18774 xorq %r15, %r15
18775
18776 + pax_force_retaddr 0, 1
18777 ret
18778
18779 1:
18780 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18781 index d7d5099..28555d0 100644
18782 --- a/arch/x86/kernel/setup.c
18783 +++ b/arch/x86/kernel/setup.c
18784 @@ -448,7 +448,7 @@ static void __init parse_setup_data(void)
18785
18786 switch (data->type) {
18787 case SETUP_E820_EXT:
18788 - parse_e820_ext(data);
18789 + parse_e820_ext((struct setup_data __force_kernel *)data);
18790 break;
18791 case SETUP_DTB:
18792 add_dtb(pa_data);
18793 @@ -649,7 +649,7 @@ static void __init trim_bios_range(void)
18794 * area (640->1Mb) as ram even though it is not.
18795 * take them out.
18796 */
18797 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18798 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18799 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18800 }
18801
18802 @@ -767,14 +767,14 @@ void __init setup_arch(char **cmdline_p)
18803
18804 if (!boot_params.hdr.root_flags)
18805 root_mountflags &= ~MS_RDONLY;
18806 - init_mm.start_code = (unsigned long) _text;
18807 - init_mm.end_code = (unsigned long) _etext;
18808 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18809 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18810 init_mm.end_data = (unsigned long) _edata;
18811 init_mm.brk = _brk_end;
18812
18813 - code_resource.start = virt_to_phys(_text);
18814 - code_resource.end = virt_to_phys(_etext)-1;
18815 - data_resource.start = virt_to_phys(_etext);
18816 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18817 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18818 + data_resource.start = virt_to_phys(_sdata);
18819 data_resource.end = virt_to_phys(_edata)-1;
18820 bss_resource.start = virt_to_phys(&__bss_start);
18821 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18822 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18823 index 71f4727..217419b 100644
18824 --- a/arch/x86/kernel/setup_percpu.c
18825 +++ b/arch/x86/kernel/setup_percpu.c
18826 @@ -21,19 +21,17 @@
18827 #include <asm/cpu.h>
18828 #include <asm/stackprotector.h>
18829
18830 -DEFINE_PER_CPU(int, cpu_number);
18831 +#ifdef CONFIG_SMP
18832 +DEFINE_PER_CPU(unsigned int, cpu_number);
18833 EXPORT_PER_CPU_SYMBOL(cpu_number);
18834 +#endif
18835
18836 -#ifdef CONFIG_X86_64
18837 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18838 -#else
18839 -#define BOOT_PERCPU_OFFSET 0
18840 -#endif
18841
18842 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18843 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18844
18845 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18846 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18847 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18848 };
18849 EXPORT_SYMBOL(__per_cpu_offset);
18850 @@ -96,6 +94,8 @@ static bool __init pcpu_need_numa(void)
18851 * Pointer to the allocated area on success, NULL on failure.
18852 */
18853 static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18854 + unsigned long align) __size_overflow(2);
18855 +static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18856 unsigned long align)
18857 {
18858 const unsigned long goal = __pa(MAX_DMA_ADDRESS);
18859 @@ -124,6 +124,8 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18860 /*
18861 * Helpers for first chunk memory allocation
18862 */
18863 +static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align) __size_overflow(2);
18864 +
18865 static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
18866 {
18867 return pcpu_alloc_bootmem(cpu, size, align);
18868 @@ -155,10 +157,10 @@ static inline void setup_percpu_segment(int cpu)
18869 {
18870 #ifdef CONFIG_X86_32
18871 struct desc_struct gdt;
18872 + unsigned long base = per_cpu_offset(cpu);
18873
18874 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18875 - 0x2 | DESCTYPE_S, 0x8);
18876 - gdt.s = 1;
18877 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18878 + 0x83 | DESCTYPE_S, 0xC);
18879 write_gdt_entry(get_cpu_gdt_table(cpu),
18880 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18881 #endif
18882 @@ -207,6 +209,11 @@ void __init setup_per_cpu_areas(void)
18883 /* alrighty, percpu areas up and running */
18884 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18885 for_each_possible_cpu(cpu) {
18886 +#ifdef CONFIG_CC_STACKPROTECTOR
18887 +#ifdef CONFIG_X86_32
18888 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
18889 +#endif
18890 +#endif
18891 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18892 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18893 per_cpu(cpu_number, cpu) = cpu;
18894 @@ -247,6 +254,12 @@ void __init setup_per_cpu_areas(void)
18895 */
18896 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18897 #endif
18898 +#ifdef CONFIG_CC_STACKPROTECTOR
18899 +#ifdef CONFIG_X86_32
18900 + if (!cpu)
18901 + per_cpu(stack_canary.canary, cpu) = canary;
18902 +#endif
18903 +#endif
18904 /*
18905 * Up to this point, the boot CPU has been using .init.data
18906 * area. Reload any changed state for the boot CPU.
18907 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18908 index 46a01bd..2e88e6d 100644
18909 --- a/arch/x86/kernel/signal.c
18910 +++ b/arch/x86/kernel/signal.c
18911 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
18912 * Align the stack pointer according to the i386 ABI,
18913 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18914 */
18915 - sp = ((sp + 4) & -16ul) - 4;
18916 + sp = ((sp - 12) & -16ul) - 4;
18917 #else /* !CONFIG_X86_32 */
18918 sp = round_down(sp, 16) - 8;
18919 #endif
18920 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18921 * Return an always-bogus address instead so we will die with SIGSEGV.
18922 */
18923 if (onsigstack && !likely(on_sig_stack(sp)))
18924 - return (void __user *)-1L;
18925 + return (__force void __user *)-1L;
18926
18927 /* save i387 state */
18928 if (used_math() && save_i387_xstate(*fpstate) < 0)
18929 - return (void __user *)-1L;
18930 + return (__force void __user *)-1L;
18931
18932 return (void __user *)sp;
18933 }
18934 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18935 }
18936
18937 if (current->mm->context.vdso)
18938 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18939 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18940 else
18941 - restorer = &frame->retcode;
18942 + restorer = (void __user *)&frame->retcode;
18943 if (ka->sa.sa_flags & SA_RESTORER)
18944 restorer = ka->sa.sa_restorer;
18945
18946 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18947 * reasons and because gdb uses it as a signature to notice
18948 * signal handler stack frames.
18949 */
18950 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
18951 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
18952
18953 if (err)
18954 return -EFAULT;
18955 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18956 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
18957
18958 /* Set up to return from userspace. */
18959 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18960 + if (current->mm->context.vdso)
18961 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18962 + else
18963 + restorer = (void __user *)&frame->retcode;
18964 if (ka->sa.sa_flags & SA_RESTORER)
18965 restorer = ka->sa.sa_restorer;
18966 put_user_ex(restorer, &frame->pretcode);
18967 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18968 * reasons and because gdb uses it as a signature to notice
18969 * signal handler stack frames.
18970 */
18971 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
18972 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
18973 } put_user_catch(err);
18974
18975 if (err)
18976 @@ -765,7 +768,7 @@ static void do_signal(struct pt_regs *regs)
18977 * X86_32: vm86 regs switched out by assembly code before reaching
18978 * here, so testing against kernel CS suffices.
18979 */
18980 - if (!user_mode(regs))
18981 + if (!user_mode_novm(regs))
18982 return;
18983
18984 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
18985 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
18986 index 66d250c..f1b10bd 100644
18987 --- a/arch/x86/kernel/smpboot.c
18988 +++ b/arch/x86/kernel/smpboot.c
18989 @@ -715,17 +715,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
18990 set_idle_for_cpu(cpu, c_idle.idle);
18991 do_rest:
18992 per_cpu(current_task, cpu) = c_idle.idle;
18993 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
18994 #ifdef CONFIG_X86_32
18995 /* Stack for startup_32 can be just as for start_secondary onwards */
18996 irq_ctx_init(cpu);
18997 #else
18998 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
18999 initial_gs = per_cpu_offset(cpu);
19000 - per_cpu(kernel_stack, cpu) =
19001 - (unsigned long)task_stack_page(c_idle.idle) -
19002 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19003 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19004 #endif
19005 +
19006 + pax_open_kernel();
19007 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19008 + pax_close_kernel();
19009 +
19010 initial_code = (unsigned long)start_secondary;
19011 stack_start = c_idle.idle->thread.sp;
19012
19013 @@ -868,6 +871,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19014
19015 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19016
19017 +#ifdef CONFIG_PAX_PER_CPU_PGD
19018 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19019 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19020 + KERNEL_PGD_PTRS);
19021 +#endif
19022 +
19023 err = do_boot_cpu(apicid, cpu);
19024 if (err) {
19025 pr_debug("do_boot_cpu failed %d\n", err);
19026 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19027 index c346d11..d43b163 100644
19028 --- a/arch/x86/kernel/step.c
19029 +++ b/arch/x86/kernel/step.c
19030 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19031 struct desc_struct *desc;
19032 unsigned long base;
19033
19034 - seg &= ~7UL;
19035 + seg >>= 3;
19036
19037 mutex_lock(&child->mm->context.lock);
19038 - if (unlikely((seg >> 3) >= child->mm->context.size))
19039 + if (unlikely(seg >= child->mm->context.size))
19040 addr = -1L; /* bogus selector, access would fault */
19041 else {
19042 desc = child->mm->context.ldt + seg;
19043 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19044 addr += base;
19045 }
19046 mutex_unlock(&child->mm->context.lock);
19047 - }
19048 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19049 + addr = ktla_ktva(addr);
19050
19051 return addr;
19052 }
19053 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19054 unsigned char opcode[15];
19055 unsigned long addr = convert_ip_to_linear(child, regs);
19056
19057 + if (addr == -EINVAL)
19058 + return 0;
19059 +
19060 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19061 for (i = 0; i < copied; i++) {
19062 switch (opcode[i]) {
19063 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19064 index 0b0cb5f..db6b9ed 100644
19065 --- a/arch/x86/kernel/sys_i386_32.c
19066 +++ b/arch/x86/kernel/sys_i386_32.c
19067 @@ -24,17 +24,224 @@
19068
19069 #include <asm/syscalls.h>
19070
19071 -/*
19072 - * Do a system call from kernel instead of calling sys_execve so we
19073 - * end up with proper pt_regs.
19074 - */
19075 -int kernel_execve(const char *filename,
19076 - const char *const argv[],
19077 - const char *const envp[])
19078 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19079 {
19080 - long __res;
19081 - asm volatile ("int $0x80"
19082 - : "=a" (__res)
19083 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19084 - return __res;
19085 + unsigned long pax_task_size = TASK_SIZE;
19086 +
19087 +#ifdef CONFIG_PAX_SEGMEXEC
19088 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19089 + pax_task_size = SEGMEXEC_TASK_SIZE;
19090 +#endif
19091 +
19092 + if (len > pax_task_size || addr > pax_task_size - len)
19093 + return -EINVAL;
19094 +
19095 + return 0;
19096 +}
19097 +
19098 +unsigned long
19099 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19100 + unsigned long len, unsigned long pgoff, unsigned long flags)
19101 +{
19102 + struct mm_struct *mm = current->mm;
19103 + struct vm_area_struct *vma;
19104 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19105 +
19106 +#ifdef CONFIG_PAX_SEGMEXEC
19107 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19108 + pax_task_size = SEGMEXEC_TASK_SIZE;
19109 +#endif
19110 +
19111 + pax_task_size -= PAGE_SIZE;
19112 +
19113 + if (len > pax_task_size)
19114 + return -ENOMEM;
19115 +
19116 + if (flags & MAP_FIXED)
19117 + return addr;
19118 +
19119 +#ifdef CONFIG_PAX_RANDMMAP
19120 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19121 +#endif
19122 +
19123 + if (addr) {
19124 + addr = PAGE_ALIGN(addr);
19125 + if (pax_task_size - len >= addr) {
19126 + vma = find_vma(mm, addr);
19127 + if (check_heap_stack_gap(vma, addr, len))
19128 + return addr;
19129 + }
19130 + }
19131 + if (len > mm->cached_hole_size) {
19132 + start_addr = addr = mm->free_area_cache;
19133 + } else {
19134 + start_addr = addr = mm->mmap_base;
19135 + mm->cached_hole_size = 0;
19136 + }
19137 +
19138 +#ifdef CONFIG_PAX_PAGEEXEC
19139 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19140 + start_addr = 0x00110000UL;
19141 +
19142 +#ifdef CONFIG_PAX_RANDMMAP
19143 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19144 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19145 +#endif
19146 +
19147 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19148 + start_addr = addr = mm->mmap_base;
19149 + else
19150 + addr = start_addr;
19151 + }
19152 +#endif
19153 +
19154 +full_search:
19155 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19156 + /* At this point: (!vma || addr < vma->vm_end). */
19157 + if (pax_task_size - len < addr) {
19158 + /*
19159 + * Start a new search - just in case we missed
19160 + * some holes.
19161 + */
19162 + if (start_addr != mm->mmap_base) {
19163 + start_addr = addr = mm->mmap_base;
19164 + mm->cached_hole_size = 0;
19165 + goto full_search;
19166 + }
19167 + return -ENOMEM;
19168 + }
19169 + if (check_heap_stack_gap(vma, addr, len))
19170 + break;
19171 + if (addr + mm->cached_hole_size < vma->vm_start)
19172 + mm->cached_hole_size = vma->vm_start - addr;
19173 + addr = vma->vm_end;
19174 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19175 + start_addr = addr = mm->mmap_base;
19176 + mm->cached_hole_size = 0;
19177 + goto full_search;
19178 + }
19179 + }
19180 +
19181 + /*
19182 + * Remember the place where we stopped the search:
19183 + */
19184 + mm->free_area_cache = addr + len;
19185 + return addr;
19186 +}
19187 +
19188 +unsigned long
19189 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19190 + const unsigned long len, const unsigned long pgoff,
19191 + const unsigned long flags)
19192 +{
19193 + struct vm_area_struct *vma;
19194 + struct mm_struct *mm = current->mm;
19195 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19196 +
19197 +#ifdef CONFIG_PAX_SEGMEXEC
19198 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19199 + pax_task_size = SEGMEXEC_TASK_SIZE;
19200 +#endif
19201 +
19202 + pax_task_size -= PAGE_SIZE;
19203 +
19204 + /* requested length too big for entire address space */
19205 + if (len > pax_task_size)
19206 + return -ENOMEM;
19207 +
19208 + if (flags & MAP_FIXED)
19209 + return addr;
19210 +
19211 +#ifdef CONFIG_PAX_PAGEEXEC
19212 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19213 + goto bottomup;
19214 +#endif
19215 +
19216 +#ifdef CONFIG_PAX_RANDMMAP
19217 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19218 +#endif
19219 +
19220 + /* requesting a specific address */
19221 + if (addr) {
19222 + addr = PAGE_ALIGN(addr);
19223 + if (pax_task_size - len >= addr) {
19224 + vma = find_vma(mm, addr);
19225 + if (check_heap_stack_gap(vma, addr, len))
19226 + return addr;
19227 + }
19228 + }
19229 +
19230 + /* check if free_area_cache is useful for us */
19231 + if (len <= mm->cached_hole_size) {
19232 + mm->cached_hole_size = 0;
19233 + mm->free_area_cache = mm->mmap_base;
19234 + }
19235 +
19236 + /* either no address requested or can't fit in requested address hole */
19237 + addr = mm->free_area_cache;
19238 +
19239 + /* make sure it can fit in the remaining address space */
19240 + if (addr > len) {
19241 + vma = find_vma(mm, addr-len);
19242 + if (check_heap_stack_gap(vma, addr - len, len))
19243 + /* remember the address as a hint for next time */
19244 + return (mm->free_area_cache = addr-len);
19245 + }
19246 +
19247 + if (mm->mmap_base < len)
19248 + goto bottomup;
19249 +
19250 + addr = mm->mmap_base-len;
19251 +
19252 + do {
19253 + /*
19254 + * Lookup failure means no vma is above this address,
19255 + * else if new region fits below vma->vm_start,
19256 + * return with success:
19257 + */
19258 + vma = find_vma(mm, addr);
19259 + if (check_heap_stack_gap(vma, addr, len))
19260 + /* remember the address as a hint for next time */
19261 + return (mm->free_area_cache = addr);
19262 +
19263 + /* remember the largest hole we saw so far */
19264 + if (addr + mm->cached_hole_size < vma->vm_start)
19265 + mm->cached_hole_size = vma->vm_start - addr;
19266 +
19267 + /* try just below the current vma->vm_start */
19268 + addr = skip_heap_stack_gap(vma, len);
19269 + } while (!IS_ERR_VALUE(addr));
19270 +
19271 +bottomup:
19272 + /*
19273 + * A failed mmap() very likely causes application failure,
19274 + * so fall back to the bottom-up function here. This scenario
19275 + * can happen with large stack limits and large mmap()
19276 + * allocations.
19277 + */
19278 +
19279 +#ifdef CONFIG_PAX_SEGMEXEC
19280 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19281 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19282 + else
19283 +#endif
19284 +
19285 + mm->mmap_base = TASK_UNMAPPED_BASE;
19286 +
19287 +#ifdef CONFIG_PAX_RANDMMAP
19288 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19289 + mm->mmap_base += mm->delta_mmap;
19290 +#endif
19291 +
19292 + mm->free_area_cache = mm->mmap_base;
19293 + mm->cached_hole_size = ~0UL;
19294 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19295 + /*
19296 + * Restore the topdown base:
19297 + */
19298 + mm->mmap_base = base;
19299 + mm->free_area_cache = base;
19300 + mm->cached_hole_size = ~0UL;
19301 +
19302 + return addr;
19303 }
19304 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19305 index 0514890..3dbebce 100644
19306 --- a/arch/x86/kernel/sys_x86_64.c
19307 +++ b/arch/x86/kernel/sys_x86_64.c
19308 @@ -95,8 +95,8 @@ out:
19309 return error;
19310 }
19311
19312 -static void find_start_end(unsigned long flags, unsigned long *begin,
19313 - unsigned long *end)
19314 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19315 + unsigned long *begin, unsigned long *end)
19316 {
19317 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
19318 unsigned long new_begin;
19319 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19320 *begin = new_begin;
19321 }
19322 } else {
19323 - *begin = TASK_UNMAPPED_BASE;
19324 + *begin = mm->mmap_base;
19325 *end = TASK_SIZE;
19326 }
19327 }
19328 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19329 if (flags & MAP_FIXED)
19330 return addr;
19331
19332 - find_start_end(flags, &begin, &end);
19333 + find_start_end(mm, flags, &begin, &end);
19334
19335 if (len > end)
19336 return -ENOMEM;
19337
19338 +#ifdef CONFIG_PAX_RANDMMAP
19339 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19340 +#endif
19341 +
19342 if (addr) {
19343 addr = PAGE_ALIGN(addr);
19344 vma = find_vma(mm, addr);
19345 - if (end - len >= addr &&
19346 - (!vma || addr + len <= vma->vm_start))
19347 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19348 return addr;
19349 }
19350 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
19351 @@ -172,7 +175,7 @@ full_search:
19352 }
19353 return -ENOMEM;
19354 }
19355 - if (!vma || addr + len <= vma->vm_start) {
19356 + if (check_heap_stack_gap(vma, addr, len)) {
19357 /*
19358 * Remember the place where we stopped the search:
19359 */
19360 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19361 {
19362 struct vm_area_struct *vma;
19363 struct mm_struct *mm = current->mm;
19364 - unsigned long addr = addr0;
19365 + unsigned long base = mm->mmap_base, addr = addr0;
19366
19367 /* requested length too big for entire address space */
19368 if (len > TASK_SIZE)
19369 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19370 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
19371 goto bottomup;
19372
19373 +#ifdef CONFIG_PAX_RANDMMAP
19374 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19375 +#endif
19376 +
19377 /* requesting a specific address */
19378 if (addr) {
19379 addr = PAGE_ALIGN(addr);
19380 - vma = find_vma(mm, addr);
19381 - if (TASK_SIZE - len >= addr &&
19382 - (!vma || addr + len <= vma->vm_start))
19383 - return addr;
19384 + if (TASK_SIZE - len >= addr) {
19385 + vma = find_vma(mm, addr);
19386 + if (check_heap_stack_gap(vma, addr, len))
19387 + return addr;
19388 + }
19389 }
19390
19391 /* check if free_area_cache is useful for us */
19392 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19393 ALIGN_TOPDOWN);
19394
19395 vma = find_vma(mm, tmp_addr);
19396 - if (!vma || tmp_addr + len <= vma->vm_start)
19397 + if (check_heap_stack_gap(vma, tmp_addr, len))
19398 /* remember the address as a hint for next time */
19399 return mm->free_area_cache = tmp_addr;
19400 }
19401 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19402 * return with success:
19403 */
19404 vma = find_vma(mm, addr);
19405 - if (!vma || addr+len <= vma->vm_start)
19406 + if (check_heap_stack_gap(vma, addr, len))
19407 /* remember the address as a hint for next time */
19408 return mm->free_area_cache = addr;
19409
19410 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19411 mm->cached_hole_size = vma->vm_start - addr;
19412
19413 /* try just below the current vma->vm_start */
19414 - addr = vma->vm_start-len;
19415 - } while (len < vma->vm_start);
19416 + addr = skip_heap_stack_gap(vma, len);
19417 + } while (!IS_ERR_VALUE(addr));
19418
19419 bottomup:
19420 /*
19421 @@ -270,13 +278,21 @@ bottomup:
19422 * can happen with large stack limits and large mmap()
19423 * allocations.
19424 */
19425 + mm->mmap_base = TASK_UNMAPPED_BASE;
19426 +
19427 +#ifdef CONFIG_PAX_RANDMMAP
19428 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19429 + mm->mmap_base += mm->delta_mmap;
19430 +#endif
19431 +
19432 + mm->free_area_cache = mm->mmap_base;
19433 mm->cached_hole_size = ~0UL;
19434 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19435 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19436 /*
19437 * Restore the topdown base:
19438 */
19439 - mm->free_area_cache = mm->mmap_base;
19440 + mm->mmap_base = base;
19441 + mm->free_area_cache = base;
19442 mm->cached_hole_size = ~0UL;
19443
19444 return addr;
19445 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19446 index e2410e2..4fe3fbc 100644
19447 --- a/arch/x86/kernel/tboot.c
19448 +++ b/arch/x86/kernel/tboot.c
19449 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19450
19451 void tboot_shutdown(u32 shutdown_type)
19452 {
19453 - void (*shutdown)(void);
19454 + void (* __noreturn shutdown)(void);
19455
19456 if (!tboot_enabled())
19457 return;
19458 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19459
19460 switch_to_tboot_pt();
19461
19462 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19463 + shutdown = (void *)tboot->shutdown_entry;
19464 shutdown();
19465
19466 /* should not reach here */
19467 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19468 tboot_shutdown(acpi_shutdown_map[sleep_state]);
19469 }
19470
19471 -static atomic_t ap_wfs_count;
19472 +static atomic_unchecked_t ap_wfs_count;
19473
19474 static int tboot_wait_for_aps(int num_aps)
19475 {
19476 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19477 {
19478 switch (action) {
19479 case CPU_DYING:
19480 - atomic_inc(&ap_wfs_count);
19481 + atomic_inc_unchecked(&ap_wfs_count);
19482 if (num_online_cpus() == 1)
19483 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19484 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19485 return NOTIFY_BAD;
19486 break;
19487 }
19488 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
19489
19490 tboot_create_trampoline();
19491
19492 - atomic_set(&ap_wfs_count, 0);
19493 + atomic_set_unchecked(&ap_wfs_count, 0);
19494 register_hotcpu_notifier(&tboot_cpu_notifier);
19495 return 0;
19496 }
19497 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19498 index dd5fbf4..b7f2232 100644
19499 --- a/arch/x86/kernel/time.c
19500 +++ b/arch/x86/kernel/time.c
19501 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19502 {
19503 unsigned long pc = instruction_pointer(regs);
19504
19505 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19506 + if (!user_mode(regs) && in_lock_functions(pc)) {
19507 #ifdef CONFIG_FRAME_POINTER
19508 - return *(unsigned long *)(regs->bp + sizeof(long));
19509 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19510 #else
19511 unsigned long *sp =
19512 (unsigned long *)kernel_stack_pointer(regs);
19513 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19514 * or above a saved flags. Eflags has bits 22-31 zero,
19515 * kernel addresses don't.
19516 */
19517 +
19518 +#ifdef CONFIG_PAX_KERNEXEC
19519 + return ktla_ktva(sp[0]);
19520 +#else
19521 if (sp[0] >> 22)
19522 return sp[0];
19523 if (sp[1] >> 22)
19524 return sp[1];
19525 #endif
19526 +
19527 +#endif
19528 }
19529 return pc;
19530 }
19531 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19532 index bcfec2d..8f88b4a 100644
19533 --- a/arch/x86/kernel/tls.c
19534 +++ b/arch/x86/kernel/tls.c
19535 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19536 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19537 return -EINVAL;
19538
19539 +#ifdef CONFIG_PAX_SEGMEXEC
19540 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19541 + return -EINVAL;
19542 +#endif
19543 +
19544 set_tls_desc(p, idx, &info, 1);
19545
19546 return 0;
19547 diff --git a/arch/x86/kernel/tls.h b/arch/x86/kernel/tls.h
19548 index 2f083a2..7d3fecc 100644
19549 --- a/arch/x86/kernel/tls.h
19550 +++ b/arch/x86/kernel/tls.h
19551 @@ -16,6 +16,6 @@
19552
19553 extern user_regset_active_fn regset_tls_active;
19554 extern user_regset_get_fn regset_tls_get;
19555 -extern user_regset_set_fn regset_tls_set;
19556 +extern user_regset_set_fn regset_tls_set __size_overflow(4);
19557
19558 #endif /* _ARCH_X86_KERNEL_TLS_H */
19559 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19560 index 451c0a7..e57f551 100644
19561 --- a/arch/x86/kernel/trampoline_32.S
19562 +++ b/arch/x86/kernel/trampoline_32.S
19563 @@ -32,6 +32,12 @@
19564 #include <asm/segment.h>
19565 #include <asm/page_types.h>
19566
19567 +#ifdef CONFIG_PAX_KERNEXEC
19568 +#define ta(X) (X)
19569 +#else
19570 +#define ta(X) ((X) - __PAGE_OFFSET)
19571 +#endif
19572 +
19573 #ifdef CONFIG_SMP
19574
19575 .section ".x86_trampoline","a"
19576 @@ -62,7 +68,7 @@ r_base = .
19577 inc %ax # protected mode (PE) bit
19578 lmsw %ax # into protected mode
19579 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19580 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19581 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
19582
19583 # These need to be in the same 64K segment as the above;
19584 # hence we don't use the boot_gdt_descr defined in head.S
19585 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19586 index 09ff517..df19fbff 100644
19587 --- a/arch/x86/kernel/trampoline_64.S
19588 +++ b/arch/x86/kernel/trampoline_64.S
19589 @@ -90,7 +90,7 @@ startup_32:
19590 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19591 movl %eax, %ds
19592
19593 - movl $X86_CR4_PAE, %eax
19594 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19595 movl %eax, %cr4 # Enable PAE mode
19596
19597 # Setup trampoline 4 level pagetables
19598 @@ -138,7 +138,7 @@ tidt:
19599 # so the kernel can live anywhere
19600 .balign 4
19601 tgdt:
19602 - .short tgdt_end - tgdt # gdt limit
19603 + .short tgdt_end - tgdt - 1 # gdt limit
19604 .long tgdt - r_base
19605 .short 0
19606 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19607 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19608 index 4bbe04d..41d0943 100644
19609 --- a/arch/x86/kernel/traps.c
19610 +++ b/arch/x86/kernel/traps.c
19611 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19612
19613 /* Do we ignore FPU interrupts ? */
19614 char ignore_fpu_irq;
19615 -
19616 -/*
19617 - * The IDT has to be page-aligned to simplify the Pentium
19618 - * F0 0F bug workaround.
19619 - */
19620 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19621 #endif
19622
19623 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19624 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19625 }
19626
19627 static void __kprobes
19628 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19629 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19630 long error_code, siginfo_t *info)
19631 {
19632 struct task_struct *tsk = current;
19633
19634 #ifdef CONFIG_X86_32
19635 - if (regs->flags & X86_VM_MASK) {
19636 + if (v8086_mode(regs)) {
19637 /*
19638 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19639 * On nmi (interrupt 2), do_trap should not be called.
19640 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19641 }
19642 #endif
19643
19644 - if (!user_mode(regs))
19645 + if (!user_mode_novm(regs))
19646 goto kernel_trap;
19647
19648 #ifdef CONFIG_X86_32
19649 @@ -148,7 +142,7 @@ trap_signal:
19650 printk_ratelimit()) {
19651 printk(KERN_INFO
19652 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19653 - tsk->comm, tsk->pid, str,
19654 + tsk->comm, task_pid_nr(tsk), str,
19655 regs->ip, regs->sp, error_code);
19656 print_vma_addr(" in ", regs->ip);
19657 printk("\n");
19658 @@ -165,8 +159,20 @@ kernel_trap:
19659 if (!fixup_exception(regs)) {
19660 tsk->thread.error_code = error_code;
19661 tsk->thread.trap_no = trapnr;
19662 +
19663 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19664 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19665 + str = "PAX: suspicious stack segment fault";
19666 +#endif
19667 +
19668 die(str, regs, error_code);
19669 }
19670 +
19671 +#ifdef CONFIG_PAX_REFCOUNT
19672 + if (trapnr == 4)
19673 + pax_report_refcount_overflow(regs);
19674 +#endif
19675 +
19676 return;
19677
19678 #ifdef CONFIG_X86_32
19679 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19680 conditional_sti(regs);
19681
19682 #ifdef CONFIG_X86_32
19683 - if (regs->flags & X86_VM_MASK)
19684 + if (v8086_mode(regs))
19685 goto gp_in_vm86;
19686 #endif
19687
19688 tsk = current;
19689 - if (!user_mode(regs))
19690 + if (!user_mode_novm(regs))
19691 goto gp_in_kernel;
19692
19693 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19694 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19695 + struct mm_struct *mm = tsk->mm;
19696 + unsigned long limit;
19697 +
19698 + down_write(&mm->mmap_sem);
19699 + limit = mm->context.user_cs_limit;
19700 + if (limit < TASK_SIZE) {
19701 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19702 + up_write(&mm->mmap_sem);
19703 + return;
19704 + }
19705 + up_write(&mm->mmap_sem);
19706 + }
19707 +#endif
19708 +
19709 tsk->thread.error_code = error_code;
19710 tsk->thread.trap_no = 13;
19711
19712 @@ -295,6 +317,13 @@ gp_in_kernel:
19713 if (notify_die(DIE_GPF, "general protection fault", regs,
19714 error_code, 13, SIGSEGV) == NOTIFY_STOP)
19715 return;
19716 +
19717 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19718 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19719 + die("PAX: suspicious general protection fault", regs, error_code);
19720 + else
19721 +#endif
19722 +
19723 die("general protection fault", regs, error_code);
19724 }
19725
19726 @@ -421,7 +450,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19727 /* It's safe to allow irq's after DR6 has been saved */
19728 preempt_conditional_sti(regs);
19729
19730 - if (regs->flags & X86_VM_MASK) {
19731 + if (v8086_mode(regs)) {
19732 handle_vm86_trap((struct kernel_vm86_regs *) regs,
19733 error_code, 1);
19734 preempt_conditional_cli(regs);
19735 @@ -436,7 +465,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19736 * We already checked v86 mode above, so we can check for kernel mode
19737 * by just checking the CPL of CS.
19738 */
19739 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19740 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19741 tsk->thread.debugreg6 &= ~DR_STEP;
19742 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19743 regs->flags &= ~X86_EFLAGS_TF;
19744 @@ -466,7 +495,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19745 return;
19746 conditional_sti(regs);
19747
19748 - if (!user_mode_vm(regs))
19749 + if (!user_mode(regs))
19750 {
19751 if (!fixup_exception(regs)) {
19752 task->thread.error_code = error_code;
19753 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19754 index b9242ba..50c5edd 100644
19755 --- a/arch/x86/kernel/verify_cpu.S
19756 +++ b/arch/x86/kernel/verify_cpu.S
19757 @@ -20,6 +20,7 @@
19758 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19759 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19760 * arch/x86/kernel/head_32.S: processor startup
19761 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19762 *
19763 * verify_cpu, returns the status of longmode and SSE in register %eax.
19764 * 0: Success 1: Failure
19765 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19766 index 328cb37..f37fee1 100644
19767 --- a/arch/x86/kernel/vm86_32.c
19768 +++ b/arch/x86/kernel/vm86_32.c
19769 @@ -41,6 +41,7 @@
19770 #include <linux/ptrace.h>
19771 #include <linux/audit.h>
19772 #include <linux/stddef.h>
19773 +#include <linux/grsecurity.h>
19774
19775 #include <asm/uaccess.h>
19776 #include <asm/io.h>
19777 @@ -109,6 +110,9 @@ static int copy_vm86_regs_to_user(struct vm86_regs __user *user,
19778 /* convert vm86_regs to kernel_vm86_regs */
19779 static int copy_vm86_regs_from_user(struct kernel_vm86_regs *regs,
19780 const struct vm86_regs __user *user,
19781 + unsigned extra) __size_overflow(3);
19782 +static int copy_vm86_regs_from_user(struct kernel_vm86_regs *regs,
19783 + const struct vm86_regs __user *user,
19784 unsigned extra)
19785 {
19786 int ret = 0;
19787 @@ -148,7 +152,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19788 do_exit(SIGSEGV);
19789 }
19790
19791 - tss = &per_cpu(init_tss, get_cpu());
19792 + tss = init_tss + get_cpu();
19793 current->thread.sp0 = current->thread.saved_sp0;
19794 current->thread.sysenter_cs = __KERNEL_CS;
19795 load_sp0(tss, &current->thread);
19796 @@ -210,6 +214,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19797 struct task_struct *tsk;
19798 int tmp, ret = -EPERM;
19799
19800 +#ifdef CONFIG_GRKERNSEC_VM86
19801 + if (!capable(CAP_SYS_RAWIO)) {
19802 + gr_handle_vm86();
19803 + goto out;
19804 + }
19805 +#endif
19806 +
19807 tsk = current;
19808 if (tsk->thread.saved_sp0)
19809 goto out;
19810 @@ -240,6 +251,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19811 int tmp, ret;
19812 struct vm86plus_struct __user *v86;
19813
19814 +#ifdef CONFIG_GRKERNSEC_VM86
19815 + if (!capable(CAP_SYS_RAWIO)) {
19816 + gr_handle_vm86();
19817 + ret = -EPERM;
19818 + goto out;
19819 + }
19820 +#endif
19821 +
19822 tsk = current;
19823 switch (cmd) {
19824 case VM86_REQUEST_IRQ:
19825 @@ -326,7 +345,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19826 tsk->thread.saved_fs = info->regs32->fs;
19827 tsk->thread.saved_gs = get_user_gs(info->regs32);
19828
19829 - tss = &per_cpu(init_tss, get_cpu());
19830 + tss = init_tss + get_cpu();
19831 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19832 if (cpu_has_sep)
19833 tsk->thread.sysenter_cs = 0;
19834 @@ -533,7 +552,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19835 goto cannot_handle;
19836 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19837 goto cannot_handle;
19838 - intr_ptr = (unsigned long __user *) (i << 2);
19839 + intr_ptr = (__force unsigned long __user *) (i << 2);
19840 if (get_user(segoffs, intr_ptr))
19841 goto cannot_handle;
19842 if ((segoffs >> 16) == BIOSSEG)
19843 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19844 index 0f703f1..9e15f64 100644
19845 --- a/arch/x86/kernel/vmlinux.lds.S
19846 +++ b/arch/x86/kernel/vmlinux.lds.S
19847 @@ -26,6 +26,13 @@
19848 #include <asm/page_types.h>
19849 #include <asm/cache.h>
19850 #include <asm/boot.h>
19851 +#include <asm/segment.h>
19852 +
19853 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19854 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19855 +#else
19856 +#define __KERNEL_TEXT_OFFSET 0
19857 +#endif
19858
19859 #undef i386 /* in case the preprocessor is a 32bit one */
19860
19861 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19862
19863 PHDRS {
19864 text PT_LOAD FLAGS(5); /* R_E */
19865 +#ifdef CONFIG_X86_32
19866 + module PT_LOAD FLAGS(5); /* R_E */
19867 +#endif
19868 +#ifdef CONFIG_XEN
19869 + rodata PT_LOAD FLAGS(5); /* R_E */
19870 +#else
19871 + rodata PT_LOAD FLAGS(4); /* R__ */
19872 +#endif
19873 data PT_LOAD FLAGS(6); /* RW_ */
19874 -#ifdef CONFIG_X86_64
19875 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19876 #ifdef CONFIG_SMP
19877 percpu PT_LOAD FLAGS(6); /* RW_ */
19878 #endif
19879 + text.init PT_LOAD FLAGS(5); /* R_E */
19880 + text.exit PT_LOAD FLAGS(5); /* R_E */
19881 init PT_LOAD FLAGS(7); /* RWE */
19882 -#endif
19883 note PT_NOTE FLAGS(0); /* ___ */
19884 }
19885
19886 SECTIONS
19887 {
19888 #ifdef CONFIG_X86_32
19889 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19890 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19891 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19892 #else
19893 - . = __START_KERNEL;
19894 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19895 + . = __START_KERNEL;
19896 #endif
19897
19898 /* Text and read-only data */
19899 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19900 - _text = .;
19901 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19902 /* bootstrapping code */
19903 +#ifdef CONFIG_X86_32
19904 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19905 +#else
19906 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19907 +#endif
19908 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19909 + _text = .;
19910 HEAD_TEXT
19911 #ifdef CONFIG_X86_32
19912 . = ALIGN(PAGE_SIZE);
19913 @@ -108,13 +128,47 @@ SECTIONS
19914 IRQENTRY_TEXT
19915 *(.fixup)
19916 *(.gnu.warning)
19917 - /* End of text section */
19918 - _etext = .;
19919 } :text = 0x9090
19920
19921 - NOTES :text :note
19922 + . += __KERNEL_TEXT_OFFSET;
19923
19924 - EXCEPTION_TABLE(16) :text = 0x9090
19925 +#ifdef CONFIG_X86_32
19926 + . = ALIGN(PAGE_SIZE);
19927 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19928 +
19929 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19930 + MODULES_EXEC_VADDR = .;
19931 + BYTE(0)
19932 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19933 + . = ALIGN(HPAGE_SIZE);
19934 + MODULES_EXEC_END = . - 1;
19935 +#endif
19936 +
19937 + } :module
19938 +#endif
19939 +
19940 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19941 + /* End of text section */
19942 + _etext = . - __KERNEL_TEXT_OFFSET;
19943 + }
19944 +
19945 +#ifdef CONFIG_X86_32
19946 + . = ALIGN(PAGE_SIZE);
19947 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19948 + *(.idt)
19949 + . = ALIGN(PAGE_SIZE);
19950 + *(.empty_zero_page)
19951 + *(.initial_pg_fixmap)
19952 + *(.initial_pg_pmd)
19953 + *(.initial_page_table)
19954 + *(.swapper_pg_dir)
19955 + } :rodata
19956 +#endif
19957 +
19958 + . = ALIGN(PAGE_SIZE);
19959 + NOTES :rodata :note
19960 +
19961 + EXCEPTION_TABLE(16) :rodata
19962
19963 #if defined(CONFIG_DEBUG_RODATA)
19964 /* .text should occupy whole number of pages */
19965 @@ -126,16 +180,20 @@ SECTIONS
19966
19967 /* Data */
19968 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19969 +
19970 +#ifdef CONFIG_PAX_KERNEXEC
19971 + . = ALIGN(HPAGE_SIZE);
19972 +#else
19973 + . = ALIGN(PAGE_SIZE);
19974 +#endif
19975 +
19976 /* Start of data section */
19977 _sdata = .;
19978
19979 /* init_task */
19980 INIT_TASK_DATA(THREAD_SIZE)
19981
19982 -#ifdef CONFIG_X86_32
19983 - /* 32 bit has nosave before _edata */
19984 NOSAVE_DATA
19985 -#endif
19986
19987 PAGE_ALIGNED_DATA(PAGE_SIZE)
19988
19989 @@ -176,12 +234,19 @@ SECTIONS
19990 #endif /* CONFIG_X86_64 */
19991
19992 /* Init code and data - will be freed after init */
19993 - . = ALIGN(PAGE_SIZE);
19994 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19995 + BYTE(0)
19996 +
19997 +#ifdef CONFIG_PAX_KERNEXEC
19998 + . = ALIGN(HPAGE_SIZE);
19999 +#else
20000 + . = ALIGN(PAGE_SIZE);
20001 +#endif
20002 +
20003 __init_begin = .; /* paired with __init_end */
20004 - }
20005 + } :init.begin
20006
20007 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20008 +#ifdef CONFIG_SMP
20009 /*
20010 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20011 * output PHDR, so the next output section - .init.text - should
20012 @@ -190,12 +255,27 @@ SECTIONS
20013 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20014 #endif
20015
20016 - INIT_TEXT_SECTION(PAGE_SIZE)
20017 -#ifdef CONFIG_X86_64
20018 - :init
20019 -#endif
20020 + . = ALIGN(PAGE_SIZE);
20021 + init_begin = .;
20022 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20023 + VMLINUX_SYMBOL(_sinittext) = .;
20024 + INIT_TEXT
20025 + VMLINUX_SYMBOL(_einittext) = .;
20026 + . = ALIGN(PAGE_SIZE);
20027 + } :text.init
20028
20029 - INIT_DATA_SECTION(16)
20030 + /*
20031 + * .exit.text is discard at runtime, not link time, to deal with
20032 + * references from .altinstructions and .eh_frame
20033 + */
20034 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20035 + EXIT_TEXT
20036 + . = ALIGN(16);
20037 + } :text.exit
20038 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20039 +
20040 + . = ALIGN(PAGE_SIZE);
20041 + INIT_DATA_SECTION(16) :init
20042
20043 /*
20044 * Code and data for a variety of lowlevel trampolines, to be
20045 @@ -269,19 +349,12 @@ SECTIONS
20046 }
20047
20048 . = ALIGN(8);
20049 - /*
20050 - * .exit.text is discard at runtime, not link time, to deal with
20051 - * references from .altinstructions and .eh_frame
20052 - */
20053 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20054 - EXIT_TEXT
20055 - }
20056
20057 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20058 EXIT_DATA
20059 }
20060
20061 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20062 +#ifndef CONFIG_SMP
20063 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20064 #endif
20065
20066 @@ -300,16 +373,10 @@ SECTIONS
20067 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20068 __smp_locks = .;
20069 *(.smp_locks)
20070 - . = ALIGN(PAGE_SIZE);
20071 __smp_locks_end = .;
20072 + . = ALIGN(PAGE_SIZE);
20073 }
20074
20075 -#ifdef CONFIG_X86_64
20076 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20077 - NOSAVE_DATA
20078 - }
20079 -#endif
20080 -
20081 /* BSS */
20082 . = ALIGN(PAGE_SIZE);
20083 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20084 @@ -325,6 +392,7 @@ SECTIONS
20085 __brk_base = .;
20086 . += 64 * 1024; /* 64k alignment slop space */
20087 *(.brk_reservation) /* areas brk users have reserved */
20088 + . = ALIGN(HPAGE_SIZE);
20089 __brk_limit = .;
20090 }
20091
20092 @@ -351,13 +419,12 @@ SECTIONS
20093 * for the boot processor.
20094 */
20095 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20096 -INIT_PER_CPU(gdt_page);
20097 INIT_PER_CPU(irq_stack_union);
20098
20099 /*
20100 * Build-time check on the image size:
20101 */
20102 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20103 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20104 "kernel image bigger than KERNEL_IMAGE_SIZE");
20105
20106 #ifdef CONFIG_SMP
20107 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20108 index b07ba93..a212969 100644
20109 --- a/arch/x86/kernel/vsyscall_64.c
20110 +++ b/arch/x86/kernel/vsyscall_64.c
20111 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
20112 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
20113 };
20114
20115 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20116 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20117
20118 static int __init vsyscall_setup(char *str)
20119 {
20120 if (str) {
20121 if (!strcmp("emulate", str))
20122 vsyscall_mode = EMULATE;
20123 - else if (!strcmp("native", str))
20124 - vsyscall_mode = NATIVE;
20125 else if (!strcmp("none", str))
20126 vsyscall_mode = NONE;
20127 else
20128 @@ -207,7 +205,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20129
20130 tsk = current;
20131 if (seccomp_mode(&tsk->seccomp))
20132 - do_exit(SIGKILL);
20133 + do_group_exit(SIGKILL);
20134
20135 /*
20136 * With a real vsyscall, page faults cause SIGSEGV. We want to
20137 @@ -279,8 +277,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20138 return true;
20139
20140 sigsegv:
20141 - force_sig(SIGSEGV, current);
20142 - return true;
20143 + do_group_exit(SIGKILL);
20144 }
20145
20146 /*
20147 @@ -333,10 +330,7 @@ void __init map_vsyscall(void)
20148 extern char __vvar_page;
20149 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20150
20151 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20152 - vsyscall_mode == NATIVE
20153 - ? PAGE_KERNEL_VSYSCALL
20154 - : PAGE_KERNEL_VVAR);
20155 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20156 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20157 (unsigned long)VSYSCALL_START);
20158
20159 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20160 index 9796c2f..f686fbf 100644
20161 --- a/arch/x86/kernel/x8664_ksyms_64.c
20162 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20163 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20164 EXPORT_SYMBOL(copy_user_generic_string);
20165 EXPORT_SYMBOL(copy_user_generic_unrolled);
20166 EXPORT_SYMBOL(__copy_user_nocache);
20167 -EXPORT_SYMBOL(_copy_from_user);
20168 -EXPORT_SYMBOL(_copy_to_user);
20169
20170 EXPORT_SYMBOL(copy_page);
20171 EXPORT_SYMBOL(clear_page);
20172 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20173 index 7110911..e8cdee5 100644
20174 --- a/arch/x86/kernel/xsave.c
20175 +++ b/arch/x86/kernel/xsave.c
20176 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20177 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20178 return -EINVAL;
20179
20180 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20181 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20182 fx_sw_user->extended_size -
20183 FP_XSTATE_MAGIC2_SIZE));
20184 if (err)
20185 @@ -266,7 +266,7 @@ fx_only:
20186 * the other extended state.
20187 */
20188 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20189 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20190 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20191 }
20192
20193 /*
20194 @@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
20195 if (use_xsave())
20196 err = restore_user_xstate(buf);
20197 else
20198 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20199 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20200 buf);
20201 if (unlikely(err)) {
20202 /*
20203 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20204 index 89b02bf..0f6511d 100644
20205 --- a/arch/x86/kvm/cpuid.c
20206 +++ b/arch/x86/kvm/cpuid.c
20207 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20208 struct kvm_cpuid2 *cpuid,
20209 struct kvm_cpuid_entry2 __user *entries)
20210 {
20211 - int r;
20212 + int r, i;
20213
20214 r = -E2BIG;
20215 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20216 goto out;
20217 r = -EFAULT;
20218 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20219 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20220 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20221 goto out;
20222 + for (i = 0; i < cpuid->nent; ++i) {
20223 + struct kvm_cpuid_entry2 cpuid_entry;
20224 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20225 + goto out;
20226 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20227 + }
20228 vcpu->arch.cpuid_nent = cpuid->nent;
20229 kvm_apic_set_version(vcpu);
20230 kvm_x86_ops->cpuid_update(vcpu);
20231 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20232 struct kvm_cpuid2 *cpuid,
20233 struct kvm_cpuid_entry2 __user *entries)
20234 {
20235 - int r;
20236 + int r, i;
20237
20238 r = -E2BIG;
20239 if (cpuid->nent < vcpu->arch.cpuid_nent)
20240 goto out;
20241 r = -EFAULT;
20242 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20243 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20244 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20245 goto out;
20246 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20247 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20248 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20249 + goto out;
20250 + }
20251 return 0;
20252
20253 out:
20254 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20255 index 0982507..7f6d72f 100644
20256 --- a/arch/x86/kvm/emulate.c
20257 +++ b/arch/x86/kvm/emulate.c
20258 @@ -250,6 +250,7 @@ struct gprefix {
20259
20260 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20261 do { \
20262 + unsigned long _tmp; \
20263 __asm__ __volatile__ ( \
20264 _PRE_EFLAGS("0", "4", "2") \
20265 _op _suffix " %"_x"3,%1; " \
20266 @@ -264,8 +265,6 @@ struct gprefix {
20267 /* Raw emulation: instruction has two explicit operands. */
20268 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20269 do { \
20270 - unsigned long _tmp; \
20271 - \
20272 switch ((ctxt)->dst.bytes) { \
20273 case 2: \
20274 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20275 @@ -281,7 +280,6 @@ struct gprefix {
20276
20277 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20278 do { \
20279 - unsigned long _tmp; \
20280 switch ((ctxt)->dst.bytes) { \
20281 case 1: \
20282 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20283 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20284 index cfdc6e0..ab92e84 100644
20285 --- a/arch/x86/kvm/lapic.c
20286 +++ b/arch/x86/kvm/lapic.c
20287 @@ -54,7 +54,7 @@
20288 #define APIC_BUS_CYCLE_NS 1
20289
20290 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20291 -#define apic_debug(fmt, arg...)
20292 +#define apic_debug(fmt, arg...) do {} while (0)
20293
20294 #define APIC_LVT_NUM 6
20295 /* 14 is the version for Xeon and Pentium 8.4.8*/
20296 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20297 index 1561028..0ed7f14 100644
20298 --- a/arch/x86/kvm/paging_tmpl.h
20299 +++ b/arch/x86/kvm/paging_tmpl.h
20300 @@ -197,7 +197,7 @@ retry_walk:
20301 if (unlikely(kvm_is_error_hva(host_addr)))
20302 goto error;
20303
20304 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20305 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20306 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20307 goto error;
20308
20309 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20310 index e385214..f8df033 100644
20311 --- a/arch/x86/kvm/svm.c
20312 +++ b/arch/x86/kvm/svm.c
20313 @@ -3420,7 +3420,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20314 int cpu = raw_smp_processor_id();
20315
20316 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20317 +
20318 + pax_open_kernel();
20319 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20320 + pax_close_kernel();
20321 +
20322 load_TR_desc();
20323 }
20324
20325 @@ -3798,6 +3802,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20326 #endif
20327 #endif
20328
20329 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20330 + __set_fs(current_thread_info()->addr_limit);
20331 +#endif
20332 +
20333 reload_tss(vcpu);
20334
20335 local_irq_disable();
20336 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20337 index 3b4c8d8..f457b63 100644
20338 --- a/arch/x86/kvm/vmx.c
20339 +++ b/arch/x86/kvm/vmx.c
20340 @@ -1306,7 +1306,11 @@ static void reload_tss(void)
20341 struct desc_struct *descs;
20342
20343 descs = (void *)gdt->address;
20344 +
20345 + pax_open_kernel();
20346 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20347 + pax_close_kernel();
20348 +
20349 load_TR_desc();
20350 }
20351
20352 @@ -2631,8 +2635,11 @@ static __init int hardware_setup(void)
20353 if (!cpu_has_vmx_flexpriority())
20354 flexpriority_enabled = 0;
20355
20356 - if (!cpu_has_vmx_tpr_shadow())
20357 - kvm_x86_ops->update_cr8_intercept = NULL;
20358 + if (!cpu_has_vmx_tpr_shadow()) {
20359 + pax_open_kernel();
20360 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20361 + pax_close_kernel();
20362 + }
20363
20364 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20365 kvm_disable_largepages();
20366 @@ -3648,7 +3655,7 @@ static void vmx_set_constant_host_state(void)
20367 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20368
20369 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20370 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20371 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20372
20373 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20374 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20375 @@ -6184,6 +6191,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20376 "jmp .Lkvm_vmx_return \n\t"
20377 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20378 ".Lkvm_vmx_return: "
20379 +
20380 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20381 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20382 + ".Lkvm_vmx_return2: "
20383 +#endif
20384 +
20385 /* Save guest registers, load host registers, keep flags */
20386 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20387 "pop %0 \n\t"
20388 @@ -6232,6 +6245,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20389 #endif
20390 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20391 [wordsize]"i"(sizeof(ulong))
20392 +
20393 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20394 + ,[cs]"i"(__KERNEL_CS)
20395 +#endif
20396 +
20397 : "cc", "memory"
20398 , R"ax", R"bx", R"di", R"si"
20399 #ifdef CONFIG_X86_64
20400 @@ -6260,7 +6278,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20401 }
20402 }
20403
20404 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20405 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20406 +
20407 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20408 + loadsegment(fs, __KERNEL_PERCPU);
20409 +#endif
20410 +
20411 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20412 + __set_fs(current_thread_info()->addr_limit);
20413 +#endif
20414 +
20415 vmx->loaded_vmcs->launched = 1;
20416
20417 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20418 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20419 index 9cbfc06..943ffa6 100644
20420 --- a/arch/x86/kvm/x86.c
20421 +++ b/arch/x86/kvm/x86.c
20422 @@ -873,6 +873,7 @@ static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
20423 return kvm_set_msr(vcpu, index, *data);
20424 }
20425
20426 +static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) __size_overflow(2);
20427 static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
20428 {
20429 int version;
20430 @@ -1307,12 +1308,13 @@ static int set_msr_mce(struct kvm_vcpu *vcpu, u32 msr, u64 data)
20431 return 0;
20432 }
20433
20434 +static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data) __size_overflow(2);
20435 static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20436 {
20437 struct kvm *kvm = vcpu->kvm;
20438 int lm = is_long_mode(vcpu);
20439 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20440 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20441 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20442 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20443 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20444 : kvm->arch.xen_hvm_config.blob_size_32;
20445 u32 page_num = data & ~PAGE_MASK;
20446 @@ -2145,6 +2147,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20447 if (n < msr_list.nmsrs)
20448 goto out;
20449 r = -EFAULT;
20450 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20451 + goto out;
20452 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20453 num_msrs_to_save * sizeof(u32)))
20454 goto out;
20455 @@ -2266,7 +2270,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20456 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20457 struct kvm_interrupt *irq)
20458 {
20459 - if (irq->irq < 0 || irq->irq >= 256)
20460 + if (irq->irq >= 256)
20461 return -EINVAL;
20462 if (irqchip_in_kernel(vcpu->kvm))
20463 return -ENXIO;
20464 @@ -3497,6 +3501,9 @@ gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,
20465
20466 static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
20467 struct kvm_vcpu *vcpu, u32 access,
20468 + struct x86_exception *exception) __size_overflow(1,3);
20469 +static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
20470 + struct kvm_vcpu *vcpu, u32 access,
20471 struct x86_exception *exception)
20472 {
20473 void *data = val;
20474 @@ -3528,6 +3535,9 @@ out:
20475 /* used for instruction fetching */
20476 static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
20477 gva_t addr, void *val, unsigned int bytes,
20478 + struct x86_exception *exception) __size_overflow(2,4);
20479 +static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
20480 + gva_t addr, void *val, unsigned int bytes,
20481 struct x86_exception *exception)
20482 {
20483 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20484 @@ -3552,6 +3562,9 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_virt);
20485
20486 static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20487 gva_t addr, void *val, unsigned int bytes,
20488 + struct x86_exception *exception) __size_overflow(2,4);
20489 +static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20490 + gva_t addr, void *val, unsigned int bytes,
20491 struct x86_exception *exception)
20492 {
20493 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20494 @@ -3665,12 +3678,16 @@ static int read_prepare(struct kvm_vcpu *vcpu, void *val, int bytes)
20495 }
20496
20497 static int read_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20498 + void *val, int bytes) __size_overflow(2);
20499 +static int read_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20500 void *val, int bytes)
20501 {
20502 return !kvm_read_guest(vcpu->kvm, gpa, val, bytes);
20503 }
20504
20505 static int write_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20506 + void *val, int bytes) __size_overflow(2);
20507 +static int write_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20508 void *val, int bytes)
20509 {
20510 return emulator_write_phys(vcpu, gpa, val, bytes);
20511 @@ -3821,6 +3838,12 @@ static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
20512 const void *old,
20513 const void *new,
20514 unsigned int bytes,
20515 + struct x86_exception *exception) __size_overflow(5);
20516 +static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
20517 + unsigned long addr,
20518 + const void *old,
20519 + const void *new,
20520 + unsigned int bytes,
20521 struct x86_exception *exception)
20522 {
20523 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20524 @@ -4780,7 +4803,7 @@ static void kvm_set_mmio_spte_mask(void)
20525 kvm_mmu_set_mmio_spte_mask(mask);
20526 }
20527
20528 -int kvm_arch_init(void *opaque)
20529 +int kvm_arch_init(const void *opaque)
20530 {
20531 int r;
20532 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20533 diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
20534 index cb80c29..aeee86c 100644
20535 --- a/arch/x86/kvm/x86.h
20536 +++ b/arch/x86/kvm/x86.h
20537 @@ -116,11 +116,11 @@ void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data);
20538
20539 int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt,
20540 gva_t addr, void *val, unsigned int bytes,
20541 - struct x86_exception *exception);
20542 + struct x86_exception *exception) __size_overflow(2,4);
20543
20544 int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20545 gva_t addr, void *val, unsigned int bytes,
20546 - struct x86_exception *exception);
20547 + struct x86_exception *exception) __size_overflow(2,4);
20548
20549 extern u64 host_xcr0;
20550
20551 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20552 index 642d880..44e0f3f 100644
20553 --- a/arch/x86/lguest/boot.c
20554 +++ b/arch/x86/lguest/boot.c
20555 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20556 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20557 * Launcher to reboot us.
20558 */
20559 -static void lguest_restart(char *reason)
20560 +static __noreturn void lguest_restart(char *reason)
20561 {
20562 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20563 + BUG();
20564 }
20565
20566 /*G:050
20567 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
20568 index 042f682..c92afb6 100644
20569 --- a/arch/x86/lib/atomic64_32.c
20570 +++ b/arch/x86/lib/atomic64_32.c
20571 @@ -8,18 +8,30 @@
20572
20573 long long atomic64_read_cx8(long long, const atomic64_t *v);
20574 EXPORT_SYMBOL(atomic64_read_cx8);
20575 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20576 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
20577 long long atomic64_set_cx8(long long, const atomic64_t *v);
20578 EXPORT_SYMBOL(atomic64_set_cx8);
20579 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20580 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
20581 long long atomic64_xchg_cx8(long long, unsigned high);
20582 EXPORT_SYMBOL(atomic64_xchg_cx8);
20583 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
20584 EXPORT_SYMBOL(atomic64_add_return_cx8);
20585 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20586 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
20587 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
20588 EXPORT_SYMBOL(atomic64_sub_return_cx8);
20589 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20590 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
20591 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
20592 EXPORT_SYMBOL(atomic64_inc_return_cx8);
20593 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20594 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
20595 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
20596 EXPORT_SYMBOL(atomic64_dec_return_cx8);
20597 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20598 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
20599 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
20600 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
20601 int atomic64_inc_not_zero_cx8(atomic64_t *v);
20602 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
20603 #ifndef CONFIG_X86_CMPXCHG64
20604 long long atomic64_read_386(long long, const atomic64_t *v);
20605 EXPORT_SYMBOL(atomic64_read_386);
20606 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
20607 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
20608 long long atomic64_set_386(long long, const atomic64_t *v);
20609 EXPORT_SYMBOL(atomic64_set_386);
20610 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
20611 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
20612 long long atomic64_xchg_386(long long, unsigned high);
20613 EXPORT_SYMBOL(atomic64_xchg_386);
20614 long long atomic64_add_return_386(long long a, atomic64_t *v);
20615 EXPORT_SYMBOL(atomic64_add_return_386);
20616 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20617 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
20618 long long atomic64_sub_return_386(long long a, atomic64_t *v);
20619 EXPORT_SYMBOL(atomic64_sub_return_386);
20620 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20621 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
20622 long long atomic64_inc_return_386(long long a, atomic64_t *v);
20623 EXPORT_SYMBOL(atomic64_inc_return_386);
20624 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20625 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
20626 long long atomic64_dec_return_386(long long a, atomic64_t *v);
20627 EXPORT_SYMBOL(atomic64_dec_return_386);
20628 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20629 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
20630 long long atomic64_add_386(long long a, atomic64_t *v);
20631 EXPORT_SYMBOL(atomic64_add_386);
20632 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
20633 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
20634 long long atomic64_sub_386(long long a, atomic64_t *v);
20635 EXPORT_SYMBOL(atomic64_sub_386);
20636 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
20637 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
20638 long long atomic64_inc_386(long long a, atomic64_t *v);
20639 EXPORT_SYMBOL(atomic64_inc_386);
20640 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
20641 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
20642 long long atomic64_dec_386(long long a, atomic64_t *v);
20643 EXPORT_SYMBOL(atomic64_dec_386);
20644 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
20645 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
20646 long long atomic64_dec_if_positive_386(atomic64_t *v);
20647 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
20648 int atomic64_inc_not_zero_386(atomic64_t *v);
20649 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20650 index e8e7e0d..56fd1b0 100644
20651 --- a/arch/x86/lib/atomic64_386_32.S
20652 +++ b/arch/x86/lib/atomic64_386_32.S
20653 @@ -48,6 +48,10 @@ BEGIN(read)
20654 movl (v), %eax
20655 movl 4(v), %edx
20656 RET_ENDP
20657 +BEGIN(read_unchecked)
20658 + movl (v), %eax
20659 + movl 4(v), %edx
20660 +RET_ENDP
20661 #undef v
20662
20663 #define v %esi
20664 @@ -55,6 +59,10 @@ BEGIN(set)
20665 movl %ebx, (v)
20666 movl %ecx, 4(v)
20667 RET_ENDP
20668 +BEGIN(set_unchecked)
20669 + movl %ebx, (v)
20670 + movl %ecx, 4(v)
20671 +RET_ENDP
20672 #undef v
20673
20674 #define v %esi
20675 @@ -70,6 +78,20 @@ RET_ENDP
20676 BEGIN(add)
20677 addl %eax, (v)
20678 adcl %edx, 4(v)
20679 +
20680 +#ifdef CONFIG_PAX_REFCOUNT
20681 + jno 0f
20682 + subl %eax, (v)
20683 + sbbl %edx, 4(v)
20684 + int $4
20685 +0:
20686 + _ASM_EXTABLE(0b, 0b)
20687 +#endif
20688 +
20689 +RET_ENDP
20690 +BEGIN(add_unchecked)
20691 + addl %eax, (v)
20692 + adcl %edx, 4(v)
20693 RET_ENDP
20694 #undef v
20695
20696 @@ -77,6 +99,24 @@ RET_ENDP
20697 BEGIN(add_return)
20698 addl (v), %eax
20699 adcl 4(v), %edx
20700 +
20701 +#ifdef CONFIG_PAX_REFCOUNT
20702 + into
20703 +1234:
20704 + _ASM_EXTABLE(1234b, 2f)
20705 +#endif
20706 +
20707 + movl %eax, (v)
20708 + movl %edx, 4(v)
20709 +
20710 +#ifdef CONFIG_PAX_REFCOUNT
20711 +2:
20712 +#endif
20713 +
20714 +RET_ENDP
20715 +BEGIN(add_return_unchecked)
20716 + addl (v), %eax
20717 + adcl 4(v), %edx
20718 movl %eax, (v)
20719 movl %edx, 4(v)
20720 RET_ENDP
20721 @@ -86,6 +126,20 @@ RET_ENDP
20722 BEGIN(sub)
20723 subl %eax, (v)
20724 sbbl %edx, 4(v)
20725 +
20726 +#ifdef CONFIG_PAX_REFCOUNT
20727 + jno 0f
20728 + addl %eax, (v)
20729 + adcl %edx, 4(v)
20730 + int $4
20731 +0:
20732 + _ASM_EXTABLE(0b, 0b)
20733 +#endif
20734 +
20735 +RET_ENDP
20736 +BEGIN(sub_unchecked)
20737 + subl %eax, (v)
20738 + sbbl %edx, 4(v)
20739 RET_ENDP
20740 #undef v
20741
20742 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20743 sbbl $0, %edx
20744 addl (v), %eax
20745 adcl 4(v), %edx
20746 +
20747 +#ifdef CONFIG_PAX_REFCOUNT
20748 + into
20749 +1234:
20750 + _ASM_EXTABLE(1234b, 2f)
20751 +#endif
20752 +
20753 + movl %eax, (v)
20754 + movl %edx, 4(v)
20755 +
20756 +#ifdef CONFIG_PAX_REFCOUNT
20757 +2:
20758 +#endif
20759 +
20760 +RET_ENDP
20761 +BEGIN(sub_return_unchecked)
20762 + negl %edx
20763 + negl %eax
20764 + sbbl $0, %edx
20765 + addl (v), %eax
20766 + adcl 4(v), %edx
20767 movl %eax, (v)
20768 movl %edx, 4(v)
20769 RET_ENDP
20770 @@ -105,6 +180,20 @@ RET_ENDP
20771 BEGIN(inc)
20772 addl $1, (v)
20773 adcl $0, 4(v)
20774 +
20775 +#ifdef CONFIG_PAX_REFCOUNT
20776 + jno 0f
20777 + subl $1, (v)
20778 + sbbl $0, 4(v)
20779 + int $4
20780 +0:
20781 + _ASM_EXTABLE(0b, 0b)
20782 +#endif
20783 +
20784 +RET_ENDP
20785 +BEGIN(inc_unchecked)
20786 + addl $1, (v)
20787 + adcl $0, 4(v)
20788 RET_ENDP
20789 #undef v
20790
20791 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20792 movl 4(v), %edx
20793 addl $1, %eax
20794 adcl $0, %edx
20795 +
20796 +#ifdef CONFIG_PAX_REFCOUNT
20797 + into
20798 +1234:
20799 + _ASM_EXTABLE(1234b, 2f)
20800 +#endif
20801 +
20802 + movl %eax, (v)
20803 + movl %edx, 4(v)
20804 +
20805 +#ifdef CONFIG_PAX_REFCOUNT
20806 +2:
20807 +#endif
20808 +
20809 +RET_ENDP
20810 +BEGIN(inc_return_unchecked)
20811 + movl (v), %eax
20812 + movl 4(v), %edx
20813 + addl $1, %eax
20814 + adcl $0, %edx
20815 movl %eax, (v)
20816 movl %edx, 4(v)
20817 RET_ENDP
20818 @@ -123,6 +232,20 @@ RET_ENDP
20819 BEGIN(dec)
20820 subl $1, (v)
20821 sbbl $0, 4(v)
20822 +
20823 +#ifdef CONFIG_PAX_REFCOUNT
20824 + jno 0f
20825 + addl $1, (v)
20826 + adcl $0, 4(v)
20827 + int $4
20828 +0:
20829 + _ASM_EXTABLE(0b, 0b)
20830 +#endif
20831 +
20832 +RET_ENDP
20833 +BEGIN(dec_unchecked)
20834 + subl $1, (v)
20835 + sbbl $0, 4(v)
20836 RET_ENDP
20837 #undef v
20838
20839 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20840 movl 4(v), %edx
20841 subl $1, %eax
20842 sbbl $0, %edx
20843 +
20844 +#ifdef CONFIG_PAX_REFCOUNT
20845 + into
20846 +1234:
20847 + _ASM_EXTABLE(1234b, 2f)
20848 +#endif
20849 +
20850 + movl %eax, (v)
20851 + movl %edx, 4(v)
20852 +
20853 +#ifdef CONFIG_PAX_REFCOUNT
20854 +2:
20855 +#endif
20856 +
20857 +RET_ENDP
20858 +BEGIN(dec_return_unchecked)
20859 + movl (v), %eax
20860 + movl 4(v), %edx
20861 + subl $1, %eax
20862 + sbbl $0, %edx
20863 movl %eax, (v)
20864 movl %edx, 4(v)
20865 RET_ENDP
20866 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20867 adcl %edx, %edi
20868 addl (v), %eax
20869 adcl 4(v), %edx
20870 +
20871 +#ifdef CONFIG_PAX_REFCOUNT
20872 + into
20873 +1234:
20874 + _ASM_EXTABLE(1234b, 2f)
20875 +#endif
20876 +
20877 cmpl %eax, %esi
20878 je 3f
20879 1:
20880 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20881 1:
20882 addl $1, %eax
20883 adcl $0, %edx
20884 +
20885 +#ifdef CONFIG_PAX_REFCOUNT
20886 + into
20887 +1234:
20888 + _ASM_EXTABLE(1234b, 2f)
20889 +#endif
20890 +
20891 movl %eax, (v)
20892 movl %edx, 4(v)
20893 movl $1, %eax
20894 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20895 movl 4(v), %edx
20896 subl $1, %eax
20897 sbbl $0, %edx
20898 +
20899 +#ifdef CONFIG_PAX_REFCOUNT
20900 + into
20901 +1234:
20902 + _ASM_EXTABLE(1234b, 1f)
20903 +#endif
20904 +
20905 js 1f
20906 movl %eax, (v)
20907 movl %edx, 4(v)
20908 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20909 index 391a083..d658e9f 100644
20910 --- a/arch/x86/lib/atomic64_cx8_32.S
20911 +++ b/arch/x86/lib/atomic64_cx8_32.S
20912 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20913 CFI_STARTPROC
20914
20915 read64 %ecx
20916 + pax_force_retaddr
20917 ret
20918 CFI_ENDPROC
20919 ENDPROC(atomic64_read_cx8)
20920
20921 +ENTRY(atomic64_read_unchecked_cx8)
20922 + CFI_STARTPROC
20923 +
20924 + read64 %ecx
20925 + pax_force_retaddr
20926 + ret
20927 + CFI_ENDPROC
20928 +ENDPROC(atomic64_read_unchecked_cx8)
20929 +
20930 ENTRY(atomic64_set_cx8)
20931 CFI_STARTPROC
20932
20933 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20934 cmpxchg8b (%esi)
20935 jne 1b
20936
20937 + pax_force_retaddr
20938 ret
20939 CFI_ENDPROC
20940 ENDPROC(atomic64_set_cx8)
20941
20942 +ENTRY(atomic64_set_unchecked_cx8)
20943 + CFI_STARTPROC
20944 +
20945 +1:
20946 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20947 + * are atomic on 586 and newer */
20948 + cmpxchg8b (%esi)
20949 + jne 1b
20950 +
20951 + pax_force_retaddr
20952 + ret
20953 + CFI_ENDPROC
20954 +ENDPROC(atomic64_set_unchecked_cx8)
20955 +
20956 ENTRY(atomic64_xchg_cx8)
20957 CFI_STARTPROC
20958
20959 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
20960 cmpxchg8b (%esi)
20961 jne 1b
20962
20963 + pax_force_retaddr
20964 ret
20965 CFI_ENDPROC
20966 ENDPROC(atomic64_xchg_cx8)
20967
20968 -.macro addsub_return func ins insc
20969 -ENTRY(atomic64_\func\()_return_cx8)
20970 +.macro addsub_return func ins insc unchecked=""
20971 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20972 CFI_STARTPROC
20973 SAVE ebp
20974 SAVE ebx
20975 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20976 movl %edx, %ecx
20977 \ins\()l %esi, %ebx
20978 \insc\()l %edi, %ecx
20979 +
20980 +.ifb \unchecked
20981 +#ifdef CONFIG_PAX_REFCOUNT
20982 + into
20983 +2:
20984 + _ASM_EXTABLE(2b, 3f)
20985 +#endif
20986 +.endif
20987 +
20988 LOCK_PREFIX
20989 cmpxchg8b (%ebp)
20990 jne 1b
20991 -
20992 -10:
20993 movl %ebx, %eax
20994 movl %ecx, %edx
20995 +
20996 +.ifb \unchecked
20997 +#ifdef CONFIG_PAX_REFCOUNT
20998 +3:
20999 +#endif
21000 +.endif
21001 +
21002 RESTORE edi
21003 RESTORE esi
21004 RESTORE ebx
21005 RESTORE ebp
21006 + pax_force_retaddr
21007 ret
21008 CFI_ENDPROC
21009 -ENDPROC(atomic64_\func\()_return_cx8)
21010 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21011 .endm
21012
21013 addsub_return add add adc
21014 addsub_return sub sub sbb
21015 +addsub_return add add adc _unchecked
21016 +addsub_return sub sub sbb _unchecked
21017
21018 -.macro incdec_return func ins insc
21019 -ENTRY(atomic64_\func\()_return_cx8)
21020 +.macro incdec_return func ins insc unchecked
21021 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21022 CFI_STARTPROC
21023 SAVE ebx
21024
21025 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21026 movl %edx, %ecx
21027 \ins\()l $1, %ebx
21028 \insc\()l $0, %ecx
21029 +
21030 +.ifb \unchecked
21031 +#ifdef CONFIG_PAX_REFCOUNT
21032 + into
21033 +2:
21034 + _ASM_EXTABLE(2b, 3f)
21035 +#endif
21036 +.endif
21037 +
21038 LOCK_PREFIX
21039 cmpxchg8b (%esi)
21040 jne 1b
21041
21042 -10:
21043 movl %ebx, %eax
21044 movl %ecx, %edx
21045 +
21046 +.ifb \unchecked
21047 +#ifdef CONFIG_PAX_REFCOUNT
21048 +3:
21049 +#endif
21050 +.endif
21051 +
21052 RESTORE ebx
21053 + pax_force_retaddr
21054 ret
21055 CFI_ENDPROC
21056 -ENDPROC(atomic64_\func\()_return_cx8)
21057 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21058 .endm
21059
21060 incdec_return inc add adc
21061 incdec_return dec sub sbb
21062 +incdec_return inc add adc _unchecked
21063 +incdec_return dec sub sbb _unchecked
21064
21065 ENTRY(atomic64_dec_if_positive_cx8)
21066 CFI_STARTPROC
21067 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21068 movl %edx, %ecx
21069 subl $1, %ebx
21070 sbb $0, %ecx
21071 +
21072 +#ifdef CONFIG_PAX_REFCOUNT
21073 + into
21074 +1234:
21075 + _ASM_EXTABLE(1234b, 2f)
21076 +#endif
21077 +
21078 js 2f
21079 LOCK_PREFIX
21080 cmpxchg8b (%esi)
21081 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21082 movl %ebx, %eax
21083 movl %ecx, %edx
21084 RESTORE ebx
21085 + pax_force_retaddr
21086 ret
21087 CFI_ENDPROC
21088 ENDPROC(atomic64_dec_if_positive_cx8)
21089 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
21090 movl %edx, %ecx
21091 addl %esi, %ebx
21092 adcl %edi, %ecx
21093 +
21094 +#ifdef CONFIG_PAX_REFCOUNT
21095 + into
21096 +1234:
21097 + _ASM_EXTABLE(1234b, 3f)
21098 +#endif
21099 +
21100 LOCK_PREFIX
21101 cmpxchg8b (%ebp)
21102 jne 1b
21103 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
21104 CFI_ADJUST_CFA_OFFSET -8
21105 RESTORE ebx
21106 RESTORE ebp
21107 + pax_force_retaddr
21108 ret
21109 4:
21110 cmpl %edx, 4(%esp)
21111 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21112 movl %edx, %ecx
21113 addl $1, %ebx
21114 adcl $0, %ecx
21115 +
21116 +#ifdef CONFIG_PAX_REFCOUNT
21117 + into
21118 +1234:
21119 + _ASM_EXTABLE(1234b, 3f)
21120 +#endif
21121 +
21122 LOCK_PREFIX
21123 cmpxchg8b (%esi)
21124 jne 1b
21125 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21126 movl $1, %eax
21127 3:
21128 RESTORE ebx
21129 + pax_force_retaddr
21130 ret
21131 4:
21132 testl %edx, %edx
21133 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21134 index 78d16a5..fbcf666 100644
21135 --- a/arch/x86/lib/checksum_32.S
21136 +++ b/arch/x86/lib/checksum_32.S
21137 @@ -28,7 +28,8 @@
21138 #include <linux/linkage.h>
21139 #include <asm/dwarf2.h>
21140 #include <asm/errno.h>
21141 -
21142 +#include <asm/segment.h>
21143 +
21144 /*
21145 * computes a partial checksum, e.g. for TCP/UDP fragments
21146 */
21147 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21148
21149 #define ARGBASE 16
21150 #define FP 12
21151 -
21152 -ENTRY(csum_partial_copy_generic)
21153 +
21154 +ENTRY(csum_partial_copy_generic_to_user)
21155 CFI_STARTPROC
21156 +
21157 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21158 + pushl_cfi %gs
21159 + popl_cfi %es
21160 + jmp csum_partial_copy_generic
21161 +#endif
21162 +
21163 +ENTRY(csum_partial_copy_generic_from_user)
21164 +
21165 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21166 + pushl_cfi %gs
21167 + popl_cfi %ds
21168 +#endif
21169 +
21170 +ENTRY(csum_partial_copy_generic)
21171 subl $4,%esp
21172 CFI_ADJUST_CFA_OFFSET 4
21173 pushl_cfi %edi
21174 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
21175 jmp 4f
21176 SRC(1: movw (%esi), %bx )
21177 addl $2, %esi
21178 -DST( movw %bx, (%edi) )
21179 +DST( movw %bx, %es:(%edi) )
21180 addl $2, %edi
21181 addw %bx, %ax
21182 adcl $0, %eax
21183 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
21184 SRC(1: movl (%esi), %ebx )
21185 SRC( movl 4(%esi), %edx )
21186 adcl %ebx, %eax
21187 -DST( movl %ebx, (%edi) )
21188 +DST( movl %ebx, %es:(%edi) )
21189 adcl %edx, %eax
21190 -DST( movl %edx, 4(%edi) )
21191 +DST( movl %edx, %es:4(%edi) )
21192
21193 SRC( movl 8(%esi), %ebx )
21194 SRC( movl 12(%esi), %edx )
21195 adcl %ebx, %eax
21196 -DST( movl %ebx, 8(%edi) )
21197 +DST( movl %ebx, %es:8(%edi) )
21198 adcl %edx, %eax
21199 -DST( movl %edx, 12(%edi) )
21200 +DST( movl %edx, %es:12(%edi) )
21201
21202 SRC( movl 16(%esi), %ebx )
21203 SRC( movl 20(%esi), %edx )
21204 adcl %ebx, %eax
21205 -DST( movl %ebx, 16(%edi) )
21206 +DST( movl %ebx, %es:16(%edi) )
21207 adcl %edx, %eax
21208 -DST( movl %edx, 20(%edi) )
21209 +DST( movl %edx, %es:20(%edi) )
21210
21211 SRC( movl 24(%esi), %ebx )
21212 SRC( movl 28(%esi), %edx )
21213 adcl %ebx, %eax
21214 -DST( movl %ebx, 24(%edi) )
21215 +DST( movl %ebx, %es:24(%edi) )
21216 adcl %edx, %eax
21217 -DST( movl %edx, 28(%edi) )
21218 +DST( movl %edx, %es:28(%edi) )
21219
21220 lea 32(%esi), %esi
21221 lea 32(%edi), %edi
21222 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21223 shrl $2, %edx # This clears CF
21224 SRC(3: movl (%esi), %ebx )
21225 adcl %ebx, %eax
21226 -DST( movl %ebx, (%edi) )
21227 +DST( movl %ebx, %es:(%edi) )
21228 lea 4(%esi), %esi
21229 lea 4(%edi), %edi
21230 dec %edx
21231 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21232 jb 5f
21233 SRC( movw (%esi), %cx )
21234 leal 2(%esi), %esi
21235 -DST( movw %cx, (%edi) )
21236 +DST( movw %cx, %es:(%edi) )
21237 leal 2(%edi), %edi
21238 je 6f
21239 shll $16,%ecx
21240 SRC(5: movb (%esi), %cl )
21241 -DST( movb %cl, (%edi) )
21242 +DST( movb %cl, %es:(%edi) )
21243 6: addl %ecx, %eax
21244 adcl $0, %eax
21245 7:
21246 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21247
21248 6001:
21249 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21250 - movl $-EFAULT, (%ebx)
21251 + movl $-EFAULT, %ss:(%ebx)
21252
21253 # zero the complete destination - computing the rest
21254 # is too much work
21255 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21256
21257 6002:
21258 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21259 - movl $-EFAULT,(%ebx)
21260 + movl $-EFAULT,%ss:(%ebx)
21261 jmp 5000b
21262
21263 .previous
21264
21265 + pushl_cfi %ss
21266 + popl_cfi %ds
21267 + pushl_cfi %ss
21268 + popl_cfi %es
21269 popl_cfi %ebx
21270 CFI_RESTORE ebx
21271 popl_cfi %esi
21272 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21273 popl_cfi %ecx # equivalent to addl $4,%esp
21274 ret
21275 CFI_ENDPROC
21276 -ENDPROC(csum_partial_copy_generic)
21277 +ENDPROC(csum_partial_copy_generic_to_user)
21278
21279 #else
21280
21281 /* Version for PentiumII/PPro */
21282
21283 #define ROUND1(x) \
21284 + nop; nop; nop; \
21285 SRC(movl x(%esi), %ebx ) ; \
21286 addl %ebx, %eax ; \
21287 - DST(movl %ebx, x(%edi) ) ;
21288 + DST(movl %ebx, %es:x(%edi)) ;
21289
21290 #define ROUND(x) \
21291 + nop; nop; nop; \
21292 SRC(movl x(%esi), %ebx ) ; \
21293 adcl %ebx, %eax ; \
21294 - DST(movl %ebx, x(%edi) ) ;
21295 + DST(movl %ebx, %es:x(%edi)) ;
21296
21297 #define ARGBASE 12
21298 -
21299 -ENTRY(csum_partial_copy_generic)
21300 +
21301 +ENTRY(csum_partial_copy_generic_to_user)
21302 CFI_STARTPROC
21303 +
21304 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21305 + pushl_cfi %gs
21306 + popl_cfi %es
21307 + jmp csum_partial_copy_generic
21308 +#endif
21309 +
21310 +ENTRY(csum_partial_copy_generic_from_user)
21311 +
21312 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21313 + pushl_cfi %gs
21314 + popl_cfi %ds
21315 +#endif
21316 +
21317 +ENTRY(csum_partial_copy_generic)
21318 pushl_cfi %ebx
21319 CFI_REL_OFFSET ebx, 0
21320 pushl_cfi %edi
21321 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21322 subl %ebx, %edi
21323 lea -1(%esi),%edx
21324 andl $-32,%edx
21325 - lea 3f(%ebx,%ebx), %ebx
21326 + lea 3f(%ebx,%ebx,2), %ebx
21327 testl %esi, %esi
21328 jmp *%ebx
21329 1: addl $64,%esi
21330 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21331 jb 5f
21332 SRC( movw (%esi), %dx )
21333 leal 2(%esi), %esi
21334 -DST( movw %dx, (%edi) )
21335 +DST( movw %dx, %es:(%edi) )
21336 leal 2(%edi), %edi
21337 je 6f
21338 shll $16,%edx
21339 5:
21340 SRC( movb (%esi), %dl )
21341 -DST( movb %dl, (%edi) )
21342 +DST( movb %dl, %es:(%edi) )
21343 6: addl %edx, %eax
21344 adcl $0, %eax
21345 7:
21346 .section .fixup, "ax"
21347 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21348 - movl $-EFAULT, (%ebx)
21349 + movl $-EFAULT, %ss:(%ebx)
21350 # zero the complete destination (computing the rest is too much work)
21351 movl ARGBASE+8(%esp),%edi # dst
21352 movl ARGBASE+12(%esp),%ecx # len
21353 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21354 rep; stosb
21355 jmp 7b
21356 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21357 - movl $-EFAULT, (%ebx)
21358 + movl $-EFAULT, %ss:(%ebx)
21359 jmp 7b
21360 .previous
21361
21362 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21363 + pushl_cfi %ss
21364 + popl_cfi %ds
21365 + pushl_cfi %ss
21366 + popl_cfi %es
21367 +#endif
21368 +
21369 popl_cfi %esi
21370 CFI_RESTORE esi
21371 popl_cfi %edi
21372 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21373 CFI_RESTORE ebx
21374 ret
21375 CFI_ENDPROC
21376 -ENDPROC(csum_partial_copy_generic)
21377 +ENDPROC(csum_partial_copy_generic_to_user)
21378
21379 #undef ROUND
21380 #undef ROUND1
21381 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21382 index f2145cf..cea889d 100644
21383 --- a/arch/x86/lib/clear_page_64.S
21384 +++ b/arch/x86/lib/clear_page_64.S
21385 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21386 movl $4096/8,%ecx
21387 xorl %eax,%eax
21388 rep stosq
21389 + pax_force_retaddr
21390 ret
21391 CFI_ENDPROC
21392 ENDPROC(clear_page_c)
21393 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21394 movl $4096,%ecx
21395 xorl %eax,%eax
21396 rep stosb
21397 + pax_force_retaddr
21398 ret
21399 CFI_ENDPROC
21400 ENDPROC(clear_page_c_e)
21401 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21402 leaq 64(%rdi),%rdi
21403 jnz .Lloop
21404 nop
21405 + pax_force_retaddr
21406 ret
21407 CFI_ENDPROC
21408 .Lclear_page_end:
21409 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21410
21411 #include <asm/cpufeature.h>
21412
21413 - .section .altinstr_replacement,"ax"
21414 + .section .altinstr_replacement,"a"
21415 1: .byte 0xeb /* jmp <disp8> */
21416 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21417 2: .byte 0xeb /* jmp <disp8> */
21418 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21419 index 1e572c5..2a162cd 100644
21420 --- a/arch/x86/lib/cmpxchg16b_emu.S
21421 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21422 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21423
21424 popf
21425 mov $1, %al
21426 + pax_force_retaddr
21427 ret
21428
21429 not_same:
21430 popf
21431 xor %al,%al
21432 + pax_force_retaddr
21433 ret
21434
21435 CFI_ENDPROC
21436 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21437 index 01c805b..dccb07f 100644
21438 --- a/arch/x86/lib/copy_page_64.S
21439 +++ b/arch/x86/lib/copy_page_64.S
21440 @@ -9,6 +9,7 @@ copy_page_c:
21441 CFI_STARTPROC
21442 movl $4096/8,%ecx
21443 rep movsq
21444 + pax_force_retaddr
21445 ret
21446 CFI_ENDPROC
21447 ENDPROC(copy_page_c)
21448 @@ -39,7 +40,7 @@ ENTRY(copy_page)
21449 movq 16 (%rsi), %rdx
21450 movq 24 (%rsi), %r8
21451 movq 32 (%rsi), %r9
21452 - movq 40 (%rsi), %r10
21453 + movq 40 (%rsi), %r13
21454 movq 48 (%rsi), %r11
21455 movq 56 (%rsi), %r12
21456
21457 @@ -50,7 +51,7 @@ ENTRY(copy_page)
21458 movq %rdx, 16 (%rdi)
21459 movq %r8, 24 (%rdi)
21460 movq %r9, 32 (%rdi)
21461 - movq %r10, 40 (%rdi)
21462 + movq %r13, 40 (%rdi)
21463 movq %r11, 48 (%rdi)
21464 movq %r12, 56 (%rdi)
21465
21466 @@ -69,7 +70,7 @@ ENTRY(copy_page)
21467 movq 16 (%rsi), %rdx
21468 movq 24 (%rsi), %r8
21469 movq 32 (%rsi), %r9
21470 - movq 40 (%rsi), %r10
21471 + movq 40 (%rsi), %r13
21472 movq 48 (%rsi), %r11
21473 movq 56 (%rsi), %r12
21474
21475 @@ -78,7 +79,7 @@ ENTRY(copy_page)
21476 movq %rdx, 16 (%rdi)
21477 movq %r8, 24 (%rdi)
21478 movq %r9, 32 (%rdi)
21479 - movq %r10, 40 (%rdi)
21480 + movq %r13, 40 (%rdi)
21481 movq %r11, 48 (%rdi)
21482 movq %r12, 56 (%rdi)
21483
21484 @@ -95,6 +96,7 @@ ENTRY(copy_page)
21485 CFI_RESTORE r13
21486 addq $3*8,%rsp
21487 CFI_ADJUST_CFA_OFFSET -3*8
21488 + pax_force_retaddr
21489 ret
21490 .Lcopy_page_end:
21491 CFI_ENDPROC
21492 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
21493
21494 #include <asm/cpufeature.h>
21495
21496 - .section .altinstr_replacement,"ax"
21497 + .section .altinstr_replacement,"a"
21498 1: .byte 0xeb /* jmp <disp8> */
21499 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21500 2:
21501 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21502 index 0248402..821c786 100644
21503 --- a/arch/x86/lib/copy_user_64.S
21504 +++ b/arch/x86/lib/copy_user_64.S
21505 @@ -16,6 +16,7 @@
21506 #include <asm/thread_info.h>
21507 #include <asm/cpufeature.h>
21508 #include <asm/alternative-asm.h>
21509 +#include <asm/pgtable.h>
21510
21511 /*
21512 * By placing feature2 after feature1 in altinstructions section, we logically
21513 @@ -29,7 +30,7 @@
21514 .byte 0xe9 /* 32bit jump */
21515 .long \orig-1f /* by default jump to orig */
21516 1:
21517 - .section .altinstr_replacement,"ax"
21518 + .section .altinstr_replacement,"a"
21519 2: .byte 0xe9 /* near jump with 32bit immediate */
21520 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21521 3: .byte 0xe9 /* near jump with 32bit immediate */
21522 @@ -71,47 +72,20 @@
21523 #endif
21524 .endm
21525
21526 -/* Standard copy_to_user with segment limit checking */
21527 -ENTRY(_copy_to_user)
21528 - CFI_STARTPROC
21529 - GET_THREAD_INFO(%rax)
21530 - movq %rdi,%rcx
21531 - addq %rdx,%rcx
21532 - jc bad_to_user
21533 - cmpq TI_addr_limit(%rax),%rcx
21534 - ja bad_to_user
21535 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21536 - copy_user_generic_unrolled,copy_user_generic_string, \
21537 - copy_user_enhanced_fast_string
21538 - CFI_ENDPROC
21539 -ENDPROC(_copy_to_user)
21540 -
21541 -/* Standard copy_from_user with segment limit checking */
21542 -ENTRY(_copy_from_user)
21543 - CFI_STARTPROC
21544 - GET_THREAD_INFO(%rax)
21545 - movq %rsi,%rcx
21546 - addq %rdx,%rcx
21547 - jc bad_from_user
21548 - cmpq TI_addr_limit(%rax),%rcx
21549 - ja bad_from_user
21550 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21551 - copy_user_generic_unrolled,copy_user_generic_string, \
21552 - copy_user_enhanced_fast_string
21553 - CFI_ENDPROC
21554 -ENDPROC(_copy_from_user)
21555 -
21556 .section .fixup,"ax"
21557 /* must zero dest */
21558 ENTRY(bad_from_user)
21559 bad_from_user:
21560 CFI_STARTPROC
21561 + testl %edx,%edx
21562 + js bad_to_user
21563 movl %edx,%ecx
21564 xorl %eax,%eax
21565 rep
21566 stosb
21567 bad_to_user:
21568 movl %edx,%eax
21569 + pax_force_retaddr
21570 ret
21571 CFI_ENDPROC
21572 ENDPROC(bad_from_user)
21573 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21574 jz 17f
21575 1: movq (%rsi),%r8
21576 2: movq 1*8(%rsi),%r9
21577 -3: movq 2*8(%rsi),%r10
21578 +3: movq 2*8(%rsi),%rax
21579 4: movq 3*8(%rsi),%r11
21580 5: movq %r8,(%rdi)
21581 6: movq %r9,1*8(%rdi)
21582 -7: movq %r10,2*8(%rdi)
21583 +7: movq %rax,2*8(%rdi)
21584 8: movq %r11,3*8(%rdi)
21585 9: movq 4*8(%rsi),%r8
21586 10: movq 5*8(%rsi),%r9
21587 -11: movq 6*8(%rsi),%r10
21588 +11: movq 6*8(%rsi),%rax
21589 12: movq 7*8(%rsi),%r11
21590 13: movq %r8,4*8(%rdi)
21591 14: movq %r9,5*8(%rdi)
21592 -15: movq %r10,6*8(%rdi)
21593 +15: movq %rax,6*8(%rdi)
21594 16: movq %r11,7*8(%rdi)
21595 leaq 64(%rsi),%rsi
21596 leaq 64(%rdi),%rdi
21597 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21598 decl %ecx
21599 jnz 21b
21600 23: xor %eax,%eax
21601 + pax_force_retaddr
21602 ret
21603
21604 .section .fixup,"ax"
21605 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21606 3: rep
21607 movsb
21608 4: xorl %eax,%eax
21609 + pax_force_retaddr
21610 ret
21611
21612 .section .fixup,"ax"
21613 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21614 1: rep
21615 movsb
21616 2: xorl %eax,%eax
21617 + pax_force_retaddr
21618 ret
21619
21620 .section .fixup,"ax"
21621 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21622 index cb0c112..e3a6895 100644
21623 --- a/arch/x86/lib/copy_user_nocache_64.S
21624 +++ b/arch/x86/lib/copy_user_nocache_64.S
21625 @@ -8,12 +8,14 @@
21626
21627 #include <linux/linkage.h>
21628 #include <asm/dwarf2.h>
21629 +#include <asm/alternative-asm.h>
21630
21631 #define FIX_ALIGNMENT 1
21632
21633 #include <asm/current.h>
21634 #include <asm/asm-offsets.h>
21635 #include <asm/thread_info.h>
21636 +#include <asm/pgtable.h>
21637
21638 .macro ALIGN_DESTINATION
21639 #ifdef FIX_ALIGNMENT
21640 @@ -50,6 +52,15 @@
21641 */
21642 ENTRY(__copy_user_nocache)
21643 CFI_STARTPROC
21644 +
21645 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21646 + mov $PAX_USER_SHADOW_BASE,%rcx
21647 + cmp %rcx,%rsi
21648 + jae 1f
21649 + add %rcx,%rsi
21650 +1:
21651 +#endif
21652 +
21653 cmpl $8,%edx
21654 jb 20f /* less then 8 bytes, go to byte copy loop */
21655 ALIGN_DESTINATION
21656 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21657 jz 17f
21658 1: movq (%rsi),%r8
21659 2: movq 1*8(%rsi),%r9
21660 -3: movq 2*8(%rsi),%r10
21661 +3: movq 2*8(%rsi),%rax
21662 4: movq 3*8(%rsi),%r11
21663 5: movnti %r8,(%rdi)
21664 6: movnti %r9,1*8(%rdi)
21665 -7: movnti %r10,2*8(%rdi)
21666 +7: movnti %rax,2*8(%rdi)
21667 8: movnti %r11,3*8(%rdi)
21668 9: movq 4*8(%rsi),%r8
21669 10: movq 5*8(%rsi),%r9
21670 -11: movq 6*8(%rsi),%r10
21671 +11: movq 6*8(%rsi),%rax
21672 12: movq 7*8(%rsi),%r11
21673 13: movnti %r8,4*8(%rdi)
21674 14: movnti %r9,5*8(%rdi)
21675 -15: movnti %r10,6*8(%rdi)
21676 +15: movnti %rax,6*8(%rdi)
21677 16: movnti %r11,7*8(%rdi)
21678 leaq 64(%rsi),%rsi
21679 leaq 64(%rdi),%rdi
21680 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21681 jnz 21b
21682 23: xorl %eax,%eax
21683 sfence
21684 + pax_force_retaddr
21685 ret
21686
21687 .section .fixup,"ax"
21688 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21689 index fb903b7..c92b7f7 100644
21690 --- a/arch/x86/lib/csum-copy_64.S
21691 +++ b/arch/x86/lib/csum-copy_64.S
21692 @@ -8,6 +8,7 @@
21693 #include <linux/linkage.h>
21694 #include <asm/dwarf2.h>
21695 #include <asm/errno.h>
21696 +#include <asm/alternative-asm.h>
21697
21698 /*
21699 * Checksum copy with exception handling.
21700 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21701 CFI_RESTORE rbp
21702 addq $7*8, %rsp
21703 CFI_ADJUST_CFA_OFFSET -7*8
21704 + pax_force_retaddr 0, 1
21705 ret
21706 CFI_RESTORE_STATE
21707
21708 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21709 index 459b58a..9570bc7 100644
21710 --- a/arch/x86/lib/csum-wrappers_64.c
21711 +++ b/arch/x86/lib/csum-wrappers_64.c
21712 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21713 len -= 2;
21714 }
21715 }
21716 - isum = csum_partial_copy_generic((__force const void *)src,
21717 +
21718 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21719 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21720 + src += PAX_USER_SHADOW_BASE;
21721 +#endif
21722 +
21723 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21724 dst, len, isum, errp, NULL);
21725 if (unlikely(*errp))
21726 goto out_err;
21727 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21728 }
21729
21730 *errp = 0;
21731 - return csum_partial_copy_generic(src, (void __force *)dst,
21732 +
21733 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21734 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21735 + dst += PAX_USER_SHADOW_BASE;
21736 +#endif
21737 +
21738 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21739 len, isum, NULL, errp);
21740 }
21741 EXPORT_SYMBOL(csum_partial_copy_to_user);
21742 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21743 index 51f1504..ddac4c1 100644
21744 --- a/arch/x86/lib/getuser.S
21745 +++ b/arch/x86/lib/getuser.S
21746 @@ -33,15 +33,38 @@
21747 #include <asm/asm-offsets.h>
21748 #include <asm/thread_info.h>
21749 #include <asm/asm.h>
21750 +#include <asm/segment.h>
21751 +#include <asm/pgtable.h>
21752 +#include <asm/alternative-asm.h>
21753 +
21754 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21755 +#define __copyuser_seg gs;
21756 +#else
21757 +#define __copyuser_seg
21758 +#endif
21759
21760 .text
21761 ENTRY(__get_user_1)
21762 CFI_STARTPROC
21763 +
21764 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21765 GET_THREAD_INFO(%_ASM_DX)
21766 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21767 jae bad_get_user
21768 -1: movzb (%_ASM_AX),%edx
21769 +
21770 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21771 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21772 + cmp %_ASM_DX,%_ASM_AX
21773 + jae 1234f
21774 + add %_ASM_DX,%_ASM_AX
21775 +1234:
21776 +#endif
21777 +
21778 +#endif
21779 +
21780 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21781 xor %eax,%eax
21782 + pax_force_retaddr
21783 ret
21784 CFI_ENDPROC
21785 ENDPROC(__get_user_1)
21786 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21787 ENTRY(__get_user_2)
21788 CFI_STARTPROC
21789 add $1,%_ASM_AX
21790 +
21791 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21792 jc bad_get_user
21793 GET_THREAD_INFO(%_ASM_DX)
21794 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21795 jae bad_get_user
21796 -2: movzwl -1(%_ASM_AX),%edx
21797 +
21798 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21799 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21800 + cmp %_ASM_DX,%_ASM_AX
21801 + jae 1234f
21802 + add %_ASM_DX,%_ASM_AX
21803 +1234:
21804 +#endif
21805 +
21806 +#endif
21807 +
21808 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21809 xor %eax,%eax
21810 + pax_force_retaddr
21811 ret
21812 CFI_ENDPROC
21813 ENDPROC(__get_user_2)
21814 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21815 ENTRY(__get_user_4)
21816 CFI_STARTPROC
21817 add $3,%_ASM_AX
21818 +
21819 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21820 jc bad_get_user
21821 GET_THREAD_INFO(%_ASM_DX)
21822 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21823 jae bad_get_user
21824 -3: mov -3(%_ASM_AX),%edx
21825 +
21826 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21827 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21828 + cmp %_ASM_DX,%_ASM_AX
21829 + jae 1234f
21830 + add %_ASM_DX,%_ASM_AX
21831 +1234:
21832 +#endif
21833 +
21834 +#endif
21835 +
21836 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21837 xor %eax,%eax
21838 + pax_force_retaddr
21839 ret
21840 CFI_ENDPROC
21841 ENDPROC(__get_user_4)
21842 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21843 GET_THREAD_INFO(%_ASM_DX)
21844 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21845 jae bad_get_user
21846 +
21847 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21848 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21849 + cmp %_ASM_DX,%_ASM_AX
21850 + jae 1234f
21851 + add %_ASM_DX,%_ASM_AX
21852 +1234:
21853 +#endif
21854 +
21855 4: movq -7(%_ASM_AX),%_ASM_DX
21856 xor %eax,%eax
21857 + pax_force_retaddr
21858 ret
21859 CFI_ENDPROC
21860 ENDPROC(__get_user_8)
21861 @@ -91,6 +152,7 @@ bad_get_user:
21862 CFI_STARTPROC
21863 xor %edx,%edx
21864 mov $(-EFAULT),%_ASM_AX
21865 + pax_force_retaddr
21866 ret
21867 CFI_ENDPROC
21868 END(bad_get_user)
21869 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21870 index 5a1f9f3..ba9f577 100644
21871 --- a/arch/x86/lib/insn.c
21872 +++ b/arch/x86/lib/insn.c
21873 @@ -21,6 +21,11 @@
21874 #include <linux/string.h>
21875 #include <asm/inat.h>
21876 #include <asm/insn.h>
21877 +#ifdef __KERNEL__
21878 +#include <asm/pgtable_types.h>
21879 +#else
21880 +#define ktla_ktva(addr) addr
21881 +#endif
21882
21883 /* Verify next sizeof(t) bytes can be on the same instruction */
21884 #define validate_next(t, insn, n) \
21885 @@ -49,8 +54,8 @@
21886 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21887 {
21888 memset(insn, 0, sizeof(*insn));
21889 - insn->kaddr = kaddr;
21890 - insn->next_byte = kaddr;
21891 + insn->kaddr = ktla_ktva(kaddr);
21892 + insn->next_byte = ktla_ktva(kaddr);
21893 insn->x86_64 = x86_64 ? 1 : 0;
21894 insn->opnd_bytes = 4;
21895 if (x86_64)
21896 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21897 index 05a95e7..326f2fa 100644
21898 --- a/arch/x86/lib/iomap_copy_64.S
21899 +++ b/arch/x86/lib/iomap_copy_64.S
21900 @@ -17,6 +17,7 @@
21901
21902 #include <linux/linkage.h>
21903 #include <asm/dwarf2.h>
21904 +#include <asm/alternative-asm.h>
21905
21906 /*
21907 * override generic version in lib/iomap_copy.c
21908 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21909 CFI_STARTPROC
21910 movl %edx,%ecx
21911 rep movsd
21912 + pax_force_retaddr
21913 ret
21914 CFI_ENDPROC
21915 ENDPROC(__iowrite32_copy)
21916 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21917 index efbf2a0..8893637 100644
21918 --- a/arch/x86/lib/memcpy_64.S
21919 +++ b/arch/x86/lib/memcpy_64.S
21920 @@ -34,6 +34,7 @@
21921 rep movsq
21922 movl %edx, %ecx
21923 rep movsb
21924 + pax_force_retaddr
21925 ret
21926 .Lmemcpy_e:
21927 .previous
21928 @@ -51,6 +52,7 @@
21929
21930 movl %edx, %ecx
21931 rep movsb
21932 + pax_force_retaddr
21933 ret
21934 .Lmemcpy_e_e:
21935 .previous
21936 @@ -81,13 +83,13 @@ ENTRY(memcpy)
21937 */
21938 movq 0*8(%rsi), %r8
21939 movq 1*8(%rsi), %r9
21940 - movq 2*8(%rsi), %r10
21941 + movq 2*8(%rsi), %rcx
21942 movq 3*8(%rsi), %r11
21943 leaq 4*8(%rsi), %rsi
21944
21945 movq %r8, 0*8(%rdi)
21946 movq %r9, 1*8(%rdi)
21947 - movq %r10, 2*8(%rdi)
21948 + movq %rcx, 2*8(%rdi)
21949 movq %r11, 3*8(%rdi)
21950 leaq 4*8(%rdi), %rdi
21951 jae .Lcopy_forward_loop
21952 @@ -110,12 +112,12 @@ ENTRY(memcpy)
21953 subq $0x20, %rdx
21954 movq -1*8(%rsi), %r8
21955 movq -2*8(%rsi), %r9
21956 - movq -3*8(%rsi), %r10
21957 + movq -3*8(%rsi), %rcx
21958 movq -4*8(%rsi), %r11
21959 leaq -4*8(%rsi), %rsi
21960 movq %r8, -1*8(%rdi)
21961 movq %r9, -2*8(%rdi)
21962 - movq %r10, -3*8(%rdi)
21963 + movq %rcx, -3*8(%rdi)
21964 movq %r11, -4*8(%rdi)
21965 leaq -4*8(%rdi), %rdi
21966 jae .Lcopy_backward_loop
21967 @@ -135,12 +137,13 @@ ENTRY(memcpy)
21968 */
21969 movq 0*8(%rsi), %r8
21970 movq 1*8(%rsi), %r9
21971 - movq -2*8(%rsi, %rdx), %r10
21972 + movq -2*8(%rsi, %rdx), %rcx
21973 movq -1*8(%rsi, %rdx), %r11
21974 movq %r8, 0*8(%rdi)
21975 movq %r9, 1*8(%rdi)
21976 - movq %r10, -2*8(%rdi, %rdx)
21977 + movq %rcx, -2*8(%rdi, %rdx)
21978 movq %r11, -1*8(%rdi, %rdx)
21979 + pax_force_retaddr
21980 retq
21981 .p2align 4
21982 .Lless_16bytes:
21983 @@ -153,6 +156,7 @@ ENTRY(memcpy)
21984 movq -1*8(%rsi, %rdx), %r9
21985 movq %r8, 0*8(%rdi)
21986 movq %r9, -1*8(%rdi, %rdx)
21987 + pax_force_retaddr
21988 retq
21989 .p2align 4
21990 .Lless_8bytes:
21991 @@ -166,6 +170,7 @@ ENTRY(memcpy)
21992 movl -4(%rsi, %rdx), %r8d
21993 movl %ecx, (%rdi)
21994 movl %r8d, -4(%rdi, %rdx)
21995 + pax_force_retaddr
21996 retq
21997 .p2align 4
21998 .Lless_3bytes:
21999 @@ -183,6 +188,7 @@ ENTRY(memcpy)
22000 jnz .Lloop_1
22001
22002 .Lend:
22003 + pax_force_retaddr
22004 retq
22005 CFI_ENDPROC
22006 ENDPROC(memcpy)
22007 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22008 index ee16461..c39c199 100644
22009 --- a/arch/x86/lib/memmove_64.S
22010 +++ b/arch/x86/lib/memmove_64.S
22011 @@ -61,13 +61,13 @@ ENTRY(memmove)
22012 5:
22013 sub $0x20, %rdx
22014 movq 0*8(%rsi), %r11
22015 - movq 1*8(%rsi), %r10
22016 + movq 1*8(%rsi), %rcx
22017 movq 2*8(%rsi), %r9
22018 movq 3*8(%rsi), %r8
22019 leaq 4*8(%rsi), %rsi
22020
22021 movq %r11, 0*8(%rdi)
22022 - movq %r10, 1*8(%rdi)
22023 + movq %rcx, 1*8(%rdi)
22024 movq %r9, 2*8(%rdi)
22025 movq %r8, 3*8(%rdi)
22026 leaq 4*8(%rdi), %rdi
22027 @@ -81,10 +81,10 @@ ENTRY(memmove)
22028 4:
22029 movq %rdx, %rcx
22030 movq -8(%rsi, %rdx), %r11
22031 - lea -8(%rdi, %rdx), %r10
22032 + lea -8(%rdi, %rdx), %r9
22033 shrq $3, %rcx
22034 rep movsq
22035 - movq %r11, (%r10)
22036 + movq %r11, (%r9)
22037 jmp 13f
22038 .Lmemmove_end_forward:
22039
22040 @@ -95,14 +95,14 @@ ENTRY(memmove)
22041 7:
22042 movq %rdx, %rcx
22043 movq (%rsi), %r11
22044 - movq %rdi, %r10
22045 + movq %rdi, %r9
22046 leaq -8(%rsi, %rdx), %rsi
22047 leaq -8(%rdi, %rdx), %rdi
22048 shrq $3, %rcx
22049 std
22050 rep movsq
22051 cld
22052 - movq %r11, (%r10)
22053 + movq %r11, (%r9)
22054 jmp 13f
22055
22056 /*
22057 @@ -127,13 +127,13 @@ ENTRY(memmove)
22058 8:
22059 subq $0x20, %rdx
22060 movq -1*8(%rsi), %r11
22061 - movq -2*8(%rsi), %r10
22062 + movq -2*8(%rsi), %rcx
22063 movq -3*8(%rsi), %r9
22064 movq -4*8(%rsi), %r8
22065 leaq -4*8(%rsi), %rsi
22066
22067 movq %r11, -1*8(%rdi)
22068 - movq %r10, -2*8(%rdi)
22069 + movq %rcx, -2*8(%rdi)
22070 movq %r9, -3*8(%rdi)
22071 movq %r8, -4*8(%rdi)
22072 leaq -4*8(%rdi), %rdi
22073 @@ -151,11 +151,11 @@ ENTRY(memmove)
22074 * Move data from 16 bytes to 31 bytes.
22075 */
22076 movq 0*8(%rsi), %r11
22077 - movq 1*8(%rsi), %r10
22078 + movq 1*8(%rsi), %rcx
22079 movq -2*8(%rsi, %rdx), %r9
22080 movq -1*8(%rsi, %rdx), %r8
22081 movq %r11, 0*8(%rdi)
22082 - movq %r10, 1*8(%rdi)
22083 + movq %rcx, 1*8(%rdi)
22084 movq %r9, -2*8(%rdi, %rdx)
22085 movq %r8, -1*8(%rdi, %rdx)
22086 jmp 13f
22087 @@ -167,9 +167,9 @@ ENTRY(memmove)
22088 * Move data from 8 bytes to 15 bytes.
22089 */
22090 movq 0*8(%rsi), %r11
22091 - movq -1*8(%rsi, %rdx), %r10
22092 + movq -1*8(%rsi, %rdx), %r9
22093 movq %r11, 0*8(%rdi)
22094 - movq %r10, -1*8(%rdi, %rdx)
22095 + movq %r9, -1*8(%rdi, %rdx)
22096 jmp 13f
22097 10:
22098 cmpq $4, %rdx
22099 @@ -178,9 +178,9 @@ ENTRY(memmove)
22100 * Move data from 4 bytes to 7 bytes.
22101 */
22102 movl (%rsi), %r11d
22103 - movl -4(%rsi, %rdx), %r10d
22104 + movl -4(%rsi, %rdx), %r9d
22105 movl %r11d, (%rdi)
22106 - movl %r10d, -4(%rdi, %rdx)
22107 + movl %r9d, -4(%rdi, %rdx)
22108 jmp 13f
22109 11:
22110 cmp $2, %rdx
22111 @@ -189,9 +189,9 @@ ENTRY(memmove)
22112 * Move data from 2 bytes to 3 bytes.
22113 */
22114 movw (%rsi), %r11w
22115 - movw -2(%rsi, %rdx), %r10w
22116 + movw -2(%rsi, %rdx), %r9w
22117 movw %r11w, (%rdi)
22118 - movw %r10w, -2(%rdi, %rdx)
22119 + movw %r9w, -2(%rdi, %rdx)
22120 jmp 13f
22121 12:
22122 cmp $1, %rdx
22123 @@ -202,6 +202,7 @@ ENTRY(memmove)
22124 movb (%rsi), %r11b
22125 movb %r11b, (%rdi)
22126 13:
22127 + pax_force_retaddr
22128 retq
22129 CFI_ENDPROC
22130
22131 @@ -210,6 +211,7 @@ ENTRY(memmove)
22132 /* Forward moving data. */
22133 movq %rdx, %rcx
22134 rep movsb
22135 + pax_force_retaddr
22136 retq
22137 .Lmemmove_end_forward_efs:
22138 .previous
22139 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22140 index 79bd454..dff325a 100644
22141 --- a/arch/x86/lib/memset_64.S
22142 +++ b/arch/x86/lib/memset_64.S
22143 @@ -31,6 +31,7 @@
22144 movl %r8d,%ecx
22145 rep stosb
22146 movq %r9,%rax
22147 + pax_force_retaddr
22148 ret
22149 .Lmemset_e:
22150 .previous
22151 @@ -53,6 +54,7 @@
22152 movl %edx,%ecx
22153 rep stosb
22154 movq %r9,%rax
22155 + pax_force_retaddr
22156 ret
22157 .Lmemset_e_e:
22158 .previous
22159 @@ -60,13 +62,13 @@
22160 ENTRY(memset)
22161 ENTRY(__memset)
22162 CFI_STARTPROC
22163 - movq %rdi,%r10
22164 movq %rdx,%r11
22165
22166 /* expand byte value */
22167 movzbl %sil,%ecx
22168 movabs $0x0101010101010101,%rax
22169 mul %rcx /* with rax, clobbers rdx */
22170 + movq %rdi,%rdx
22171
22172 /* align dst */
22173 movl %edi,%r9d
22174 @@ -120,7 +122,8 @@ ENTRY(__memset)
22175 jnz .Lloop_1
22176
22177 .Lende:
22178 - movq %r10,%rax
22179 + movq %rdx,%rax
22180 + pax_force_retaddr
22181 ret
22182
22183 CFI_RESTORE_STATE
22184 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22185 index c9f2d9b..e7fd2c0 100644
22186 --- a/arch/x86/lib/mmx_32.c
22187 +++ b/arch/x86/lib/mmx_32.c
22188 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22189 {
22190 void *p;
22191 int i;
22192 + unsigned long cr0;
22193
22194 if (unlikely(in_interrupt()))
22195 return __memcpy(to, from, len);
22196 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22197 kernel_fpu_begin();
22198
22199 __asm__ __volatile__ (
22200 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22201 - " prefetch 64(%0)\n"
22202 - " prefetch 128(%0)\n"
22203 - " prefetch 192(%0)\n"
22204 - " prefetch 256(%0)\n"
22205 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22206 + " prefetch 64(%1)\n"
22207 + " prefetch 128(%1)\n"
22208 + " prefetch 192(%1)\n"
22209 + " prefetch 256(%1)\n"
22210 "2: \n"
22211 ".section .fixup, \"ax\"\n"
22212 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22213 + "3: \n"
22214 +
22215 +#ifdef CONFIG_PAX_KERNEXEC
22216 + " movl %%cr0, %0\n"
22217 + " movl %0, %%eax\n"
22218 + " andl $0xFFFEFFFF, %%eax\n"
22219 + " movl %%eax, %%cr0\n"
22220 +#endif
22221 +
22222 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22223 +
22224 +#ifdef CONFIG_PAX_KERNEXEC
22225 + " movl %0, %%cr0\n"
22226 +#endif
22227 +
22228 " jmp 2b\n"
22229 ".previous\n"
22230 _ASM_EXTABLE(1b, 3b)
22231 - : : "r" (from));
22232 + : "=&r" (cr0) : "r" (from) : "ax");
22233
22234 for ( ; i > 5; i--) {
22235 __asm__ __volatile__ (
22236 - "1: prefetch 320(%0)\n"
22237 - "2: movq (%0), %%mm0\n"
22238 - " movq 8(%0), %%mm1\n"
22239 - " movq 16(%0), %%mm2\n"
22240 - " movq 24(%0), %%mm3\n"
22241 - " movq %%mm0, (%1)\n"
22242 - " movq %%mm1, 8(%1)\n"
22243 - " movq %%mm2, 16(%1)\n"
22244 - " movq %%mm3, 24(%1)\n"
22245 - " movq 32(%0), %%mm0\n"
22246 - " movq 40(%0), %%mm1\n"
22247 - " movq 48(%0), %%mm2\n"
22248 - " movq 56(%0), %%mm3\n"
22249 - " movq %%mm0, 32(%1)\n"
22250 - " movq %%mm1, 40(%1)\n"
22251 - " movq %%mm2, 48(%1)\n"
22252 - " movq %%mm3, 56(%1)\n"
22253 + "1: prefetch 320(%1)\n"
22254 + "2: movq (%1), %%mm0\n"
22255 + " movq 8(%1), %%mm1\n"
22256 + " movq 16(%1), %%mm2\n"
22257 + " movq 24(%1), %%mm3\n"
22258 + " movq %%mm0, (%2)\n"
22259 + " movq %%mm1, 8(%2)\n"
22260 + " movq %%mm2, 16(%2)\n"
22261 + " movq %%mm3, 24(%2)\n"
22262 + " movq 32(%1), %%mm0\n"
22263 + " movq 40(%1), %%mm1\n"
22264 + " movq 48(%1), %%mm2\n"
22265 + " movq 56(%1), %%mm3\n"
22266 + " movq %%mm0, 32(%2)\n"
22267 + " movq %%mm1, 40(%2)\n"
22268 + " movq %%mm2, 48(%2)\n"
22269 + " movq %%mm3, 56(%2)\n"
22270 ".section .fixup, \"ax\"\n"
22271 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22272 + "3:\n"
22273 +
22274 +#ifdef CONFIG_PAX_KERNEXEC
22275 + " movl %%cr0, %0\n"
22276 + " movl %0, %%eax\n"
22277 + " andl $0xFFFEFFFF, %%eax\n"
22278 + " movl %%eax, %%cr0\n"
22279 +#endif
22280 +
22281 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22282 +
22283 +#ifdef CONFIG_PAX_KERNEXEC
22284 + " movl %0, %%cr0\n"
22285 +#endif
22286 +
22287 " jmp 2b\n"
22288 ".previous\n"
22289 _ASM_EXTABLE(1b, 3b)
22290 - : : "r" (from), "r" (to) : "memory");
22291 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22292
22293 from += 64;
22294 to += 64;
22295 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22296 static void fast_copy_page(void *to, void *from)
22297 {
22298 int i;
22299 + unsigned long cr0;
22300
22301 kernel_fpu_begin();
22302
22303 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22304 * but that is for later. -AV
22305 */
22306 __asm__ __volatile__(
22307 - "1: prefetch (%0)\n"
22308 - " prefetch 64(%0)\n"
22309 - " prefetch 128(%0)\n"
22310 - " prefetch 192(%0)\n"
22311 - " prefetch 256(%0)\n"
22312 + "1: prefetch (%1)\n"
22313 + " prefetch 64(%1)\n"
22314 + " prefetch 128(%1)\n"
22315 + " prefetch 192(%1)\n"
22316 + " prefetch 256(%1)\n"
22317 "2: \n"
22318 ".section .fixup, \"ax\"\n"
22319 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22320 + "3: \n"
22321 +
22322 +#ifdef CONFIG_PAX_KERNEXEC
22323 + " movl %%cr0, %0\n"
22324 + " movl %0, %%eax\n"
22325 + " andl $0xFFFEFFFF, %%eax\n"
22326 + " movl %%eax, %%cr0\n"
22327 +#endif
22328 +
22329 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22330 +
22331 +#ifdef CONFIG_PAX_KERNEXEC
22332 + " movl %0, %%cr0\n"
22333 +#endif
22334 +
22335 " jmp 2b\n"
22336 ".previous\n"
22337 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22338 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22339
22340 for (i = 0; i < (4096-320)/64; i++) {
22341 __asm__ __volatile__ (
22342 - "1: prefetch 320(%0)\n"
22343 - "2: movq (%0), %%mm0\n"
22344 - " movntq %%mm0, (%1)\n"
22345 - " movq 8(%0), %%mm1\n"
22346 - " movntq %%mm1, 8(%1)\n"
22347 - " movq 16(%0), %%mm2\n"
22348 - " movntq %%mm2, 16(%1)\n"
22349 - " movq 24(%0), %%mm3\n"
22350 - " movntq %%mm3, 24(%1)\n"
22351 - " movq 32(%0), %%mm4\n"
22352 - " movntq %%mm4, 32(%1)\n"
22353 - " movq 40(%0), %%mm5\n"
22354 - " movntq %%mm5, 40(%1)\n"
22355 - " movq 48(%0), %%mm6\n"
22356 - " movntq %%mm6, 48(%1)\n"
22357 - " movq 56(%0), %%mm7\n"
22358 - " movntq %%mm7, 56(%1)\n"
22359 + "1: prefetch 320(%1)\n"
22360 + "2: movq (%1), %%mm0\n"
22361 + " movntq %%mm0, (%2)\n"
22362 + " movq 8(%1), %%mm1\n"
22363 + " movntq %%mm1, 8(%2)\n"
22364 + " movq 16(%1), %%mm2\n"
22365 + " movntq %%mm2, 16(%2)\n"
22366 + " movq 24(%1), %%mm3\n"
22367 + " movntq %%mm3, 24(%2)\n"
22368 + " movq 32(%1), %%mm4\n"
22369 + " movntq %%mm4, 32(%2)\n"
22370 + " movq 40(%1), %%mm5\n"
22371 + " movntq %%mm5, 40(%2)\n"
22372 + " movq 48(%1), %%mm6\n"
22373 + " movntq %%mm6, 48(%2)\n"
22374 + " movq 56(%1), %%mm7\n"
22375 + " movntq %%mm7, 56(%2)\n"
22376 ".section .fixup, \"ax\"\n"
22377 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22378 + "3:\n"
22379 +
22380 +#ifdef CONFIG_PAX_KERNEXEC
22381 + " movl %%cr0, %0\n"
22382 + " movl %0, %%eax\n"
22383 + " andl $0xFFFEFFFF, %%eax\n"
22384 + " movl %%eax, %%cr0\n"
22385 +#endif
22386 +
22387 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22388 +
22389 +#ifdef CONFIG_PAX_KERNEXEC
22390 + " movl %0, %%cr0\n"
22391 +#endif
22392 +
22393 " jmp 2b\n"
22394 ".previous\n"
22395 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22396 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22397
22398 from += 64;
22399 to += 64;
22400 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22401 static void fast_copy_page(void *to, void *from)
22402 {
22403 int i;
22404 + unsigned long cr0;
22405
22406 kernel_fpu_begin();
22407
22408 __asm__ __volatile__ (
22409 - "1: prefetch (%0)\n"
22410 - " prefetch 64(%0)\n"
22411 - " prefetch 128(%0)\n"
22412 - " prefetch 192(%0)\n"
22413 - " prefetch 256(%0)\n"
22414 + "1: prefetch (%1)\n"
22415 + " prefetch 64(%1)\n"
22416 + " prefetch 128(%1)\n"
22417 + " prefetch 192(%1)\n"
22418 + " prefetch 256(%1)\n"
22419 "2: \n"
22420 ".section .fixup, \"ax\"\n"
22421 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22422 + "3: \n"
22423 +
22424 +#ifdef CONFIG_PAX_KERNEXEC
22425 + " movl %%cr0, %0\n"
22426 + " movl %0, %%eax\n"
22427 + " andl $0xFFFEFFFF, %%eax\n"
22428 + " movl %%eax, %%cr0\n"
22429 +#endif
22430 +
22431 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22432 +
22433 +#ifdef CONFIG_PAX_KERNEXEC
22434 + " movl %0, %%cr0\n"
22435 +#endif
22436 +
22437 " jmp 2b\n"
22438 ".previous\n"
22439 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22440 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22441
22442 for (i = 0; i < 4096/64; i++) {
22443 __asm__ __volatile__ (
22444 - "1: prefetch 320(%0)\n"
22445 - "2: movq (%0), %%mm0\n"
22446 - " movq 8(%0), %%mm1\n"
22447 - " movq 16(%0), %%mm2\n"
22448 - " movq 24(%0), %%mm3\n"
22449 - " movq %%mm0, (%1)\n"
22450 - " movq %%mm1, 8(%1)\n"
22451 - " movq %%mm2, 16(%1)\n"
22452 - " movq %%mm3, 24(%1)\n"
22453 - " movq 32(%0), %%mm0\n"
22454 - " movq 40(%0), %%mm1\n"
22455 - " movq 48(%0), %%mm2\n"
22456 - " movq 56(%0), %%mm3\n"
22457 - " movq %%mm0, 32(%1)\n"
22458 - " movq %%mm1, 40(%1)\n"
22459 - " movq %%mm2, 48(%1)\n"
22460 - " movq %%mm3, 56(%1)\n"
22461 + "1: prefetch 320(%1)\n"
22462 + "2: movq (%1), %%mm0\n"
22463 + " movq 8(%1), %%mm1\n"
22464 + " movq 16(%1), %%mm2\n"
22465 + " movq 24(%1), %%mm3\n"
22466 + " movq %%mm0, (%2)\n"
22467 + " movq %%mm1, 8(%2)\n"
22468 + " movq %%mm2, 16(%2)\n"
22469 + " movq %%mm3, 24(%2)\n"
22470 + " movq 32(%1), %%mm0\n"
22471 + " movq 40(%1), %%mm1\n"
22472 + " movq 48(%1), %%mm2\n"
22473 + " movq 56(%1), %%mm3\n"
22474 + " movq %%mm0, 32(%2)\n"
22475 + " movq %%mm1, 40(%2)\n"
22476 + " movq %%mm2, 48(%2)\n"
22477 + " movq %%mm3, 56(%2)\n"
22478 ".section .fixup, \"ax\"\n"
22479 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22480 + "3:\n"
22481 +
22482 +#ifdef CONFIG_PAX_KERNEXEC
22483 + " movl %%cr0, %0\n"
22484 + " movl %0, %%eax\n"
22485 + " andl $0xFFFEFFFF, %%eax\n"
22486 + " movl %%eax, %%cr0\n"
22487 +#endif
22488 +
22489 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22490 +
22491 +#ifdef CONFIG_PAX_KERNEXEC
22492 + " movl %0, %%cr0\n"
22493 +#endif
22494 +
22495 " jmp 2b\n"
22496 ".previous\n"
22497 _ASM_EXTABLE(1b, 3b)
22498 - : : "r" (from), "r" (to) : "memory");
22499 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22500
22501 from += 64;
22502 to += 64;
22503 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22504 index 69fa106..adda88b 100644
22505 --- a/arch/x86/lib/msr-reg.S
22506 +++ b/arch/x86/lib/msr-reg.S
22507 @@ -3,6 +3,7 @@
22508 #include <asm/dwarf2.h>
22509 #include <asm/asm.h>
22510 #include <asm/msr.h>
22511 +#include <asm/alternative-asm.h>
22512
22513 #ifdef CONFIG_X86_64
22514 /*
22515 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22516 CFI_STARTPROC
22517 pushq_cfi %rbx
22518 pushq_cfi %rbp
22519 - movq %rdi, %r10 /* Save pointer */
22520 + movq %rdi, %r9 /* Save pointer */
22521 xorl %r11d, %r11d /* Return value */
22522 movl (%rdi), %eax
22523 movl 4(%rdi), %ecx
22524 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22525 movl 28(%rdi), %edi
22526 CFI_REMEMBER_STATE
22527 1: \op
22528 -2: movl %eax, (%r10)
22529 +2: movl %eax, (%r9)
22530 movl %r11d, %eax /* Return value */
22531 - movl %ecx, 4(%r10)
22532 - movl %edx, 8(%r10)
22533 - movl %ebx, 12(%r10)
22534 - movl %ebp, 20(%r10)
22535 - movl %esi, 24(%r10)
22536 - movl %edi, 28(%r10)
22537 + movl %ecx, 4(%r9)
22538 + movl %edx, 8(%r9)
22539 + movl %ebx, 12(%r9)
22540 + movl %ebp, 20(%r9)
22541 + movl %esi, 24(%r9)
22542 + movl %edi, 28(%r9)
22543 popq_cfi %rbp
22544 popq_cfi %rbx
22545 + pax_force_retaddr
22546 ret
22547 3:
22548 CFI_RESTORE_STATE
22549 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22550 index 36b0d15..d381858 100644
22551 --- a/arch/x86/lib/putuser.S
22552 +++ b/arch/x86/lib/putuser.S
22553 @@ -15,7 +15,9 @@
22554 #include <asm/thread_info.h>
22555 #include <asm/errno.h>
22556 #include <asm/asm.h>
22557 -
22558 +#include <asm/segment.h>
22559 +#include <asm/pgtable.h>
22560 +#include <asm/alternative-asm.h>
22561
22562 /*
22563 * __put_user_X
22564 @@ -29,52 +31,119 @@
22565 * as they get called from within inline assembly.
22566 */
22567
22568 -#define ENTER CFI_STARTPROC ; \
22569 - GET_THREAD_INFO(%_ASM_BX)
22570 -#define EXIT ret ; \
22571 +#define ENTER CFI_STARTPROC
22572 +#define EXIT pax_force_retaddr; ret ; \
22573 CFI_ENDPROC
22574
22575 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22576 +#define _DEST %_ASM_CX,%_ASM_BX
22577 +#else
22578 +#define _DEST %_ASM_CX
22579 +#endif
22580 +
22581 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22582 +#define __copyuser_seg gs;
22583 +#else
22584 +#define __copyuser_seg
22585 +#endif
22586 +
22587 .text
22588 ENTRY(__put_user_1)
22589 ENTER
22590 +
22591 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22592 + GET_THREAD_INFO(%_ASM_BX)
22593 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22594 jae bad_put_user
22595 -1: movb %al,(%_ASM_CX)
22596 +
22597 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22598 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22599 + cmp %_ASM_BX,%_ASM_CX
22600 + jb 1234f
22601 + xor %ebx,%ebx
22602 +1234:
22603 +#endif
22604 +
22605 +#endif
22606 +
22607 +1: __copyuser_seg movb %al,(_DEST)
22608 xor %eax,%eax
22609 EXIT
22610 ENDPROC(__put_user_1)
22611
22612 ENTRY(__put_user_2)
22613 ENTER
22614 +
22615 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22616 + GET_THREAD_INFO(%_ASM_BX)
22617 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22618 sub $1,%_ASM_BX
22619 cmp %_ASM_BX,%_ASM_CX
22620 jae bad_put_user
22621 -2: movw %ax,(%_ASM_CX)
22622 +
22623 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22624 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22625 + cmp %_ASM_BX,%_ASM_CX
22626 + jb 1234f
22627 + xor %ebx,%ebx
22628 +1234:
22629 +#endif
22630 +
22631 +#endif
22632 +
22633 +2: __copyuser_seg movw %ax,(_DEST)
22634 xor %eax,%eax
22635 EXIT
22636 ENDPROC(__put_user_2)
22637
22638 ENTRY(__put_user_4)
22639 ENTER
22640 +
22641 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22642 + GET_THREAD_INFO(%_ASM_BX)
22643 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22644 sub $3,%_ASM_BX
22645 cmp %_ASM_BX,%_ASM_CX
22646 jae bad_put_user
22647 -3: movl %eax,(%_ASM_CX)
22648 +
22649 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22650 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22651 + cmp %_ASM_BX,%_ASM_CX
22652 + jb 1234f
22653 + xor %ebx,%ebx
22654 +1234:
22655 +#endif
22656 +
22657 +#endif
22658 +
22659 +3: __copyuser_seg movl %eax,(_DEST)
22660 xor %eax,%eax
22661 EXIT
22662 ENDPROC(__put_user_4)
22663
22664 ENTRY(__put_user_8)
22665 ENTER
22666 +
22667 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22668 + GET_THREAD_INFO(%_ASM_BX)
22669 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22670 sub $7,%_ASM_BX
22671 cmp %_ASM_BX,%_ASM_CX
22672 jae bad_put_user
22673 -4: mov %_ASM_AX,(%_ASM_CX)
22674 +
22675 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22676 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22677 + cmp %_ASM_BX,%_ASM_CX
22678 + jb 1234f
22679 + xor %ebx,%ebx
22680 +1234:
22681 +#endif
22682 +
22683 +#endif
22684 +
22685 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22686 #ifdef CONFIG_X86_32
22687 -5: movl %edx,4(%_ASM_CX)
22688 +5: __copyuser_seg movl %edx,4(_DEST)
22689 #endif
22690 xor %eax,%eax
22691 EXIT
22692 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22693 index 1cad221..de671ee 100644
22694 --- a/arch/x86/lib/rwlock.S
22695 +++ b/arch/x86/lib/rwlock.S
22696 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22697 FRAME
22698 0: LOCK_PREFIX
22699 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22700 +
22701 +#ifdef CONFIG_PAX_REFCOUNT
22702 + jno 1234f
22703 + LOCK_PREFIX
22704 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22705 + int $4
22706 +1234:
22707 + _ASM_EXTABLE(1234b, 1234b)
22708 +#endif
22709 +
22710 1: rep; nop
22711 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22712 jne 1b
22713 LOCK_PREFIX
22714 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22715 +
22716 +#ifdef CONFIG_PAX_REFCOUNT
22717 + jno 1234f
22718 + LOCK_PREFIX
22719 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22720 + int $4
22721 +1234:
22722 + _ASM_EXTABLE(1234b, 1234b)
22723 +#endif
22724 +
22725 jnz 0b
22726 ENDFRAME
22727 + pax_force_retaddr
22728 ret
22729 CFI_ENDPROC
22730 END(__write_lock_failed)
22731 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22732 FRAME
22733 0: LOCK_PREFIX
22734 READ_LOCK_SIZE(inc) (%__lock_ptr)
22735 +
22736 +#ifdef CONFIG_PAX_REFCOUNT
22737 + jno 1234f
22738 + LOCK_PREFIX
22739 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22740 + int $4
22741 +1234:
22742 + _ASM_EXTABLE(1234b, 1234b)
22743 +#endif
22744 +
22745 1: rep; nop
22746 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22747 js 1b
22748 LOCK_PREFIX
22749 READ_LOCK_SIZE(dec) (%__lock_ptr)
22750 +
22751 +#ifdef CONFIG_PAX_REFCOUNT
22752 + jno 1234f
22753 + LOCK_PREFIX
22754 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22755 + int $4
22756 +1234:
22757 + _ASM_EXTABLE(1234b, 1234b)
22758 +#endif
22759 +
22760 js 0b
22761 ENDFRAME
22762 + pax_force_retaddr
22763 ret
22764 CFI_ENDPROC
22765 END(__read_lock_failed)
22766 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22767 index 5dff5f0..cadebf4 100644
22768 --- a/arch/x86/lib/rwsem.S
22769 +++ b/arch/x86/lib/rwsem.S
22770 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22771 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22772 CFI_RESTORE __ASM_REG(dx)
22773 restore_common_regs
22774 + pax_force_retaddr
22775 ret
22776 CFI_ENDPROC
22777 ENDPROC(call_rwsem_down_read_failed)
22778 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22779 movq %rax,%rdi
22780 call rwsem_down_write_failed
22781 restore_common_regs
22782 + pax_force_retaddr
22783 ret
22784 CFI_ENDPROC
22785 ENDPROC(call_rwsem_down_write_failed)
22786 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22787 movq %rax,%rdi
22788 call rwsem_wake
22789 restore_common_regs
22790 -1: ret
22791 +1: pax_force_retaddr
22792 + ret
22793 CFI_ENDPROC
22794 ENDPROC(call_rwsem_wake)
22795
22796 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22797 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22798 CFI_RESTORE __ASM_REG(dx)
22799 restore_common_regs
22800 + pax_force_retaddr
22801 ret
22802 CFI_ENDPROC
22803 ENDPROC(call_rwsem_downgrade_wake)
22804 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22805 index a63efd6..ccecad8 100644
22806 --- a/arch/x86/lib/thunk_64.S
22807 +++ b/arch/x86/lib/thunk_64.S
22808 @@ -8,6 +8,7 @@
22809 #include <linux/linkage.h>
22810 #include <asm/dwarf2.h>
22811 #include <asm/calling.h>
22812 +#include <asm/alternative-asm.h>
22813
22814 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22815 .macro THUNK name, func, put_ret_addr_in_rdi=0
22816 @@ -41,5 +42,6 @@
22817 SAVE_ARGS
22818 restore:
22819 RESTORE_ARGS
22820 + pax_force_retaddr
22821 ret
22822 CFI_ENDPROC
22823 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22824 index e218d5d..a99a1eb 100644
22825 --- a/arch/x86/lib/usercopy_32.c
22826 +++ b/arch/x86/lib/usercopy_32.c
22827 @@ -43,7 +43,7 @@ do { \
22828 __asm__ __volatile__( \
22829 " testl %1,%1\n" \
22830 " jz 2f\n" \
22831 - "0: lodsb\n" \
22832 + "0: "__copyuser_seg"lodsb\n" \
22833 " stosb\n" \
22834 " testb %%al,%%al\n" \
22835 " jz 1f\n" \
22836 @@ -128,10 +128,12 @@ do { \
22837 int __d0; \
22838 might_fault(); \
22839 __asm__ __volatile__( \
22840 + __COPYUSER_SET_ES \
22841 "0: rep; stosl\n" \
22842 " movl %2,%0\n" \
22843 "1: rep; stosb\n" \
22844 "2:\n" \
22845 + __COPYUSER_RESTORE_ES \
22846 ".section .fixup,\"ax\"\n" \
22847 "3: lea 0(%2,%0,4),%0\n" \
22848 " jmp 2b\n" \
22849 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
22850 might_fault();
22851
22852 __asm__ __volatile__(
22853 + __COPYUSER_SET_ES
22854 " testl %0, %0\n"
22855 " jz 3f\n"
22856 " andl %0,%%ecx\n"
22857 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
22858 " subl %%ecx,%0\n"
22859 " addl %0,%%eax\n"
22860 "1:\n"
22861 + __COPYUSER_RESTORE_ES
22862 ".section .fixup,\"ax\"\n"
22863 "2: xorl %%eax,%%eax\n"
22864 " jmp 1b\n"
22865 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
22866
22867 #ifdef CONFIG_X86_INTEL_USERCOPY
22868 static unsigned long
22869 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22870 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22871 {
22872 int d0, d1;
22873 __asm__ __volatile__(
22874 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22875 " .align 2,0x90\n"
22876 "3: movl 0(%4), %%eax\n"
22877 "4: movl 4(%4), %%edx\n"
22878 - "5: movl %%eax, 0(%3)\n"
22879 - "6: movl %%edx, 4(%3)\n"
22880 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22881 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22882 "7: movl 8(%4), %%eax\n"
22883 "8: movl 12(%4),%%edx\n"
22884 - "9: movl %%eax, 8(%3)\n"
22885 - "10: movl %%edx, 12(%3)\n"
22886 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22887 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22888 "11: movl 16(%4), %%eax\n"
22889 "12: movl 20(%4), %%edx\n"
22890 - "13: movl %%eax, 16(%3)\n"
22891 - "14: movl %%edx, 20(%3)\n"
22892 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22893 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22894 "15: movl 24(%4), %%eax\n"
22895 "16: movl 28(%4), %%edx\n"
22896 - "17: movl %%eax, 24(%3)\n"
22897 - "18: movl %%edx, 28(%3)\n"
22898 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22899 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22900 "19: movl 32(%4), %%eax\n"
22901 "20: movl 36(%4), %%edx\n"
22902 - "21: movl %%eax, 32(%3)\n"
22903 - "22: movl %%edx, 36(%3)\n"
22904 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22905 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22906 "23: movl 40(%4), %%eax\n"
22907 "24: movl 44(%4), %%edx\n"
22908 - "25: movl %%eax, 40(%3)\n"
22909 - "26: movl %%edx, 44(%3)\n"
22910 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22911 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22912 "27: movl 48(%4), %%eax\n"
22913 "28: movl 52(%4), %%edx\n"
22914 - "29: movl %%eax, 48(%3)\n"
22915 - "30: movl %%edx, 52(%3)\n"
22916 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22917 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22918 "31: movl 56(%4), %%eax\n"
22919 "32: movl 60(%4), %%edx\n"
22920 - "33: movl %%eax, 56(%3)\n"
22921 - "34: movl %%edx, 60(%3)\n"
22922 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22923 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22924 " addl $-64, %0\n"
22925 " addl $64, %4\n"
22926 " addl $64, %3\n"
22927 @@ -278,10 +282,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22928 " shrl $2, %0\n"
22929 " andl $3, %%eax\n"
22930 " cld\n"
22931 + __COPYUSER_SET_ES
22932 "99: rep; movsl\n"
22933 "36: movl %%eax, %0\n"
22934 "37: rep; movsb\n"
22935 "100:\n"
22936 + __COPYUSER_RESTORE_ES
22937 ".section .fixup,\"ax\"\n"
22938 "101: lea 0(%%eax,%0,4),%0\n"
22939 " jmp 100b\n"
22940 @@ -334,46 +340,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22941 }
22942
22943 static unsigned long
22944 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22945 +{
22946 + int d0, d1;
22947 + __asm__ __volatile__(
22948 + " .align 2,0x90\n"
22949 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22950 + " cmpl $67, %0\n"
22951 + " jbe 3f\n"
22952 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22953 + " .align 2,0x90\n"
22954 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22955 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22956 + "5: movl %%eax, 0(%3)\n"
22957 + "6: movl %%edx, 4(%3)\n"
22958 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22959 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22960 + "9: movl %%eax, 8(%3)\n"
22961 + "10: movl %%edx, 12(%3)\n"
22962 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22963 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22964 + "13: movl %%eax, 16(%3)\n"
22965 + "14: movl %%edx, 20(%3)\n"
22966 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22967 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22968 + "17: movl %%eax, 24(%3)\n"
22969 + "18: movl %%edx, 28(%3)\n"
22970 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22971 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22972 + "21: movl %%eax, 32(%3)\n"
22973 + "22: movl %%edx, 36(%3)\n"
22974 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22975 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22976 + "25: movl %%eax, 40(%3)\n"
22977 + "26: movl %%edx, 44(%3)\n"
22978 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22979 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22980 + "29: movl %%eax, 48(%3)\n"
22981 + "30: movl %%edx, 52(%3)\n"
22982 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22983 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22984 + "33: movl %%eax, 56(%3)\n"
22985 + "34: movl %%edx, 60(%3)\n"
22986 + " addl $-64, %0\n"
22987 + " addl $64, %4\n"
22988 + " addl $64, %3\n"
22989 + " cmpl $63, %0\n"
22990 + " ja 1b\n"
22991 + "35: movl %0, %%eax\n"
22992 + " shrl $2, %0\n"
22993 + " andl $3, %%eax\n"
22994 + " cld\n"
22995 + "99: rep; "__copyuser_seg" movsl\n"
22996 + "36: movl %%eax, %0\n"
22997 + "37: rep; "__copyuser_seg" movsb\n"
22998 + "100:\n"
22999 + ".section .fixup,\"ax\"\n"
23000 + "101: lea 0(%%eax,%0,4),%0\n"
23001 + " jmp 100b\n"
23002 + ".previous\n"
23003 + ".section __ex_table,\"a\"\n"
23004 + " .align 4\n"
23005 + " .long 1b,100b\n"
23006 + " .long 2b,100b\n"
23007 + " .long 3b,100b\n"
23008 + " .long 4b,100b\n"
23009 + " .long 5b,100b\n"
23010 + " .long 6b,100b\n"
23011 + " .long 7b,100b\n"
23012 + " .long 8b,100b\n"
23013 + " .long 9b,100b\n"
23014 + " .long 10b,100b\n"
23015 + " .long 11b,100b\n"
23016 + " .long 12b,100b\n"
23017 + " .long 13b,100b\n"
23018 + " .long 14b,100b\n"
23019 + " .long 15b,100b\n"
23020 + " .long 16b,100b\n"
23021 + " .long 17b,100b\n"
23022 + " .long 18b,100b\n"
23023 + " .long 19b,100b\n"
23024 + " .long 20b,100b\n"
23025 + " .long 21b,100b\n"
23026 + " .long 22b,100b\n"
23027 + " .long 23b,100b\n"
23028 + " .long 24b,100b\n"
23029 + " .long 25b,100b\n"
23030 + " .long 26b,100b\n"
23031 + " .long 27b,100b\n"
23032 + " .long 28b,100b\n"
23033 + " .long 29b,100b\n"
23034 + " .long 30b,100b\n"
23035 + " .long 31b,100b\n"
23036 + " .long 32b,100b\n"
23037 + " .long 33b,100b\n"
23038 + " .long 34b,100b\n"
23039 + " .long 35b,100b\n"
23040 + " .long 36b,100b\n"
23041 + " .long 37b,100b\n"
23042 + " .long 99b,101b\n"
23043 + ".previous"
23044 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23045 + : "1"(to), "2"(from), "0"(size)
23046 + : "eax", "edx", "memory");
23047 + return size;
23048 +}
23049 +
23050 +static unsigned long
23051 +__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
23052 +static unsigned long
23053 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23054 {
23055 int d0, d1;
23056 __asm__ __volatile__(
23057 " .align 2,0x90\n"
23058 - "0: movl 32(%4), %%eax\n"
23059 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23060 " cmpl $67, %0\n"
23061 " jbe 2f\n"
23062 - "1: movl 64(%4), %%eax\n"
23063 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23064 " .align 2,0x90\n"
23065 - "2: movl 0(%4), %%eax\n"
23066 - "21: movl 4(%4), %%edx\n"
23067 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23068 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23069 " movl %%eax, 0(%3)\n"
23070 " movl %%edx, 4(%3)\n"
23071 - "3: movl 8(%4), %%eax\n"
23072 - "31: movl 12(%4),%%edx\n"
23073 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23074 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23075 " movl %%eax, 8(%3)\n"
23076 " movl %%edx, 12(%3)\n"
23077 - "4: movl 16(%4), %%eax\n"
23078 - "41: movl 20(%4), %%edx\n"
23079 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23080 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23081 " movl %%eax, 16(%3)\n"
23082 " movl %%edx, 20(%3)\n"
23083 - "10: movl 24(%4), %%eax\n"
23084 - "51: movl 28(%4), %%edx\n"
23085 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23086 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23087 " movl %%eax, 24(%3)\n"
23088 " movl %%edx, 28(%3)\n"
23089 - "11: movl 32(%4), %%eax\n"
23090 - "61: movl 36(%4), %%edx\n"
23091 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23092 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23093 " movl %%eax, 32(%3)\n"
23094 " movl %%edx, 36(%3)\n"
23095 - "12: movl 40(%4), %%eax\n"
23096 - "71: movl 44(%4), %%edx\n"
23097 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23098 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23099 " movl %%eax, 40(%3)\n"
23100 " movl %%edx, 44(%3)\n"
23101 - "13: movl 48(%4), %%eax\n"
23102 - "81: movl 52(%4), %%edx\n"
23103 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23104 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23105 " movl %%eax, 48(%3)\n"
23106 " movl %%edx, 52(%3)\n"
23107 - "14: movl 56(%4), %%eax\n"
23108 - "91: movl 60(%4), %%edx\n"
23109 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23110 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23111 " movl %%eax, 56(%3)\n"
23112 " movl %%edx, 60(%3)\n"
23113 " addl $-64, %0\n"
23114 @@ -385,9 +500,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23115 " shrl $2, %0\n"
23116 " andl $3, %%eax\n"
23117 " cld\n"
23118 - "6: rep; movsl\n"
23119 + "6: rep; "__copyuser_seg" movsl\n"
23120 " movl %%eax,%0\n"
23121 - "7: rep; movsb\n"
23122 + "7: rep; "__copyuser_seg" movsb\n"
23123 "8:\n"
23124 ".section .fixup,\"ax\"\n"
23125 "9: lea 0(%%eax,%0,4),%0\n"
23126 @@ -434,47 +549,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23127 */
23128
23129 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23130 + const void __user *from, unsigned long size) __size_overflow(3);
23131 +static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23132 const void __user *from, unsigned long size)
23133 {
23134 int d0, d1;
23135
23136 __asm__ __volatile__(
23137 " .align 2,0x90\n"
23138 - "0: movl 32(%4), %%eax\n"
23139 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23140 " cmpl $67, %0\n"
23141 " jbe 2f\n"
23142 - "1: movl 64(%4), %%eax\n"
23143 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23144 " .align 2,0x90\n"
23145 - "2: movl 0(%4), %%eax\n"
23146 - "21: movl 4(%4), %%edx\n"
23147 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23148 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23149 " movnti %%eax, 0(%3)\n"
23150 " movnti %%edx, 4(%3)\n"
23151 - "3: movl 8(%4), %%eax\n"
23152 - "31: movl 12(%4),%%edx\n"
23153 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23154 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23155 " movnti %%eax, 8(%3)\n"
23156 " movnti %%edx, 12(%3)\n"
23157 - "4: movl 16(%4), %%eax\n"
23158 - "41: movl 20(%4), %%edx\n"
23159 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23160 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23161 " movnti %%eax, 16(%3)\n"
23162 " movnti %%edx, 20(%3)\n"
23163 - "10: movl 24(%4), %%eax\n"
23164 - "51: movl 28(%4), %%edx\n"
23165 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23166 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23167 " movnti %%eax, 24(%3)\n"
23168 " movnti %%edx, 28(%3)\n"
23169 - "11: movl 32(%4), %%eax\n"
23170 - "61: movl 36(%4), %%edx\n"
23171 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23172 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23173 " movnti %%eax, 32(%3)\n"
23174 " movnti %%edx, 36(%3)\n"
23175 - "12: movl 40(%4), %%eax\n"
23176 - "71: movl 44(%4), %%edx\n"
23177 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23178 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23179 " movnti %%eax, 40(%3)\n"
23180 " movnti %%edx, 44(%3)\n"
23181 - "13: movl 48(%4), %%eax\n"
23182 - "81: movl 52(%4), %%edx\n"
23183 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23184 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23185 " movnti %%eax, 48(%3)\n"
23186 " movnti %%edx, 52(%3)\n"
23187 - "14: movl 56(%4), %%eax\n"
23188 - "91: movl 60(%4), %%edx\n"
23189 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23190 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23191 " movnti %%eax, 56(%3)\n"
23192 " movnti %%edx, 60(%3)\n"
23193 " addl $-64, %0\n"
23194 @@ -487,9 +604,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23195 " shrl $2, %0\n"
23196 " andl $3, %%eax\n"
23197 " cld\n"
23198 - "6: rep; movsl\n"
23199 + "6: rep; "__copyuser_seg" movsl\n"
23200 " movl %%eax,%0\n"
23201 - "7: rep; movsb\n"
23202 + "7: rep; "__copyuser_seg" movsb\n"
23203 "8:\n"
23204 ".section .fixup,\"ax\"\n"
23205 "9: lea 0(%%eax,%0,4),%0\n"
23206 @@ -531,47 +648,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23207 }
23208
23209 static unsigned long __copy_user_intel_nocache(void *to,
23210 + const void __user *from, unsigned long size) __size_overflow(3);
23211 +static unsigned long __copy_user_intel_nocache(void *to,
23212 const void __user *from, unsigned long size)
23213 {
23214 int d0, d1;
23215
23216 __asm__ __volatile__(
23217 " .align 2,0x90\n"
23218 - "0: movl 32(%4), %%eax\n"
23219 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23220 " cmpl $67, %0\n"
23221 " jbe 2f\n"
23222 - "1: movl 64(%4), %%eax\n"
23223 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23224 " .align 2,0x90\n"
23225 - "2: movl 0(%4), %%eax\n"
23226 - "21: movl 4(%4), %%edx\n"
23227 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23228 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23229 " movnti %%eax, 0(%3)\n"
23230 " movnti %%edx, 4(%3)\n"
23231 - "3: movl 8(%4), %%eax\n"
23232 - "31: movl 12(%4),%%edx\n"
23233 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23234 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23235 " movnti %%eax, 8(%3)\n"
23236 " movnti %%edx, 12(%3)\n"
23237 - "4: movl 16(%4), %%eax\n"
23238 - "41: movl 20(%4), %%edx\n"
23239 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23240 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23241 " movnti %%eax, 16(%3)\n"
23242 " movnti %%edx, 20(%3)\n"
23243 - "10: movl 24(%4), %%eax\n"
23244 - "51: movl 28(%4), %%edx\n"
23245 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23246 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23247 " movnti %%eax, 24(%3)\n"
23248 " movnti %%edx, 28(%3)\n"
23249 - "11: movl 32(%4), %%eax\n"
23250 - "61: movl 36(%4), %%edx\n"
23251 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23252 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23253 " movnti %%eax, 32(%3)\n"
23254 " movnti %%edx, 36(%3)\n"
23255 - "12: movl 40(%4), %%eax\n"
23256 - "71: movl 44(%4), %%edx\n"
23257 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23258 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23259 " movnti %%eax, 40(%3)\n"
23260 " movnti %%edx, 44(%3)\n"
23261 - "13: movl 48(%4), %%eax\n"
23262 - "81: movl 52(%4), %%edx\n"
23263 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23264 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23265 " movnti %%eax, 48(%3)\n"
23266 " movnti %%edx, 52(%3)\n"
23267 - "14: movl 56(%4), %%eax\n"
23268 - "91: movl 60(%4), %%edx\n"
23269 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23270 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23271 " movnti %%eax, 56(%3)\n"
23272 " movnti %%edx, 60(%3)\n"
23273 " addl $-64, %0\n"
23274 @@ -584,9 +703,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23275 " shrl $2, %0\n"
23276 " andl $3, %%eax\n"
23277 " cld\n"
23278 - "6: rep; movsl\n"
23279 + "6: rep; "__copyuser_seg" movsl\n"
23280 " movl %%eax,%0\n"
23281 - "7: rep; movsb\n"
23282 + "7: rep; "__copyuser_seg" movsb\n"
23283 "8:\n"
23284 ".section .fixup,\"ax\"\n"
23285 "9: lea 0(%%eax,%0,4),%0\n"
23286 @@ -629,32 +748,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23287 */
23288 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23289 unsigned long size);
23290 -unsigned long __copy_user_intel(void __user *to, const void *from,
23291 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23292 + unsigned long size);
23293 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23294 unsigned long size);
23295 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23296 const void __user *from, unsigned long size);
23297 #endif /* CONFIG_X86_INTEL_USERCOPY */
23298
23299 /* Generic arbitrary sized copy. */
23300 -#define __copy_user(to, from, size) \
23301 +#define __copy_user(to, from, size, prefix, set, restore) \
23302 do { \
23303 int __d0, __d1, __d2; \
23304 __asm__ __volatile__( \
23305 + set \
23306 " cmp $7,%0\n" \
23307 " jbe 1f\n" \
23308 " movl %1,%0\n" \
23309 " negl %0\n" \
23310 " andl $7,%0\n" \
23311 " subl %0,%3\n" \
23312 - "4: rep; movsb\n" \
23313 + "4: rep; "prefix"movsb\n" \
23314 " movl %3,%0\n" \
23315 " shrl $2,%0\n" \
23316 " andl $3,%3\n" \
23317 " .align 2,0x90\n" \
23318 - "0: rep; movsl\n" \
23319 + "0: rep; "prefix"movsl\n" \
23320 " movl %3,%0\n" \
23321 - "1: rep; movsb\n" \
23322 + "1: rep; "prefix"movsb\n" \
23323 "2:\n" \
23324 + restore \
23325 ".section .fixup,\"ax\"\n" \
23326 "5: addl %3,%0\n" \
23327 " jmp 2b\n" \
23328 @@ -682,14 +805,14 @@ do { \
23329 " negl %0\n" \
23330 " andl $7,%0\n" \
23331 " subl %0,%3\n" \
23332 - "4: rep; movsb\n" \
23333 + "4: rep; "__copyuser_seg"movsb\n" \
23334 " movl %3,%0\n" \
23335 " shrl $2,%0\n" \
23336 " andl $3,%3\n" \
23337 " .align 2,0x90\n" \
23338 - "0: rep; movsl\n" \
23339 + "0: rep; "__copyuser_seg"movsl\n" \
23340 " movl %3,%0\n" \
23341 - "1: rep; movsb\n" \
23342 + "1: rep; "__copyuser_seg"movsb\n" \
23343 "2:\n" \
23344 ".section .fixup,\"ax\"\n" \
23345 "5: addl %3,%0\n" \
23346 @@ -775,9 +898,9 @@ survive:
23347 }
23348 #endif
23349 if (movsl_is_ok(to, from, n))
23350 - __copy_user(to, from, n);
23351 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23352 else
23353 - n = __copy_user_intel(to, from, n);
23354 + n = __generic_copy_to_user_intel(to, from, n);
23355 return n;
23356 }
23357 EXPORT_SYMBOL(__copy_to_user_ll);
23358 @@ -797,10 +920,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23359 unsigned long n)
23360 {
23361 if (movsl_is_ok(to, from, n))
23362 - __copy_user(to, from, n);
23363 + __copy_user(to, from, n, __copyuser_seg, "", "");
23364 else
23365 - n = __copy_user_intel((void __user *)to,
23366 - (const void *)from, n);
23367 + n = __generic_copy_from_user_intel(to, from, n);
23368 return n;
23369 }
23370 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23371 @@ -827,65 +949,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23372 if (n > 64 && cpu_has_xmm2)
23373 n = __copy_user_intel_nocache(to, from, n);
23374 else
23375 - __copy_user(to, from, n);
23376 + __copy_user(to, from, n, __copyuser_seg, "", "");
23377 #else
23378 - __copy_user(to, from, n);
23379 + __copy_user(to, from, n, __copyuser_seg, "", "");
23380 #endif
23381 return n;
23382 }
23383 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23384
23385 -/**
23386 - * copy_to_user: - Copy a block of data into user space.
23387 - * @to: Destination address, in user space.
23388 - * @from: Source address, in kernel space.
23389 - * @n: Number of bytes to copy.
23390 - *
23391 - * Context: User context only. This function may sleep.
23392 - *
23393 - * Copy data from kernel space to user space.
23394 - *
23395 - * Returns number of bytes that could not be copied.
23396 - * On success, this will be zero.
23397 - */
23398 -unsigned long
23399 -copy_to_user(void __user *to, const void *from, unsigned long n)
23400 -{
23401 - if (access_ok(VERIFY_WRITE, to, n))
23402 - n = __copy_to_user(to, from, n);
23403 - return n;
23404 -}
23405 -EXPORT_SYMBOL(copy_to_user);
23406 -
23407 -/**
23408 - * copy_from_user: - Copy a block of data from user space.
23409 - * @to: Destination address, in kernel space.
23410 - * @from: Source address, in user space.
23411 - * @n: Number of bytes to copy.
23412 - *
23413 - * Context: User context only. This function may sleep.
23414 - *
23415 - * Copy data from user space to kernel space.
23416 - *
23417 - * Returns number of bytes that could not be copied.
23418 - * On success, this will be zero.
23419 - *
23420 - * If some data could not be copied, this function will pad the copied
23421 - * data to the requested size using zero bytes.
23422 - */
23423 -unsigned long
23424 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23425 -{
23426 - if (access_ok(VERIFY_READ, from, n))
23427 - n = __copy_from_user(to, from, n);
23428 - else
23429 - memset(to, 0, n);
23430 - return n;
23431 -}
23432 -EXPORT_SYMBOL(_copy_from_user);
23433 -
23434 void copy_from_user_overflow(void)
23435 {
23436 WARN(1, "Buffer overflow detected!\n");
23437 }
23438 EXPORT_SYMBOL(copy_from_user_overflow);
23439 +
23440 +void copy_to_user_overflow(void)
23441 +{
23442 + WARN(1, "Buffer overflow detected!\n");
23443 +}
23444 +EXPORT_SYMBOL(copy_to_user_overflow);
23445 +
23446 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23447 +void __set_fs(mm_segment_t x)
23448 +{
23449 + switch (x.seg) {
23450 + case 0:
23451 + loadsegment(gs, 0);
23452 + break;
23453 + case TASK_SIZE_MAX:
23454 + loadsegment(gs, __USER_DS);
23455 + break;
23456 + case -1UL:
23457 + loadsegment(gs, __KERNEL_DS);
23458 + break;
23459 + default:
23460 + BUG();
23461 + }
23462 + return;
23463 +}
23464 +EXPORT_SYMBOL(__set_fs);
23465 +
23466 +void set_fs(mm_segment_t x)
23467 +{
23468 + current_thread_info()->addr_limit = x;
23469 + __set_fs(x);
23470 +}
23471 +EXPORT_SYMBOL(set_fs);
23472 +#endif
23473 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23474 index b7c2849..8633ad8 100644
23475 --- a/arch/x86/lib/usercopy_64.c
23476 +++ b/arch/x86/lib/usercopy_64.c
23477 @@ -42,6 +42,12 @@ long
23478 __strncpy_from_user(char *dst, const char __user *src, long count)
23479 {
23480 long res;
23481 +
23482 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23483 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
23484 + src += PAX_USER_SHADOW_BASE;
23485 +#endif
23486 +
23487 __do_strncpy_from_user(dst, src, count, res);
23488 return res;
23489 }
23490 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23491 {
23492 long __d0;
23493 might_fault();
23494 +
23495 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23496 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23497 + addr += PAX_USER_SHADOW_BASE;
23498 +#endif
23499 +
23500 /* no memory constraint because it doesn't change any memory gcc knows
23501 about */
23502 asm volatile(
23503 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
23504 }
23505 EXPORT_SYMBOL(strlen_user);
23506
23507 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23508 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23509 {
23510 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23511 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23512 - }
23513 - return len;
23514 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23515 +
23516 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23517 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23518 + to += PAX_USER_SHADOW_BASE;
23519 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23520 + from += PAX_USER_SHADOW_BASE;
23521 +#endif
23522 +
23523 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23524 + }
23525 + return len;
23526 }
23527 EXPORT_SYMBOL(copy_in_user);
23528
23529 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
23530 * it is not necessary to optimize tail handling.
23531 */
23532 unsigned long
23533 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23534 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23535 {
23536 char c;
23537 unsigned zero_len;
23538 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23539 index 1fb85db..8b3540b 100644
23540 --- a/arch/x86/mm/extable.c
23541 +++ b/arch/x86/mm/extable.c
23542 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23543 const struct exception_table_entry *fixup;
23544
23545 #ifdef CONFIG_PNPBIOS
23546 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23547 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23548 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23549 extern u32 pnp_bios_is_utter_crap;
23550 pnp_bios_is_utter_crap = 1;
23551 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23552 index f0b4caf..d92fd42 100644
23553 --- a/arch/x86/mm/fault.c
23554 +++ b/arch/x86/mm/fault.c
23555 @@ -13,11 +13,18 @@
23556 #include <linux/perf_event.h> /* perf_sw_event */
23557 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23558 #include <linux/prefetch.h> /* prefetchw */
23559 +#include <linux/unistd.h>
23560 +#include <linux/compiler.h>
23561
23562 #include <asm/traps.h> /* dotraplinkage, ... */
23563 #include <asm/pgalloc.h> /* pgd_*(), ... */
23564 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23565 #include <asm/fixmap.h> /* VSYSCALL_START */
23566 +#include <asm/tlbflush.h>
23567 +
23568 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23569 +#include <asm/stacktrace.h>
23570 +#endif
23571
23572 /*
23573 * Page fault error code bits:
23574 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23575 int ret = 0;
23576
23577 /* kprobe_running() needs smp_processor_id() */
23578 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23579 + if (kprobes_built_in() && !user_mode(regs)) {
23580 preempt_disable();
23581 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23582 ret = 1;
23583 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23584 return !instr_lo || (instr_lo>>1) == 1;
23585 case 0x00:
23586 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23587 - if (probe_kernel_address(instr, opcode))
23588 + if (user_mode(regs)) {
23589 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23590 + return 0;
23591 + } else if (probe_kernel_address(instr, opcode))
23592 return 0;
23593
23594 *prefetch = (instr_lo == 0xF) &&
23595 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23596 while (instr < max_instr) {
23597 unsigned char opcode;
23598
23599 - if (probe_kernel_address(instr, opcode))
23600 + if (user_mode(regs)) {
23601 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23602 + break;
23603 + } else if (probe_kernel_address(instr, opcode))
23604 break;
23605
23606 instr++;
23607 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23608 force_sig_info(si_signo, &info, tsk);
23609 }
23610
23611 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23612 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23613 +#endif
23614 +
23615 +#ifdef CONFIG_PAX_EMUTRAMP
23616 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23617 +#endif
23618 +
23619 +#ifdef CONFIG_PAX_PAGEEXEC
23620 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23621 +{
23622 + pgd_t *pgd;
23623 + pud_t *pud;
23624 + pmd_t *pmd;
23625 +
23626 + pgd = pgd_offset(mm, address);
23627 + if (!pgd_present(*pgd))
23628 + return NULL;
23629 + pud = pud_offset(pgd, address);
23630 + if (!pud_present(*pud))
23631 + return NULL;
23632 + pmd = pmd_offset(pud, address);
23633 + if (!pmd_present(*pmd))
23634 + return NULL;
23635 + return pmd;
23636 +}
23637 +#endif
23638 +
23639 DEFINE_SPINLOCK(pgd_lock);
23640 LIST_HEAD(pgd_list);
23641
23642 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23643 for (address = VMALLOC_START & PMD_MASK;
23644 address >= TASK_SIZE && address < FIXADDR_TOP;
23645 address += PMD_SIZE) {
23646 +
23647 +#ifdef CONFIG_PAX_PER_CPU_PGD
23648 + unsigned long cpu;
23649 +#else
23650 struct page *page;
23651 +#endif
23652
23653 spin_lock(&pgd_lock);
23654 +
23655 +#ifdef CONFIG_PAX_PER_CPU_PGD
23656 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23657 + pgd_t *pgd = get_cpu_pgd(cpu);
23658 + pmd_t *ret;
23659 +#else
23660 list_for_each_entry(page, &pgd_list, lru) {
23661 + pgd_t *pgd = page_address(page);
23662 spinlock_t *pgt_lock;
23663 pmd_t *ret;
23664
23665 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23666 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23667
23668 spin_lock(pgt_lock);
23669 - ret = vmalloc_sync_one(page_address(page), address);
23670 +#endif
23671 +
23672 + ret = vmalloc_sync_one(pgd, address);
23673 +
23674 +#ifndef CONFIG_PAX_PER_CPU_PGD
23675 spin_unlock(pgt_lock);
23676 +#endif
23677
23678 if (!ret)
23679 break;
23680 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23681 * an interrupt in the middle of a task switch..
23682 */
23683 pgd_paddr = read_cr3();
23684 +
23685 +#ifdef CONFIG_PAX_PER_CPU_PGD
23686 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23687 +#endif
23688 +
23689 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23690 if (!pmd_k)
23691 return -1;
23692 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23693 * happen within a race in page table update. In the later
23694 * case just flush:
23695 */
23696 +
23697 +#ifdef CONFIG_PAX_PER_CPU_PGD
23698 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23699 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23700 +#else
23701 pgd = pgd_offset(current->active_mm, address);
23702 +#endif
23703 +
23704 pgd_ref = pgd_offset_k(address);
23705 if (pgd_none(*pgd_ref))
23706 return -1;
23707 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23708 static int is_errata100(struct pt_regs *regs, unsigned long address)
23709 {
23710 #ifdef CONFIG_X86_64
23711 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23712 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23713 return 1;
23714 #endif
23715 return 0;
23716 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23717 }
23718
23719 static const char nx_warning[] = KERN_CRIT
23720 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23721 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23722
23723 static void
23724 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23725 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23726 if (!oops_may_print())
23727 return;
23728
23729 - if (error_code & PF_INSTR) {
23730 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23731 unsigned int level;
23732
23733 pte_t *pte = lookup_address(address, &level);
23734
23735 if (pte && pte_present(*pte) && !pte_exec(*pte))
23736 - printk(nx_warning, current_uid());
23737 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23738 }
23739
23740 +#ifdef CONFIG_PAX_KERNEXEC
23741 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23742 + if (current->signal->curr_ip)
23743 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23744 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23745 + else
23746 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23747 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23748 + }
23749 +#endif
23750 +
23751 printk(KERN_ALERT "BUG: unable to handle kernel ");
23752 if (address < PAGE_SIZE)
23753 printk(KERN_CONT "NULL pointer dereference");
23754 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23755 }
23756 #endif
23757
23758 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23759 + if (pax_is_fetch_fault(regs, error_code, address)) {
23760 +
23761 +#ifdef CONFIG_PAX_EMUTRAMP
23762 + switch (pax_handle_fetch_fault(regs)) {
23763 + case 2:
23764 + return;
23765 + }
23766 +#endif
23767 +
23768 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23769 + do_group_exit(SIGKILL);
23770 + }
23771 +#endif
23772 +
23773 if (unlikely(show_unhandled_signals))
23774 show_signal_msg(regs, error_code, address, tsk);
23775
23776 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23777 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23778 printk(KERN_ERR
23779 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23780 - tsk->comm, tsk->pid, address);
23781 + tsk->comm, task_pid_nr(tsk), address);
23782 code = BUS_MCEERR_AR;
23783 }
23784 #endif
23785 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23786 return 1;
23787 }
23788
23789 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23790 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23791 +{
23792 + pte_t *pte;
23793 + pmd_t *pmd;
23794 + spinlock_t *ptl;
23795 + unsigned char pte_mask;
23796 +
23797 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23798 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23799 + return 0;
23800 +
23801 + /* PaX: it's our fault, let's handle it if we can */
23802 +
23803 + /* PaX: take a look at read faults before acquiring any locks */
23804 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23805 + /* instruction fetch attempt from a protected page in user mode */
23806 + up_read(&mm->mmap_sem);
23807 +
23808 +#ifdef CONFIG_PAX_EMUTRAMP
23809 + switch (pax_handle_fetch_fault(regs)) {
23810 + case 2:
23811 + return 1;
23812 + }
23813 +#endif
23814 +
23815 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23816 + do_group_exit(SIGKILL);
23817 + }
23818 +
23819 + pmd = pax_get_pmd(mm, address);
23820 + if (unlikely(!pmd))
23821 + return 0;
23822 +
23823 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23824 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23825 + pte_unmap_unlock(pte, ptl);
23826 + return 0;
23827 + }
23828 +
23829 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23830 + /* write attempt to a protected page in user mode */
23831 + pte_unmap_unlock(pte, ptl);
23832 + return 0;
23833 + }
23834 +
23835 +#ifdef CONFIG_SMP
23836 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23837 +#else
23838 + if (likely(address > get_limit(regs->cs)))
23839 +#endif
23840 + {
23841 + set_pte(pte, pte_mkread(*pte));
23842 + __flush_tlb_one(address);
23843 + pte_unmap_unlock(pte, ptl);
23844 + up_read(&mm->mmap_sem);
23845 + return 1;
23846 + }
23847 +
23848 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23849 +
23850 + /*
23851 + * PaX: fill DTLB with user rights and retry
23852 + */
23853 + __asm__ __volatile__ (
23854 + "orb %2,(%1)\n"
23855 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23856 +/*
23857 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23858 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23859 + * page fault when examined during a TLB load attempt. this is true not only
23860 + * for PTEs holding a non-present entry but also present entries that will
23861 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23862 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23863 + * for our target pages since their PTEs are simply not in the TLBs at all.
23864 +
23865 + * the best thing in omitting it is that we gain around 15-20% speed in the
23866 + * fast path of the page fault handler and can get rid of tracing since we
23867 + * can no longer flush unintended entries.
23868 + */
23869 + "invlpg (%0)\n"
23870 +#endif
23871 + __copyuser_seg"testb $0,(%0)\n"
23872 + "xorb %3,(%1)\n"
23873 + :
23874 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23875 + : "memory", "cc");
23876 + pte_unmap_unlock(pte, ptl);
23877 + up_read(&mm->mmap_sem);
23878 + return 1;
23879 +}
23880 +#endif
23881 +
23882 /*
23883 * Handle a spurious fault caused by a stale TLB entry.
23884 *
23885 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23886 static inline int
23887 access_error(unsigned long error_code, struct vm_area_struct *vma)
23888 {
23889 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23890 + return 1;
23891 +
23892 if (error_code & PF_WRITE) {
23893 /* write, present and write, not present: */
23894 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23895 @@ -1005,18 +1197,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23896 {
23897 struct vm_area_struct *vma;
23898 struct task_struct *tsk;
23899 - unsigned long address;
23900 struct mm_struct *mm;
23901 int fault;
23902 int write = error_code & PF_WRITE;
23903 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23904 (write ? FAULT_FLAG_WRITE : 0);
23905
23906 - tsk = current;
23907 - mm = tsk->mm;
23908 -
23909 /* Get the faulting address: */
23910 - address = read_cr2();
23911 + unsigned long address = read_cr2();
23912 +
23913 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23914 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23915 + if (!search_exception_tables(regs->ip)) {
23916 + bad_area_nosemaphore(regs, error_code, address);
23917 + return;
23918 + }
23919 + if (address < PAX_USER_SHADOW_BASE) {
23920 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23921 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23922 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23923 + } else
23924 + address -= PAX_USER_SHADOW_BASE;
23925 + }
23926 +#endif
23927 +
23928 + tsk = current;
23929 + mm = tsk->mm;
23930
23931 /*
23932 * Detect and handle instructions that would cause a page fault for
23933 @@ -1077,7 +1283,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23934 * User-mode registers count as a user access even for any
23935 * potential system fault or CPU buglet:
23936 */
23937 - if (user_mode_vm(regs)) {
23938 + if (user_mode(regs)) {
23939 local_irq_enable();
23940 error_code |= PF_USER;
23941 } else {
23942 @@ -1132,6 +1338,11 @@ retry:
23943 might_sleep();
23944 }
23945
23946 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23947 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23948 + return;
23949 +#endif
23950 +
23951 vma = find_vma(mm, address);
23952 if (unlikely(!vma)) {
23953 bad_area(regs, error_code, address);
23954 @@ -1143,18 +1354,24 @@ retry:
23955 bad_area(regs, error_code, address);
23956 return;
23957 }
23958 - if (error_code & PF_USER) {
23959 - /*
23960 - * Accessing the stack below %sp is always a bug.
23961 - * The large cushion allows instructions like enter
23962 - * and pusha to work. ("enter $65535, $31" pushes
23963 - * 32 pointers and then decrements %sp by 65535.)
23964 - */
23965 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23966 - bad_area(regs, error_code, address);
23967 - return;
23968 - }
23969 + /*
23970 + * Accessing the stack below %sp is always a bug.
23971 + * The large cushion allows instructions like enter
23972 + * and pusha to work. ("enter $65535, $31" pushes
23973 + * 32 pointers and then decrements %sp by 65535.)
23974 + */
23975 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23976 + bad_area(regs, error_code, address);
23977 + return;
23978 }
23979 +
23980 +#ifdef CONFIG_PAX_SEGMEXEC
23981 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23982 + bad_area(regs, error_code, address);
23983 + return;
23984 + }
23985 +#endif
23986 +
23987 if (unlikely(expand_stack(vma, address))) {
23988 bad_area(regs, error_code, address);
23989 return;
23990 @@ -1209,3 +1426,292 @@ good_area:
23991
23992 up_read(&mm->mmap_sem);
23993 }
23994 +
23995 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23996 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23997 +{
23998 + struct mm_struct *mm = current->mm;
23999 + unsigned long ip = regs->ip;
24000 +
24001 + if (v8086_mode(regs))
24002 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24003 +
24004 +#ifdef CONFIG_PAX_PAGEEXEC
24005 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24006 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24007 + return true;
24008 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24009 + return true;
24010 + return false;
24011 + }
24012 +#endif
24013 +
24014 +#ifdef CONFIG_PAX_SEGMEXEC
24015 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24016 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24017 + return true;
24018 + return false;
24019 + }
24020 +#endif
24021 +
24022 + return false;
24023 +}
24024 +#endif
24025 +
24026 +#ifdef CONFIG_PAX_EMUTRAMP
24027 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24028 +{
24029 + int err;
24030 +
24031 + do { /* PaX: libffi trampoline emulation */
24032 + unsigned char mov, jmp;
24033 + unsigned int addr1, addr2;
24034 +
24035 +#ifdef CONFIG_X86_64
24036 + if ((regs->ip + 9) >> 32)
24037 + break;
24038 +#endif
24039 +
24040 + err = get_user(mov, (unsigned char __user *)regs->ip);
24041 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24042 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24043 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24044 +
24045 + if (err)
24046 + break;
24047 +
24048 + if (mov == 0xB8 && jmp == 0xE9) {
24049 + regs->ax = addr1;
24050 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24051 + return 2;
24052 + }
24053 + } while (0);
24054 +
24055 + do { /* PaX: gcc trampoline emulation #1 */
24056 + unsigned char mov1, mov2;
24057 + unsigned short jmp;
24058 + unsigned int addr1, addr2;
24059 +
24060 +#ifdef CONFIG_X86_64
24061 + if ((regs->ip + 11) >> 32)
24062 + break;
24063 +#endif
24064 +
24065 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24066 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24067 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24068 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24069 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24070 +
24071 + if (err)
24072 + break;
24073 +
24074 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24075 + regs->cx = addr1;
24076 + regs->ax = addr2;
24077 + regs->ip = addr2;
24078 + return 2;
24079 + }
24080 + } while (0);
24081 +
24082 + do { /* PaX: gcc trampoline emulation #2 */
24083 + unsigned char mov, jmp;
24084 + unsigned int addr1, addr2;
24085 +
24086 +#ifdef CONFIG_X86_64
24087 + if ((regs->ip + 9) >> 32)
24088 + break;
24089 +#endif
24090 +
24091 + err = get_user(mov, (unsigned char __user *)regs->ip);
24092 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24093 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24094 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24095 +
24096 + if (err)
24097 + break;
24098 +
24099 + if (mov == 0xB9 && jmp == 0xE9) {
24100 + regs->cx = addr1;
24101 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24102 + return 2;
24103 + }
24104 + } while (0);
24105 +
24106 + return 1; /* PaX in action */
24107 +}
24108 +
24109 +#ifdef CONFIG_X86_64
24110 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24111 +{
24112 + int err;
24113 +
24114 + do { /* PaX: libffi trampoline emulation */
24115 + unsigned short mov1, mov2, jmp1;
24116 + unsigned char stcclc, jmp2;
24117 + unsigned long addr1, addr2;
24118 +
24119 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24120 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24121 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24122 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24123 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24124 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24125 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24126 +
24127 + if (err)
24128 + break;
24129 +
24130 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24131 + regs->r11 = addr1;
24132 + regs->r10 = addr2;
24133 + if (stcclc == 0xF8)
24134 + regs->flags &= ~X86_EFLAGS_CF;
24135 + else
24136 + regs->flags |= X86_EFLAGS_CF;
24137 + regs->ip = addr1;
24138 + return 2;
24139 + }
24140 + } while (0);
24141 +
24142 + do { /* PaX: gcc trampoline emulation #1 */
24143 + unsigned short mov1, mov2, jmp1;
24144 + unsigned char jmp2;
24145 + unsigned int addr1;
24146 + unsigned long addr2;
24147 +
24148 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24149 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24150 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24151 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24152 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24153 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24154 +
24155 + if (err)
24156 + break;
24157 +
24158 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24159 + regs->r11 = addr1;
24160 + regs->r10 = addr2;
24161 + regs->ip = addr1;
24162 + return 2;
24163 + }
24164 + } while (0);
24165 +
24166 + do { /* PaX: gcc trampoline emulation #2 */
24167 + unsigned short mov1, mov2, jmp1;
24168 + unsigned char jmp2;
24169 + unsigned long addr1, addr2;
24170 +
24171 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24172 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24173 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24174 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24175 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24176 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24177 +
24178 + if (err)
24179 + break;
24180 +
24181 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24182 + regs->r11 = addr1;
24183 + regs->r10 = addr2;
24184 + regs->ip = addr1;
24185 + return 2;
24186 + }
24187 + } while (0);
24188 +
24189 + return 1; /* PaX in action */
24190 +}
24191 +#endif
24192 +
24193 +/*
24194 + * PaX: decide what to do with offenders (regs->ip = fault address)
24195 + *
24196 + * returns 1 when task should be killed
24197 + * 2 when gcc trampoline was detected
24198 + */
24199 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24200 +{
24201 + if (v8086_mode(regs))
24202 + return 1;
24203 +
24204 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24205 + return 1;
24206 +
24207 +#ifdef CONFIG_X86_32
24208 + return pax_handle_fetch_fault_32(regs);
24209 +#else
24210 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24211 + return pax_handle_fetch_fault_32(regs);
24212 + else
24213 + return pax_handle_fetch_fault_64(regs);
24214 +#endif
24215 +}
24216 +#endif
24217 +
24218 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24219 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24220 +{
24221 + long i;
24222 +
24223 + printk(KERN_ERR "PAX: bytes at PC: ");
24224 + for (i = 0; i < 20; i++) {
24225 + unsigned char c;
24226 + if (get_user(c, (unsigned char __force_user *)pc+i))
24227 + printk(KERN_CONT "?? ");
24228 + else
24229 + printk(KERN_CONT "%02x ", c);
24230 + }
24231 + printk("\n");
24232 +
24233 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24234 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24235 + unsigned long c;
24236 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24237 +#ifdef CONFIG_X86_32
24238 + printk(KERN_CONT "???????? ");
24239 +#else
24240 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24241 + printk(KERN_CONT "???????? ???????? ");
24242 + else
24243 + printk(KERN_CONT "???????????????? ");
24244 +#endif
24245 + } else {
24246 +#ifdef CONFIG_X86_64
24247 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24248 + printk(KERN_CONT "%08x ", (unsigned int)c);
24249 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24250 + } else
24251 +#endif
24252 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24253 + }
24254 + }
24255 + printk("\n");
24256 +}
24257 +#endif
24258 +
24259 +/**
24260 + * probe_kernel_write(): safely attempt to write to a location
24261 + * @dst: address to write to
24262 + * @src: pointer to the data that shall be written
24263 + * @size: size of the data chunk
24264 + *
24265 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24266 + * happens, handle that and return -EFAULT.
24267 + */
24268 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24269 +{
24270 + long ret;
24271 + mm_segment_t old_fs = get_fs();
24272 +
24273 + set_fs(KERNEL_DS);
24274 + pagefault_disable();
24275 + pax_open_kernel();
24276 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24277 + pax_close_kernel();
24278 + pagefault_enable();
24279 + set_fs(old_fs);
24280 +
24281 + return ret ? -EFAULT : 0;
24282 +}
24283 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24284 index dd74e46..7d26398 100644
24285 --- a/arch/x86/mm/gup.c
24286 +++ b/arch/x86/mm/gup.c
24287 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24288 addr = start;
24289 len = (unsigned long) nr_pages << PAGE_SHIFT;
24290 end = start + len;
24291 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24292 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24293 (void __user *)start, len)))
24294 return 0;
24295
24296 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24297 index f4f29b1..5cac4fb 100644
24298 --- a/arch/x86/mm/highmem_32.c
24299 +++ b/arch/x86/mm/highmem_32.c
24300 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24301 idx = type + KM_TYPE_NR*smp_processor_id();
24302 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24303 BUG_ON(!pte_none(*(kmap_pte-idx)));
24304 +
24305 + pax_open_kernel();
24306 set_pte(kmap_pte-idx, mk_pte(page, prot));
24307 + pax_close_kernel();
24308 +
24309 arch_flush_lazy_mmu_mode();
24310
24311 return (void *)vaddr;
24312 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24313 index 8ecbb4b..a269cab 100644
24314 --- a/arch/x86/mm/hugetlbpage.c
24315 +++ b/arch/x86/mm/hugetlbpage.c
24316 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24317 struct hstate *h = hstate_file(file);
24318 struct mm_struct *mm = current->mm;
24319 struct vm_area_struct *vma;
24320 - unsigned long start_addr;
24321 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24322 +
24323 +#ifdef CONFIG_PAX_SEGMEXEC
24324 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24325 + pax_task_size = SEGMEXEC_TASK_SIZE;
24326 +#endif
24327 +
24328 + pax_task_size -= PAGE_SIZE;
24329
24330 if (len > mm->cached_hole_size) {
24331 - start_addr = mm->free_area_cache;
24332 + start_addr = mm->free_area_cache;
24333 } else {
24334 - start_addr = TASK_UNMAPPED_BASE;
24335 - mm->cached_hole_size = 0;
24336 + start_addr = mm->mmap_base;
24337 + mm->cached_hole_size = 0;
24338 }
24339
24340 full_search:
24341 @@ -280,26 +287,27 @@ full_search:
24342
24343 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24344 /* At this point: (!vma || addr < vma->vm_end). */
24345 - if (TASK_SIZE - len < addr) {
24346 + if (pax_task_size - len < addr) {
24347 /*
24348 * Start a new search - just in case we missed
24349 * some holes.
24350 */
24351 - if (start_addr != TASK_UNMAPPED_BASE) {
24352 - start_addr = TASK_UNMAPPED_BASE;
24353 + if (start_addr != mm->mmap_base) {
24354 + start_addr = mm->mmap_base;
24355 mm->cached_hole_size = 0;
24356 goto full_search;
24357 }
24358 return -ENOMEM;
24359 }
24360 - if (!vma || addr + len <= vma->vm_start) {
24361 - mm->free_area_cache = addr + len;
24362 - return addr;
24363 - }
24364 + if (check_heap_stack_gap(vma, addr, len))
24365 + break;
24366 if (addr + mm->cached_hole_size < vma->vm_start)
24367 mm->cached_hole_size = vma->vm_start - addr;
24368 addr = ALIGN(vma->vm_end, huge_page_size(h));
24369 }
24370 +
24371 + mm->free_area_cache = addr + len;
24372 + return addr;
24373 }
24374
24375 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24376 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24377 {
24378 struct hstate *h = hstate_file(file);
24379 struct mm_struct *mm = current->mm;
24380 - struct vm_area_struct *vma, *prev_vma;
24381 - unsigned long base = mm->mmap_base, addr = addr0;
24382 + struct vm_area_struct *vma;
24383 + unsigned long base = mm->mmap_base, addr;
24384 unsigned long largest_hole = mm->cached_hole_size;
24385 - int first_time = 1;
24386
24387 /* don't allow allocations above current base */
24388 if (mm->free_area_cache > base)
24389 @@ -321,14 +328,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24390 largest_hole = 0;
24391 mm->free_area_cache = base;
24392 }
24393 -try_again:
24394 +
24395 /* make sure it can fit in the remaining address space */
24396 if (mm->free_area_cache < len)
24397 goto fail;
24398
24399 /* either no address requested or can't fit in requested address hole */
24400 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24401 + addr = (mm->free_area_cache - len);
24402 do {
24403 + addr &= huge_page_mask(h);
24404 /*
24405 * Lookup failure means no vma is above this address,
24406 * i.e. return with success:
24407 @@ -341,46 +349,47 @@ try_again:
24408 * new region fits between prev_vma->vm_end and
24409 * vma->vm_start, use it:
24410 */
24411 - prev_vma = vma->vm_prev;
24412 - if (addr + len <= vma->vm_start &&
24413 - (!prev_vma || (addr >= prev_vma->vm_end))) {
24414 + if (check_heap_stack_gap(vma, addr, len)) {
24415 /* remember the address as a hint for next time */
24416 - mm->cached_hole_size = largest_hole;
24417 - return (mm->free_area_cache = addr);
24418 - } else {
24419 - /* pull free_area_cache down to the first hole */
24420 - if (mm->free_area_cache == vma->vm_end) {
24421 - mm->free_area_cache = vma->vm_start;
24422 - mm->cached_hole_size = largest_hole;
24423 - }
24424 + mm->cached_hole_size = largest_hole;
24425 + return (mm->free_area_cache = addr);
24426 + }
24427 + /* pull free_area_cache down to the first hole */
24428 + if (mm->free_area_cache == vma->vm_end) {
24429 + mm->free_area_cache = vma->vm_start;
24430 + mm->cached_hole_size = largest_hole;
24431 }
24432
24433 /* remember the largest hole we saw so far */
24434 if (addr + largest_hole < vma->vm_start)
24435 - largest_hole = vma->vm_start - addr;
24436 + largest_hole = vma->vm_start - addr;
24437
24438 /* try just below the current vma->vm_start */
24439 - addr = (vma->vm_start - len) & huge_page_mask(h);
24440 - } while (len <= vma->vm_start);
24441 + addr = skip_heap_stack_gap(vma, len);
24442 + } while (!IS_ERR_VALUE(addr));
24443
24444 fail:
24445 /*
24446 - * if hint left us with no space for the requested
24447 - * mapping then try again:
24448 - */
24449 - if (first_time) {
24450 - mm->free_area_cache = base;
24451 - largest_hole = 0;
24452 - first_time = 0;
24453 - goto try_again;
24454 - }
24455 - /*
24456 * A failed mmap() very likely causes application failure,
24457 * so fall back to the bottom-up function here. This scenario
24458 * can happen with large stack limits and large mmap()
24459 * allocations.
24460 */
24461 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24462 +
24463 +#ifdef CONFIG_PAX_SEGMEXEC
24464 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24465 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24466 + else
24467 +#endif
24468 +
24469 + mm->mmap_base = TASK_UNMAPPED_BASE;
24470 +
24471 +#ifdef CONFIG_PAX_RANDMMAP
24472 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24473 + mm->mmap_base += mm->delta_mmap;
24474 +#endif
24475 +
24476 + mm->free_area_cache = mm->mmap_base;
24477 mm->cached_hole_size = ~0UL;
24478 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24479 len, pgoff, flags);
24480 @@ -388,6 +397,7 @@ fail:
24481 /*
24482 * Restore the topdown base:
24483 */
24484 + mm->mmap_base = base;
24485 mm->free_area_cache = base;
24486 mm->cached_hole_size = ~0UL;
24487
24488 @@ -401,10 +411,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24489 struct hstate *h = hstate_file(file);
24490 struct mm_struct *mm = current->mm;
24491 struct vm_area_struct *vma;
24492 + unsigned long pax_task_size = TASK_SIZE;
24493
24494 if (len & ~huge_page_mask(h))
24495 return -EINVAL;
24496 - if (len > TASK_SIZE)
24497 +
24498 +#ifdef CONFIG_PAX_SEGMEXEC
24499 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24500 + pax_task_size = SEGMEXEC_TASK_SIZE;
24501 +#endif
24502 +
24503 + pax_task_size -= PAGE_SIZE;
24504 +
24505 + if (len > pax_task_size)
24506 return -ENOMEM;
24507
24508 if (flags & MAP_FIXED) {
24509 @@ -416,8 +435,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24510 if (addr) {
24511 addr = ALIGN(addr, huge_page_size(h));
24512 vma = find_vma(mm, addr);
24513 - if (TASK_SIZE - len >= addr &&
24514 - (!vma || addr + len <= vma->vm_start))
24515 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24516 return addr;
24517 }
24518 if (mm->get_unmapped_area == arch_get_unmapped_area)
24519 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24520 index 6cabf65..77e9c1c 100644
24521 --- a/arch/x86/mm/init.c
24522 +++ b/arch/x86/mm/init.c
24523 @@ -17,6 +17,7 @@
24524 #include <asm/tlb.h>
24525 #include <asm/proto.h>
24526 #include <asm/dma.h> /* for MAX_DMA_PFN */
24527 +#include <asm/desc.h>
24528
24529 unsigned long __initdata pgt_buf_start;
24530 unsigned long __meminitdata pgt_buf_end;
24531 @@ -33,7 +34,7 @@ int direct_gbpages
24532 static void __init find_early_table_space(unsigned long end, int use_pse,
24533 int use_gbpages)
24534 {
24535 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24536 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24537 phys_addr_t base;
24538
24539 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24540 @@ -314,8 +315,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24541 */
24542 int devmem_is_allowed(unsigned long pagenr)
24543 {
24544 +#ifdef CONFIG_GRKERNSEC_KMEM
24545 + /* allow BDA */
24546 + if (!pagenr)
24547 + return 1;
24548 + /* allow EBDA */
24549 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
24550 + return 1;
24551 +#else
24552 + if (!pagenr)
24553 + return 1;
24554 +#ifdef CONFIG_VM86
24555 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24556 + return 1;
24557 +#endif
24558 +#endif
24559 +
24560 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24561 + return 1;
24562 +#ifdef CONFIG_GRKERNSEC_KMEM
24563 + /* throw out everything else below 1MB */
24564 if (pagenr <= 256)
24565 - return 1;
24566 + return 0;
24567 +#endif
24568 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24569 return 0;
24570 if (!page_is_ram(pagenr))
24571 @@ -374,6 +396,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24572
24573 void free_initmem(void)
24574 {
24575 +
24576 +#ifdef CONFIG_PAX_KERNEXEC
24577 +#ifdef CONFIG_X86_32
24578 + /* PaX: limit KERNEL_CS to actual size */
24579 + unsigned long addr, limit;
24580 + struct desc_struct d;
24581 + int cpu;
24582 +
24583 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24584 + limit = (limit - 1UL) >> PAGE_SHIFT;
24585 +
24586 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24587 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24588 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24589 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24590 + }
24591 +
24592 + /* PaX: make KERNEL_CS read-only */
24593 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24594 + if (!paravirt_enabled())
24595 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24596 +/*
24597 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24598 + pgd = pgd_offset_k(addr);
24599 + pud = pud_offset(pgd, addr);
24600 + pmd = pmd_offset(pud, addr);
24601 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24602 + }
24603 +*/
24604 +#ifdef CONFIG_X86_PAE
24605 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24606 +/*
24607 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24608 + pgd = pgd_offset_k(addr);
24609 + pud = pud_offset(pgd, addr);
24610 + pmd = pmd_offset(pud, addr);
24611 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24612 + }
24613 +*/
24614 +#endif
24615 +
24616 +#ifdef CONFIG_MODULES
24617 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24618 +#endif
24619 +
24620 +#else
24621 + pgd_t *pgd;
24622 + pud_t *pud;
24623 + pmd_t *pmd;
24624 + unsigned long addr, end;
24625 +
24626 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24627 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24628 + pgd = pgd_offset_k(addr);
24629 + pud = pud_offset(pgd, addr);
24630 + pmd = pmd_offset(pud, addr);
24631 + if (!pmd_present(*pmd))
24632 + continue;
24633 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24634 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24635 + else
24636 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24637 + }
24638 +
24639 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24640 + end = addr + KERNEL_IMAGE_SIZE;
24641 + for (; addr < end; addr += PMD_SIZE) {
24642 + pgd = pgd_offset_k(addr);
24643 + pud = pud_offset(pgd, addr);
24644 + pmd = pmd_offset(pud, addr);
24645 + if (!pmd_present(*pmd))
24646 + continue;
24647 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24648 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24649 + }
24650 +#endif
24651 +
24652 + flush_tlb_all();
24653 +#endif
24654 +
24655 free_init_pages("unused kernel memory",
24656 (unsigned long)(&__init_begin),
24657 (unsigned long)(&__init_end));
24658 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24659 index 8663f6c..829ae76 100644
24660 --- a/arch/x86/mm/init_32.c
24661 +++ b/arch/x86/mm/init_32.c
24662 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
24663 }
24664
24665 /*
24666 - * Creates a middle page table and puts a pointer to it in the
24667 - * given global directory entry. This only returns the gd entry
24668 - * in non-PAE compilation mode, since the middle layer is folded.
24669 - */
24670 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24671 -{
24672 - pud_t *pud;
24673 - pmd_t *pmd_table;
24674 -
24675 -#ifdef CONFIG_X86_PAE
24676 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24677 - if (after_bootmem)
24678 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24679 - else
24680 - pmd_table = (pmd_t *)alloc_low_page();
24681 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24682 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24683 - pud = pud_offset(pgd, 0);
24684 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24685 -
24686 - return pmd_table;
24687 - }
24688 -#endif
24689 - pud = pud_offset(pgd, 0);
24690 - pmd_table = pmd_offset(pud, 0);
24691 -
24692 - return pmd_table;
24693 -}
24694 -
24695 -/*
24696 * Create a page table and place a pointer to it in a middle page
24697 * directory entry:
24698 */
24699 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24700 page_table = (pte_t *)alloc_low_page();
24701
24702 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24703 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24704 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24705 +#else
24706 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24707 +#endif
24708 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24709 }
24710
24711 return pte_offset_kernel(pmd, 0);
24712 }
24713
24714 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24715 +{
24716 + pud_t *pud;
24717 + pmd_t *pmd_table;
24718 +
24719 + pud = pud_offset(pgd, 0);
24720 + pmd_table = pmd_offset(pud, 0);
24721 +
24722 + return pmd_table;
24723 +}
24724 +
24725 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24726 {
24727 int pgd_idx = pgd_index(vaddr);
24728 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24729 int pgd_idx, pmd_idx;
24730 unsigned long vaddr;
24731 pgd_t *pgd;
24732 + pud_t *pud;
24733 pmd_t *pmd;
24734 pte_t *pte = NULL;
24735
24736 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24737 pgd = pgd_base + pgd_idx;
24738
24739 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24740 - pmd = one_md_table_init(pgd);
24741 - pmd = pmd + pmd_index(vaddr);
24742 + pud = pud_offset(pgd, vaddr);
24743 + pmd = pmd_offset(pud, vaddr);
24744 +
24745 +#ifdef CONFIG_X86_PAE
24746 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24747 +#endif
24748 +
24749 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24750 pmd++, pmd_idx++) {
24751 pte = page_table_kmap_check(one_page_table_init(pmd),
24752 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24753 }
24754 }
24755
24756 -static inline int is_kernel_text(unsigned long addr)
24757 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24758 {
24759 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24760 - return 1;
24761 - return 0;
24762 + if ((start > ktla_ktva((unsigned long)_etext) ||
24763 + end <= ktla_ktva((unsigned long)_stext)) &&
24764 + (start > ktla_ktva((unsigned long)_einittext) ||
24765 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24766 +
24767 +#ifdef CONFIG_ACPI_SLEEP
24768 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24769 +#endif
24770 +
24771 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24772 + return 0;
24773 + return 1;
24774 }
24775
24776 /*
24777 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
24778 unsigned long last_map_addr = end;
24779 unsigned long start_pfn, end_pfn;
24780 pgd_t *pgd_base = swapper_pg_dir;
24781 - int pgd_idx, pmd_idx, pte_ofs;
24782 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24783 unsigned long pfn;
24784 pgd_t *pgd;
24785 + pud_t *pud;
24786 pmd_t *pmd;
24787 pte_t *pte;
24788 unsigned pages_2m, pages_4k;
24789 @@ -281,8 +282,13 @@ repeat:
24790 pfn = start_pfn;
24791 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24792 pgd = pgd_base + pgd_idx;
24793 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24794 - pmd = one_md_table_init(pgd);
24795 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24796 + pud = pud_offset(pgd, 0);
24797 + pmd = pmd_offset(pud, 0);
24798 +
24799 +#ifdef CONFIG_X86_PAE
24800 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24801 +#endif
24802
24803 if (pfn >= end_pfn)
24804 continue;
24805 @@ -294,14 +300,13 @@ repeat:
24806 #endif
24807 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24808 pmd++, pmd_idx++) {
24809 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24810 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24811
24812 /*
24813 * Map with big pages if possible, otherwise
24814 * create normal page tables:
24815 */
24816 if (use_pse) {
24817 - unsigned int addr2;
24818 pgprot_t prot = PAGE_KERNEL_LARGE;
24819 /*
24820 * first pass will use the same initial
24821 @@ -311,11 +316,7 @@ repeat:
24822 __pgprot(PTE_IDENT_ATTR |
24823 _PAGE_PSE);
24824
24825 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24826 - PAGE_OFFSET + PAGE_SIZE-1;
24827 -
24828 - if (is_kernel_text(addr) ||
24829 - is_kernel_text(addr2))
24830 + if (is_kernel_text(address, address + PMD_SIZE))
24831 prot = PAGE_KERNEL_LARGE_EXEC;
24832
24833 pages_2m++;
24834 @@ -332,7 +333,7 @@ repeat:
24835 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24836 pte += pte_ofs;
24837 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24838 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24839 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24840 pgprot_t prot = PAGE_KERNEL;
24841 /*
24842 * first pass will use the same initial
24843 @@ -340,7 +341,7 @@ repeat:
24844 */
24845 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24846
24847 - if (is_kernel_text(addr))
24848 + if (is_kernel_text(address, address + PAGE_SIZE))
24849 prot = PAGE_KERNEL_EXEC;
24850
24851 pages_4k++;
24852 @@ -466,7 +467,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24853
24854 pud = pud_offset(pgd, va);
24855 pmd = pmd_offset(pud, va);
24856 - if (!pmd_present(*pmd))
24857 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24858 break;
24859
24860 pte = pte_offset_kernel(pmd, va);
24861 @@ -518,12 +519,10 @@ void __init early_ioremap_page_table_range_init(void)
24862
24863 static void __init pagetable_init(void)
24864 {
24865 - pgd_t *pgd_base = swapper_pg_dir;
24866 -
24867 - permanent_kmaps_init(pgd_base);
24868 + permanent_kmaps_init(swapper_pg_dir);
24869 }
24870
24871 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24872 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24873 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24874
24875 /* user-defined highmem size */
24876 @@ -735,6 +734,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 #ifdef CONFIG_FLATMEM
24887 BUG_ON(!mem_map);
24888 #endif
24889 @@ -761,7 +766,7 @@ void __init mem_init(void)
24890 reservedpages++;
24891
24892 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24893 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24894 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24895 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24896
24897 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24898 @@ -802,10 +807,10 @@ void __init mem_init(void)
24899 ((unsigned long)&__init_end -
24900 (unsigned long)&__init_begin) >> 10,
24901
24902 - (unsigned long)&_etext, (unsigned long)&_edata,
24903 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24904 + (unsigned long)&_sdata, (unsigned long)&_edata,
24905 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24906
24907 - (unsigned long)&_text, (unsigned long)&_etext,
24908 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24909 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24910
24911 /*
24912 @@ -883,6 +888,7 @@ void set_kernel_text_rw(void)
24913 if (!kernel_set_to_readonly)
24914 return;
24915
24916 + start = ktla_ktva(start);
24917 pr_debug("Set kernel text: %lx - %lx for read write\n",
24918 start, start+size);
24919
24920 @@ -897,6 +903,7 @@ void set_kernel_text_ro(void)
24921 if (!kernel_set_to_readonly)
24922 return;
24923
24924 + start = ktla_ktva(start);
24925 pr_debug("Set kernel text: %lx - %lx for read only\n",
24926 start, start+size);
24927
24928 @@ -925,6 +932,7 @@ void mark_rodata_ro(void)
24929 unsigned long start = PFN_ALIGN(_text);
24930 unsigned long size = PFN_ALIGN(_etext) - start;
24931
24932 + start = ktla_ktva(start);
24933 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24934 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24935 size >> 10);
24936 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24937 index 436a030..4f97ffc 100644
24938 --- a/arch/x86/mm/init_64.c
24939 +++ b/arch/x86/mm/init_64.c
24940 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24941 * around without checking the pgd every time.
24942 */
24943
24944 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24945 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24946 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24947
24948 int force_personality32;
24949 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24950
24951 for (address = start; address <= end; address += PGDIR_SIZE) {
24952 const pgd_t *pgd_ref = pgd_offset_k(address);
24953 +
24954 +#ifdef CONFIG_PAX_PER_CPU_PGD
24955 + unsigned long cpu;
24956 +#else
24957 struct page *page;
24958 +#endif
24959
24960 if (pgd_none(*pgd_ref))
24961 continue;
24962
24963 spin_lock(&pgd_lock);
24964 +
24965 +#ifdef CONFIG_PAX_PER_CPU_PGD
24966 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24967 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24968 +#else
24969 list_for_each_entry(page, &pgd_list, lru) {
24970 pgd_t *pgd;
24971 spinlock_t *pgt_lock;
24972 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24973 /* the pgt_lock only for Xen */
24974 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24975 spin_lock(pgt_lock);
24976 +#endif
24977
24978 if (pgd_none(*pgd))
24979 set_pgd(pgd, *pgd_ref);
24980 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24981 BUG_ON(pgd_page_vaddr(*pgd)
24982 != pgd_page_vaddr(*pgd_ref));
24983
24984 +#ifndef CONFIG_PAX_PER_CPU_PGD
24985 spin_unlock(pgt_lock);
24986 +#endif
24987 +
24988 }
24989 spin_unlock(&pgd_lock);
24990 }
24991 @@ -162,7 +176,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
24992 {
24993 if (pgd_none(*pgd)) {
24994 pud_t *pud = (pud_t *)spp_getpage();
24995 - pgd_populate(&init_mm, pgd, pud);
24996 + pgd_populate_kernel(&init_mm, pgd, pud);
24997 if (pud != pud_offset(pgd, 0))
24998 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
24999 pud, pud_offset(pgd, 0));
25000 @@ -174,7 +188,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25001 {
25002 if (pud_none(*pud)) {
25003 pmd_t *pmd = (pmd_t *) spp_getpage();
25004 - pud_populate(&init_mm, pud, pmd);
25005 + pud_populate_kernel(&init_mm, pud, pmd);
25006 if (pmd != pmd_offset(pud, 0))
25007 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25008 pmd, pmd_offset(pud, 0));
25009 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25010 pmd = fill_pmd(pud, vaddr);
25011 pte = fill_pte(pmd, vaddr);
25012
25013 + pax_open_kernel();
25014 set_pte(pte, new_pte);
25015 + pax_close_kernel();
25016
25017 /*
25018 * It's enough to flush this one mapping.
25019 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25020 pgd = pgd_offset_k((unsigned long)__va(phys));
25021 if (pgd_none(*pgd)) {
25022 pud = (pud_t *) spp_getpage();
25023 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25024 - _PAGE_USER));
25025 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25026 }
25027 pud = pud_offset(pgd, (unsigned long)__va(phys));
25028 if (pud_none(*pud)) {
25029 pmd = (pmd_t *) spp_getpage();
25030 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25031 - _PAGE_USER));
25032 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25033 }
25034 pmd = pmd_offset(pud, phys);
25035 BUG_ON(!pmd_none(*pmd));
25036 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25037 if (pfn >= pgt_buf_top)
25038 panic("alloc_low_page: ran out of memory");
25039
25040 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25041 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25042 clear_page(adr);
25043 *phys = pfn * PAGE_SIZE;
25044 return adr;
25045 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
25046
25047 phys = __pa(virt);
25048 left = phys & (PAGE_SIZE - 1);
25049 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25050 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25051 adr = (void *)(((unsigned long)adr) | left);
25052
25053 return adr;
25054 @@ -546,7 +560,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25055 unmap_low_page(pmd);
25056
25057 spin_lock(&init_mm.page_table_lock);
25058 - pud_populate(&init_mm, pud, __va(pmd_phys));
25059 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25060 spin_unlock(&init_mm.page_table_lock);
25061 }
25062 __flush_tlb_all();
25063 @@ -592,7 +606,7 @@ kernel_physical_mapping_init(unsigned long start,
25064 unmap_low_page(pud);
25065
25066 spin_lock(&init_mm.page_table_lock);
25067 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25068 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25069 spin_unlock(&init_mm.page_table_lock);
25070 pgd_changed = true;
25071 }
25072 @@ -684,6 +698,12 @@ void __init mem_init(void)
25073
25074 pci_iommu_alloc();
25075
25076 +#ifdef CONFIG_PAX_PER_CPU_PGD
25077 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25078 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25079 + KERNEL_PGD_PTRS);
25080 +#endif
25081 +
25082 /* clear_bss() already clear the empty_zero_page */
25083
25084 reservedpages = 0;
25085 @@ -844,8 +864,8 @@ int kern_addr_valid(unsigned long addr)
25086 static struct vm_area_struct gate_vma = {
25087 .vm_start = VSYSCALL_START,
25088 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25089 - .vm_page_prot = PAGE_READONLY_EXEC,
25090 - .vm_flags = VM_READ | VM_EXEC
25091 + .vm_page_prot = PAGE_READONLY,
25092 + .vm_flags = VM_READ
25093 };
25094
25095 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25096 @@ -879,7 +899,7 @@ int in_gate_area_no_mm(unsigned long addr)
25097
25098 const char *arch_vma_name(struct vm_area_struct *vma)
25099 {
25100 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25101 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25102 return "[vdso]";
25103 if (vma == &gate_vma)
25104 return "[vsyscall]";
25105 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25106 index 7b179b4..6bd1777 100644
25107 --- a/arch/x86/mm/iomap_32.c
25108 +++ b/arch/x86/mm/iomap_32.c
25109 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25110 type = kmap_atomic_idx_push();
25111 idx = type + KM_TYPE_NR * smp_processor_id();
25112 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25113 +
25114 + pax_open_kernel();
25115 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25116 + pax_close_kernel();
25117 +
25118 arch_flush_lazy_mmu_mode();
25119
25120 return (void *)vaddr;
25121 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25122 index be1ef57..55f0160 100644
25123 --- a/arch/x86/mm/ioremap.c
25124 +++ b/arch/x86/mm/ioremap.c
25125 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25126 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25127 int is_ram = page_is_ram(pfn);
25128
25129 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25130 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25131 return NULL;
25132 WARN_ON_ONCE(is_ram);
25133 }
25134 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25135
25136 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25137 if (page_is_ram(start >> PAGE_SHIFT))
25138 +#ifdef CONFIG_HIGHMEM
25139 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25140 +#endif
25141 return __va(phys);
25142
25143 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25144 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25145 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25146
25147 static __initdata int after_paging_init;
25148 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25149 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25150
25151 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25152 {
25153 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25154 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25155
25156 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25157 - memset(bm_pte, 0, sizeof(bm_pte));
25158 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25159 + pmd_populate_user(&init_mm, pmd, bm_pte);
25160
25161 /*
25162 * The boot-ioremap range spans multiple pmds, for which
25163 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25164 index d87dd6d..bf3fa66 100644
25165 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25166 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25167 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25168 * memory (e.g. tracked pages)? For now, we need this to avoid
25169 * invoking kmemcheck for PnP BIOS calls.
25170 */
25171 - if (regs->flags & X86_VM_MASK)
25172 + if (v8086_mode(regs))
25173 return false;
25174 - if (regs->cs != __KERNEL_CS)
25175 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25176 return false;
25177
25178 pte = kmemcheck_pte_lookup(address);
25179 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25180 index 845df68..1d8d29f 100644
25181 --- a/arch/x86/mm/mmap.c
25182 +++ b/arch/x86/mm/mmap.c
25183 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25184 * Leave an at least ~128 MB hole with possible stack randomization.
25185 */
25186 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25187 -#define MAX_GAP (TASK_SIZE/6*5)
25188 +#define MAX_GAP (pax_task_size/6*5)
25189
25190 static int mmap_is_legacy(void)
25191 {
25192 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25193 return rnd << PAGE_SHIFT;
25194 }
25195
25196 -static unsigned long mmap_base(void)
25197 +static unsigned long mmap_base(struct mm_struct *mm)
25198 {
25199 unsigned long gap = rlimit(RLIMIT_STACK);
25200 + unsigned long pax_task_size = TASK_SIZE;
25201 +
25202 +#ifdef CONFIG_PAX_SEGMEXEC
25203 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25204 + pax_task_size = SEGMEXEC_TASK_SIZE;
25205 +#endif
25206
25207 if (gap < MIN_GAP)
25208 gap = MIN_GAP;
25209 else if (gap > MAX_GAP)
25210 gap = MAX_GAP;
25211
25212 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25213 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25214 }
25215
25216 /*
25217 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25218 * does, but not when emulating X86_32
25219 */
25220 -static unsigned long mmap_legacy_base(void)
25221 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25222 {
25223 - if (mmap_is_ia32())
25224 + if (mmap_is_ia32()) {
25225 +
25226 +#ifdef CONFIG_PAX_SEGMEXEC
25227 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25228 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25229 + else
25230 +#endif
25231 +
25232 return TASK_UNMAPPED_BASE;
25233 - else
25234 + } else
25235 return TASK_UNMAPPED_BASE + mmap_rnd();
25236 }
25237
25238 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25239 void arch_pick_mmap_layout(struct mm_struct *mm)
25240 {
25241 if (mmap_is_legacy()) {
25242 - mm->mmap_base = mmap_legacy_base();
25243 + mm->mmap_base = mmap_legacy_base(mm);
25244 +
25245 +#ifdef CONFIG_PAX_RANDMMAP
25246 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25247 + mm->mmap_base += mm->delta_mmap;
25248 +#endif
25249 +
25250 mm->get_unmapped_area = arch_get_unmapped_area;
25251 mm->unmap_area = arch_unmap_area;
25252 } else {
25253 - mm->mmap_base = mmap_base();
25254 + mm->mmap_base = mmap_base(mm);
25255 +
25256 +#ifdef CONFIG_PAX_RANDMMAP
25257 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25258 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25259 +#endif
25260 +
25261 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25262 mm->unmap_area = arch_unmap_area_topdown;
25263 }
25264 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25265 index dc0b727..dc9d71a 100644
25266 --- a/arch/x86/mm/mmio-mod.c
25267 +++ b/arch/x86/mm/mmio-mod.c
25268 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25269 break;
25270 default:
25271 {
25272 - unsigned char *ip = (unsigned char *)instptr;
25273 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25274 my_trace->opcode = MMIO_UNKNOWN_OP;
25275 my_trace->width = 0;
25276 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25277 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25278 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25279 void __iomem *addr)
25280 {
25281 - static atomic_t next_id;
25282 + static atomic_unchecked_t next_id;
25283 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25284 /* These are page-unaligned. */
25285 struct mmiotrace_map map = {
25286 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25287 .private = trace
25288 },
25289 .phys = offset,
25290 - .id = atomic_inc_return(&next_id)
25291 + .id = atomic_inc_return_unchecked(&next_id)
25292 };
25293 map.map_id = trace->id;
25294
25295 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25296 index b008656..773eac2 100644
25297 --- a/arch/x86/mm/pageattr-test.c
25298 +++ b/arch/x86/mm/pageattr-test.c
25299 @@ -36,7 +36,7 @@ enum {
25300
25301 static int pte_testbit(pte_t pte)
25302 {
25303 - return pte_flags(pte) & _PAGE_UNUSED1;
25304 + return pte_flags(pte) & _PAGE_CPA_TEST;
25305 }
25306
25307 struct split_state {
25308 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25309 index e1ebde3..b1e1db38 100644
25310 --- a/arch/x86/mm/pageattr.c
25311 +++ b/arch/x86/mm/pageattr.c
25312 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25313 */
25314 #ifdef CONFIG_PCI_BIOS
25315 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25316 - pgprot_val(forbidden) |= _PAGE_NX;
25317 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25318 #endif
25319
25320 /*
25321 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25322 * Does not cover __inittext since that is gone later on. On
25323 * 64bit we do not enforce !NX on the low mapping
25324 */
25325 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25326 - pgprot_val(forbidden) |= _PAGE_NX;
25327 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25328 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25329
25330 +#ifdef CONFIG_DEBUG_RODATA
25331 /*
25332 * The .rodata section needs to be read-only. Using the pfn
25333 * catches all aliases.
25334 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25335 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25336 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25337 pgprot_val(forbidden) |= _PAGE_RW;
25338 +#endif
25339
25340 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25341 /*
25342 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25343 }
25344 #endif
25345
25346 +#ifdef CONFIG_PAX_KERNEXEC
25347 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25348 + pgprot_val(forbidden) |= _PAGE_RW;
25349 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25350 + }
25351 +#endif
25352 +
25353 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25354
25355 return prot;
25356 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25357 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25358 {
25359 /* change init_mm */
25360 + pax_open_kernel();
25361 set_pte_atomic(kpte, pte);
25362 +
25363 #ifdef CONFIG_X86_32
25364 if (!SHARED_KERNEL_PMD) {
25365 +
25366 +#ifdef CONFIG_PAX_PER_CPU_PGD
25367 + unsigned long cpu;
25368 +#else
25369 struct page *page;
25370 +#endif
25371
25372 +#ifdef CONFIG_PAX_PER_CPU_PGD
25373 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25374 + pgd_t *pgd = get_cpu_pgd(cpu);
25375 +#else
25376 list_for_each_entry(page, &pgd_list, lru) {
25377 - pgd_t *pgd;
25378 + pgd_t *pgd = (pgd_t *)page_address(page);
25379 +#endif
25380 +
25381 pud_t *pud;
25382 pmd_t *pmd;
25383
25384 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25385 + pgd += pgd_index(address);
25386 pud = pud_offset(pgd, address);
25387 pmd = pmd_offset(pud, address);
25388 set_pte_atomic((pte_t *)pmd, pte);
25389 }
25390 }
25391 #endif
25392 + pax_close_kernel();
25393 }
25394
25395 static int
25396 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25397 index f6ff57b..481690f 100644
25398 --- a/arch/x86/mm/pat.c
25399 +++ b/arch/x86/mm/pat.c
25400 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25401
25402 if (!entry) {
25403 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25404 - current->comm, current->pid, start, end);
25405 + current->comm, task_pid_nr(current), start, end);
25406 return -EINVAL;
25407 }
25408
25409 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25410 while (cursor < to) {
25411 if (!devmem_is_allowed(pfn)) {
25412 printk(KERN_INFO
25413 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25414 - current->comm, from, to);
25415 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25416 + current->comm, from, to, cursor);
25417 return 0;
25418 }
25419 cursor += PAGE_SIZE;
25420 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25421 printk(KERN_INFO
25422 "%s:%d ioremap_change_attr failed %s "
25423 "for %Lx-%Lx\n",
25424 - current->comm, current->pid,
25425 + current->comm, task_pid_nr(current),
25426 cattr_name(flags),
25427 base, (unsigned long long)(base + size));
25428 return -EINVAL;
25429 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25430 if (want_flags != flags) {
25431 printk(KERN_WARNING
25432 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25433 - current->comm, current->pid,
25434 + current->comm, task_pid_nr(current),
25435 cattr_name(want_flags),
25436 (unsigned long long)paddr,
25437 (unsigned long long)(paddr + size),
25438 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25439 free_memtype(paddr, paddr + size);
25440 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25441 " for %Lx-%Lx, got %s\n",
25442 - current->comm, current->pid,
25443 + current->comm, task_pid_nr(current),
25444 cattr_name(want_flags),
25445 (unsigned long long)paddr,
25446 (unsigned long long)(paddr + size),
25447 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25448 index 9f0614d..92ae64a 100644
25449 --- a/arch/x86/mm/pf_in.c
25450 +++ b/arch/x86/mm/pf_in.c
25451 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25452 int i;
25453 enum reason_type rv = OTHERS;
25454
25455 - p = (unsigned char *)ins_addr;
25456 + p = (unsigned char *)ktla_ktva(ins_addr);
25457 p += skip_prefix(p, &prf);
25458 p += get_opcode(p, &opcode);
25459
25460 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25461 struct prefix_bits prf;
25462 int i;
25463
25464 - p = (unsigned char *)ins_addr;
25465 + p = (unsigned char *)ktla_ktva(ins_addr);
25466 p += skip_prefix(p, &prf);
25467 p += get_opcode(p, &opcode);
25468
25469 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25470 struct prefix_bits prf;
25471 int i;
25472
25473 - p = (unsigned char *)ins_addr;
25474 + p = (unsigned char *)ktla_ktva(ins_addr);
25475 p += skip_prefix(p, &prf);
25476 p += get_opcode(p, &opcode);
25477
25478 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25479 struct prefix_bits prf;
25480 int i;
25481
25482 - p = (unsigned char *)ins_addr;
25483 + p = (unsigned char *)ktla_ktva(ins_addr);
25484 p += skip_prefix(p, &prf);
25485 p += get_opcode(p, &opcode);
25486 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25487 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25488 struct prefix_bits prf;
25489 int i;
25490
25491 - p = (unsigned char *)ins_addr;
25492 + p = (unsigned char *)ktla_ktva(ins_addr);
25493 p += skip_prefix(p, &prf);
25494 p += get_opcode(p, &opcode);
25495 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25496 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25497 index 8573b83..7d9628f 100644
25498 --- a/arch/x86/mm/pgtable.c
25499 +++ b/arch/x86/mm/pgtable.c
25500 @@ -84,10 +84,60 @@ static inline void pgd_list_del(pgd_t *pgd)
25501 list_del(&page->lru);
25502 }
25503
25504 -#define UNSHARED_PTRS_PER_PGD \
25505 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25506 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25507 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25508
25509 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25510 +{
25511 + while (count--)
25512 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25513 +}
25514 +#endif
25515
25516 +#ifdef CONFIG_PAX_PER_CPU_PGD
25517 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25518 +{
25519 + while (count--) {
25520 + pgd_t pgd;
25521 +
25522 +#ifdef CONFIG_X86_64
25523 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25524 +#else
25525 + pgd = *src++;
25526 +#endif
25527 +
25528 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25529 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25530 +#endif
25531 +
25532 + *dst++ = pgd;
25533 + }
25534 +
25535 +}
25536 +#endif
25537 +
25538 +#ifdef CONFIG_X86_64
25539 +#define pxd_t pud_t
25540 +#define pyd_t pgd_t
25541 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25542 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25543 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25544 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25545 +#define PYD_SIZE PGDIR_SIZE
25546 +#else
25547 +#define pxd_t pmd_t
25548 +#define pyd_t pud_t
25549 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25550 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25551 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25552 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25553 +#define PYD_SIZE PUD_SIZE
25554 +#endif
25555 +
25556 +#ifdef CONFIG_PAX_PER_CPU_PGD
25557 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25558 +static inline void pgd_dtor(pgd_t *pgd) {}
25559 +#else
25560 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25561 {
25562 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25563 @@ -128,6 +178,7 @@ static void pgd_dtor(pgd_t *pgd)
25564 pgd_list_del(pgd);
25565 spin_unlock(&pgd_lock);
25566 }
25567 +#endif
25568
25569 /*
25570 * List of all pgd's needed for non-PAE so it can invalidate entries
25571 @@ -140,7 +191,7 @@ static void pgd_dtor(pgd_t *pgd)
25572 * -- wli
25573 */
25574
25575 -#ifdef CONFIG_X86_PAE
25576 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25577 /*
25578 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25579 * updating the top-level pagetable entries to guarantee the
25580 @@ -152,7 +203,7 @@ static void pgd_dtor(pgd_t *pgd)
25581 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25582 * and initialize the kernel pmds here.
25583 */
25584 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25585 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25586
25587 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25588 {
25589 @@ -170,36 +221,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25590 */
25591 flush_tlb_mm(mm);
25592 }
25593 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25594 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25595 #else /* !CONFIG_X86_PAE */
25596
25597 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25598 -#define PREALLOCATED_PMDS 0
25599 +#define PREALLOCATED_PXDS 0
25600
25601 #endif /* CONFIG_X86_PAE */
25602
25603 -static void free_pmds(pmd_t *pmds[])
25604 +static void free_pxds(pxd_t *pxds[])
25605 {
25606 int i;
25607
25608 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25609 - if (pmds[i])
25610 - free_page((unsigned long)pmds[i]);
25611 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25612 + if (pxds[i])
25613 + free_page((unsigned long)pxds[i]);
25614 }
25615
25616 -static int preallocate_pmds(pmd_t *pmds[])
25617 +static int preallocate_pxds(pxd_t *pxds[])
25618 {
25619 int i;
25620 bool failed = false;
25621
25622 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25623 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25624 - if (pmd == NULL)
25625 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25626 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25627 + if (pxd == NULL)
25628 failed = true;
25629 - pmds[i] = pmd;
25630 + pxds[i] = pxd;
25631 }
25632
25633 if (failed) {
25634 - free_pmds(pmds);
25635 + free_pxds(pxds);
25636 return -ENOMEM;
25637 }
25638
25639 @@ -212,51 +265,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25640 * preallocate which never got a corresponding vma will need to be
25641 * freed manually.
25642 */
25643 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25644 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25645 {
25646 int i;
25647
25648 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25649 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25650 pgd_t pgd = pgdp[i];
25651
25652 if (pgd_val(pgd) != 0) {
25653 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25654 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25655
25656 - pgdp[i] = native_make_pgd(0);
25657 + set_pgd(pgdp + i, native_make_pgd(0));
25658
25659 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25660 - pmd_free(mm, pmd);
25661 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25662 + pxd_free(mm, pxd);
25663 }
25664 }
25665 }
25666
25667 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25668 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25669 {
25670 - pud_t *pud;
25671 + pyd_t *pyd;
25672 unsigned long addr;
25673 int i;
25674
25675 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25676 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25677 return;
25678
25679 - pud = pud_offset(pgd, 0);
25680 +#ifdef CONFIG_X86_64
25681 + pyd = pyd_offset(mm, 0L);
25682 +#else
25683 + pyd = pyd_offset(pgd, 0L);
25684 +#endif
25685
25686 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25687 - i++, pud++, addr += PUD_SIZE) {
25688 - pmd_t *pmd = pmds[i];
25689 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25690 + i++, pyd++, addr += PYD_SIZE) {
25691 + pxd_t *pxd = pxds[i];
25692
25693 if (i >= KERNEL_PGD_BOUNDARY)
25694 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25695 - sizeof(pmd_t) * PTRS_PER_PMD);
25696 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25697 + sizeof(pxd_t) * PTRS_PER_PMD);
25698
25699 - pud_populate(mm, pud, pmd);
25700 + pyd_populate(mm, pyd, pxd);
25701 }
25702 }
25703
25704 pgd_t *pgd_alloc(struct mm_struct *mm)
25705 {
25706 pgd_t *pgd;
25707 - pmd_t *pmds[PREALLOCATED_PMDS];
25708 + pxd_t *pxds[PREALLOCATED_PXDS];
25709
25710 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25711
25712 @@ -265,11 +322,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25713
25714 mm->pgd = pgd;
25715
25716 - if (preallocate_pmds(pmds) != 0)
25717 + if (preallocate_pxds(pxds) != 0)
25718 goto out_free_pgd;
25719
25720 if (paravirt_pgd_alloc(mm) != 0)
25721 - goto out_free_pmds;
25722 + goto out_free_pxds;
25723
25724 /*
25725 * Make sure that pre-populating the pmds is atomic with
25726 @@ -279,14 +336,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25727 spin_lock(&pgd_lock);
25728
25729 pgd_ctor(mm, pgd);
25730 - pgd_prepopulate_pmd(mm, pgd, pmds);
25731 + pgd_prepopulate_pxd(mm, pgd, pxds);
25732
25733 spin_unlock(&pgd_lock);
25734
25735 return pgd;
25736
25737 -out_free_pmds:
25738 - free_pmds(pmds);
25739 +out_free_pxds:
25740 + free_pxds(pxds);
25741 out_free_pgd:
25742 free_page((unsigned long)pgd);
25743 out:
25744 @@ -295,7 +352,7 @@ out:
25745
25746 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25747 {
25748 - pgd_mop_up_pmds(mm, pgd);
25749 + pgd_mop_up_pxds(mm, pgd);
25750 pgd_dtor(pgd);
25751 paravirt_pgd_free(mm, pgd);
25752 free_page((unsigned long)pgd);
25753 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25754 index cac7184..09a39fa 100644
25755 --- a/arch/x86/mm/pgtable_32.c
25756 +++ b/arch/x86/mm/pgtable_32.c
25757 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25758 return;
25759 }
25760 pte = pte_offset_kernel(pmd, vaddr);
25761 +
25762 + pax_open_kernel();
25763 if (pte_val(pteval))
25764 set_pte_at(&init_mm, vaddr, pte, pteval);
25765 else
25766 pte_clear(&init_mm, vaddr, pte);
25767 + pax_close_kernel();
25768
25769 /*
25770 * It's enough to flush this one mapping.
25771 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25772 index 410531d..0f16030 100644
25773 --- a/arch/x86/mm/setup_nx.c
25774 +++ b/arch/x86/mm/setup_nx.c
25775 @@ -5,8 +5,10 @@
25776 #include <asm/pgtable.h>
25777 #include <asm/proto.h>
25778
25779 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25780 static int disable_nx __cpuinitdata;
25781
25782 +#ifndef CONFIG_PAX_PAGEEXEC
25783 /*
25784 * noexec = on|off
25785 *
25786 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25787 return 0;
25788 }
25789 early_param("noexec", noexec_setup);
25790 +#endif
25791 +
25792 +#endif
25793
25794 void __cpuinit x86_configure_nx(void)
25795 {
25796 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25797 if (cpu_has_nx && !disable_nx)
25798 __supported_pte_mask |= _PAGE_NX;
25799 else
25800 +#endif
25801 __supported_pte_mask &= ~_PAGE_NX;
25802 }
25803
25804 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25805 index d6c0418..06a0ad5 100644
25806 --- a/arch/x86/mm/tlb.c
25807 +++ b/arch/x86/mm/tlb.c
25808 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
25809 BUG();
25810 cpumask_clear_cpu(cpu,
25811 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25812 +
25813 +#ifndef CONFIG_PAX_PER_CPU_PGD
25814 load_cr3(swapper_pg_dir);
25815 +#endif
25816 +
25817 }
25818 EXPORT_SYMBOL_GPL(leave_mm);
25819
25820 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25821 index 6687022..ceabcfa 100644
25822 --- a/arch/x86/net/bpf_jit.S
25823 +++ b/arch/x86/net/bpf_jit.S
25824 @@ -9,6 +9,7 @@
25825 */
25826 #include <linux/linkage.h>
25827 #include <asm/dwarf2.h>
25828 +#include <asm/alternative-asm.h>
25829
25830 /*
25831 * Calling convention :
25832 @@ -35,6 +36,7 @@ sk_load_word:
25833 jle bpf_slow_path_word
25834 mov (SKBDATA,%rsi),%eax
25835 bswap %eax /* ntohl() */
25836 + pax_force_retaddr
25837 ret
25838
25839
25840 @@ -53,6 +55,7 @@ sk_load_half:
25841 jle bpf_slow_path_half
25842 movzwl (SKBDATA,%rsi),%eax
25843 rol $8,%ax # ntohs()
25844 + pax_force_retaddr
25845 ret
25846
25847 sk_load_byte_ind:
25848 @@ -66,6 +69,7 @@ sk_load_byte:
25849 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25850 jle bpf_slow_path_byte
25851 movzbl (SKBDATA,%rsi),%eax
25852 + pax_force_retaddr
25853 ret
25854
25855 /**
25856 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
25857 movzbl (SKBDATA,%rsi),%ebx
25858 and $15,%bl
25859 shl $2,%bl
25860 + pax_force_retaddr
25861 ret
25862 CFI_ENDPROC
25863 ENDPROC(sk_load_byte_msh)
25864 @@ -91,6 +96,7 @@ bpf_error:
25865 xor %eax,%eax
25866 mov -8(%rbp),%rbx
25867 leaveq
25868 + pax_force_retaddr
25869 ret
25870
25871 /* rsi contains offset and can be scratched */
25872 @@ -113,6 +119,7 @@ bpf_slow_path_word:
25873 js bpf_error
25874 mov -12(%rbp),%eax
25875 bswap %eax
25876 + pax_force_retaddr
25877 ret
25878
25879 bpf_slow_path_half:
25880 @@ -121,12 +128,14 @@ bpf_slow_path_half:
25881 mov -12(%rbp),%ax
25882 rol $8,%ax
25883 movzwl %ax,%eax
25884 + pax_force_retaddr
25885 ret
25886
25887 bpf_slow_path_byte:
25888 bpf_slow_path_common(1)
25889 js bpf_error
25890 movzbl -12(%rbp),%eax
25891 + pax_force_retaddr
25892 ret
25893
25894 bpf_slow_path_byte_msh:
25895 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
25896 and $15,%al
25897 shl $2,%al
25898 xchg %eax,%ebx
25899 + pax_force_retaddr
25900 ret
25901 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25902 index 5a5b6e4..201d42e 100644
25903 --- a/arch/x86/net/bpf_jit_comp.c
25904 +++ b/arch/x86/net/bpf_jit_comp.c
25905 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
25906 set_fs(old_fs);
25907 }
25908
25909 +struct bpf_jit_work {
25910 + struct work_struct work;
25911 + void *image;
25912 +};
25913
25914 void bpf_jit_compile(struct sk_filter *fp)
25915 {
25916 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25917 if (addrs == NULL)
25918 return;
25919
25920 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25921 + if (!fp->work)
25922 + goto out;
25923 +
25924 /* Before first pass, make a rough estimation of addrs[]
25925 * each bpf instruction is translated to less than 64 bytes
25926 */
25927 @@ -477,7 +485,7 @@ void bpf_jit_compile(struct sk_filter *fp)
25928 common_load: seen |= SEEN_DATAREF;
25929 if ((int)K < 0) {
25930 /* Abort the JIT because __load_pointer() is needed. */
25931 - goto out;
25932 + goto error;
25933 }
25934 t_offset = func - (image + addrs[i]);
25935 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
25936 @@ -492,7 +500,7 @@ common_load: seen |= SEEN_DATAREF;
25937 case BPF_S_LDX_B_MSH:
25938 if ((int)K < 0) {
25939 /* Abort the JIT because __load_pointer() is needed. */
25940 - goto out;
25941 + goto error;
25942 }
25943 seen |= SEEN_DATAREF | SEEN_XREG;
25944 t_offset = sk_load_byte_msh - (image + addrs[i]);
25945 @@ -582,17 +590,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25946 break;
25947 default:
25948 /* hmm, too complex filter, give up with jit compiler */
25949 - goto out;
25950 + goto error;
25951 }
25952 ilen = prog - temp;
25953 if (image) {
25954 if (unlikely(proglen + ilen > oldproglen)) {
25955 pr_err("bpb_jit_compile fatal error\n");
25956 - kfree(addrs);
25957 - module_free(NULL, image);
25958 - return;
25959 + module_free_exec(NULL, image);
25960 + goto error;
25961 }
25962 + pax_open_kernel();
25963 memcpy(image + proglen, temp, ilen);
25964 + pax_close_kernel();
25965 }
25966 proglen += ilen;
25967 addrs[i] = proglen;
25968 @@ -613,11 +622,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25969 break;
25970 }
25971 if (proglen == oldproglen) {
25972 - image = module_alloc(max_t(unsigned int,
25973 - proglen,
25974 - sizeof(struct work_struct)));
25975 + image = module_alloc_exec(proglen);
25976 if (!image)
25977 - goto out;
25978 + goto error;
25979 }
25980 oldproglen = proglen;
25981 }
25982 @@ -633,7 +640,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25983 bpf_flush_icache(image, image + proglen);
25984
25985 fp->bpf_func = (void *)image;
25986 - }
25987 + } else
25988 +error:
25989 + kfree(fp->work);
25990 +
25991 out:
25992 kfree(addrs);
25993 return;
25994 @@ -641,18 +651,20 @@ out:
25995
25996 static void jit_free_defer(struct work_struct *arg)
25997 {
25998 - module_free(NULL, arg);
25999 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26000 + kfree(arg);
26001 }
26002
26003 /* run from softirq, we must use a work_struct to call
26004 - * module_free() from process context
26005 + * module_free_exec() from process context
26006 */
26007 void bpf_jit_free(struct sk_filter *fp)
26008 {
26009 if (fp->bpf_func != sk_run_filter) {
26010 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26011 + struct work_struct *work = &fp->work->work;
26012
26013 INIT_WORK(work, jit_free_defer);
26014 + fp->work->image = fp->bpf_func;
26015 schedule_work(work);
26016 }
26017 }
26018 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26019 index bff89df..377758a 100644
26020 --- a/arch/x86/oprofile/backtrace.c
26021 +++ b/arch/x86/oprofile/backtrace.c
26022 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26023 struct stack_frame_ia32 *fp;
26024 unsigned long bytes;
26025
26026 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26027 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26028 if (bytes != sizeof(bufhead))
26029 return NULL;
26030
26031 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26032 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26033
26034 oprofile_add_trace(bufhead[0].return_address);
26035
26036 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26037 struct stack_frame bufhead[2];
26038 unsigned long bytes;
26039
26040 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26041 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26042 if (bytes != sizeof(bufhead))
26043 return NULL;
26044
26045 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26046 {
26047 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26048
26049 - if (!user_mode_vm(regs)) {
26050 + if (!user_mode(regs)) {
26051 unsigned long stack = kernel_stack_pointer(regs);
26052 if (depth)
26053 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26054 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26055 index cb29191..036766d 100644
26056 --- a/arch/x86/pci/mrst.c
26057 +++ b/arch/x86/pci/mrst.c
26058 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
26059 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
26060 pci_mmcfg_late_init();
26061 pcibios_enable_irq = mrst_pci_irq_enable;
26062 - pci_root_ops = pci_mrst_ops;
26063 + pax_open_kernel();
26064 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26065 + pax_close_kernel();
26066 /* Continue with standard init */
26067 return 1;
26068 }
26069 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26070 index da8fe05..7ee6704 100644
26071 --- a/arch/x86/pci/pcbios.c
26072 +++ b/arch/x86/pci/pcbios.c
26073 @@ -79,50 +79,93 @@ union bios32 {
26074 static struct {
26075 unsigned long address;
26076 unsigned short segment;
26077 -} bios32_indirect = { 0, __KERNEL_CS };
26078 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26079
26080 /*
26081 * Returns the entry point for the given service, NULL on error
26082 */
26083
26084 -static unsigned long bios32_service(unsigned long service)
26085 +static unsigned long __devinit bios32_service(unsigned long service)
26086 {
26087 unsigned char return_code; /* %al */
26088 unsigned long address; /* %ebx */
26089 unsigned long length; /* %ecx */
26090 unsigned long entry; /* %edx */
26091 unsigned long flags;
26092 + struct desc_struct d, *gdt;
26093
26094 local_irq_save(flags);
26095 - __asm__("lcall *(%%edi); cld"
26096 +
26097 + gdt = get_cpu_gdt_table(smp_processor_id());
26098 +
26099 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26100 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26101 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26102 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26103 +
26104 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26105 : "=a" (return_code),
26106 "=b" (address),
26107 "=c" (length),
26108 "=d" (entry)
26109 : "0" (service),
26110 "1" (0),
26111 - "D" (&bios32_indirect));
26112 + "D" (&bios32_indirect),
26113 + "r"(__PCIBIOS_DS)
26114 + : "memory");
26115 +
26116 + pax_open_kernel();
26117 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26118 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26119 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26120 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26121 + pax_close_kernel();
26122 +
26123 local_irq_restore(flags);
26124
26125 switch (return_code) {
26126 - case 0:
26127 - return address + entry;
26128 - case 0x80: /* Not present */
26129 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26130 - return 0;
26131 - default: /* Shouldn't happen */
26132 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26133 - service, return_code);
26134 + case 0: {
26135 + int cpu;
26136 + unsigned char flags;
26137 +
26138 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26139 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26140 + printk(KERN_WARNING "bios32_service: not valid\n");
26141 return 0;
26142 + }
26143 + address = address + PAGE_OFFSET;
26144 + length += 16UL; /* some BIOSs underreport this... */
26145 + flags = 4;
26146 + if (length >= 64*1024*1024) {
26147 + length >>= PAGE_SHIFT;
26148 + flags |= 8;
26149 + }
26150 +
26151 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26152 + gdt = get_cpu_gdt_table(cpu);
26153 + pack_descriptor(&d, address, length, 0x9b, flags);
26154 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26155 + pack_descriptor(&d, address, length, 0x93, flags);
26156 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26157 + }
26158 + return entry;
26159 + }
26160 + case 0x80: /* Not present */
26161 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26162 + return 0;
26163 + default: /* Shouldn't happen */
26164 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26165 + service, return_code);
26166 + return 0;
26167 }
26168 }
26169
26170 static struct {
26171 unsigned long address;
26172 unsigned short segment;
26173 -} pci_indirect = { 0, __KERNEL_CS };
26174 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26175
26176 -static int pci_bios_present;
26177 +static int pci_bios_present __read_only;
26178
26179 static int __devinit check_pcibios(void)
26180 {
26181 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26182 unsigned long flags, pcibios_entry;
26183
26184 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26185 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26186 + pci_indirect.address = pcibios_entry;
26187
26188 local_irq_save(flags);
26189 - __asm__(
26190 - "lcall *(%%edi); cld\n\t"
26191 + __asm__("movw %w6, %%ds\n\t"
26192 + "lcall *%%ss:(%%edi); cld\n\t"
26193 + "push %%ss\n\t"
26194 + "pop %%ds\n\t"
26195 "jc 1f\n\t"
26196 "xor %%ah, %%ah\n"
26197 "1:"
26198 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26199 "=b" (ebx),
26200 "=c" (ecx)
26201 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26202 - "D" (&pci_indirect)
26203 + "D" (&pci_indirect),
26204 + "r" (__PCIBIOS_DS)
26205 : "memory");
26206 local_irq_restore(flags);
26207
26208 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26209
26210 switch (len) {
26211 case 1:
26212 - __asm__("lcall *(%%esi); cld\n\t"
26213 + __asm__("movw %w6, %%ds\n\t"
26214 + "lcall *%%ss:(%%esi); cld\n\t"
26215 + "push %%ss\n\t"
26216 + "pop %%ds\n\t"
26217 "jc 1f\n\t"
26218 "xor %%ah, %%ah\n"
26219 "1:"
26220 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26221 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26222 "b" (bx),
26223 "D" ((long)reg),
26224 - "S" (&pci_indirect));
26225 + "S" (&pci_indirect),
26226 + "r" (__PCIBIOS_DS));
26227 /*
26228 * Zero-extend the result beyond 8 bits, do not trust the
26229 * BIOS having done it:
26230 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26231 *value &= 0xff;
26232 break;
26233 case 2:
26234 - __asm__("lcall *(%%esi); cld\n\t"
26235 + __asm__("movw %w6, %%ds\n\t"
26236 + "lcall *%%ss:(%%esi); cld\n\t"
26237 + "push %%ss\n\t"
26238 + "pop %%ds\n\t"
26239 "jc 1f\n\t"
26240 "xor %%ah, %%ah\n"
26241 "1:"
26242 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26243 : "1" (PCIBIOS_READ_CONFIG_WORD),
26244 "b" (bx),
26245 "D" ((long)reg),
26246 - "S" (&pci_indirect));
26247 + "S" (&pci_indirect),
26248 + "r" (__PCIBIOS_DS));
26249 /*
26250 * Zero-extend the result beyond 16 bits, do not trust the
26251 * BIOS having done it:
26252 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26253 *value &= 0xffff;
26254 break;
26255 case 4:
26256 - __asm__("lcall *(%%esi); cld\n\t"
26257 + __asm__("movw %w6, %%ds\n\t"
26258 + "lcall *%%ss:(%%esi); cld\n\t"
26259 + "push %%ss\n\t"
26260 + "pop %%ds\n\t"
26261 "jc 1f\n\t"
26262 "xor %%ah, %%ah\n"
26263 "1:"
26264 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26265 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26266 "b" (bx),
26267 "D" ((long)reg),
26268 - "S" (&pci_indirect));
26269 + "S" (&pci_indirect),
26270 + "r" (__PCIBIOS_DS));
26271 break;
26272 }
26273
26274 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26275
26276 switch (len) {
26277 case 1:
26278 - __asm__("lcall *(%%esi); cld\n\t"
26279 + __asm__("movw %w6, %%ds\n\t"
26280 + "lcall *%%ss:(%%esi); cld\n\t"
26281 + "push %%ss\n\t"
26282 + "pop %%ds\n\t"
26283 "jc 1f\n\t"
26284 "xor %%ah, %%ah\n"
26285 "1:"
26286 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26287 "c" (value),
26288 "b" (bx),
26289 "D" ((long)reg),
26290 - "S" (&pci_indirect));
26291 + "S" (&pci_indirect),
26292 + "r" (__PCIBIOS_DS));
26293 break;
26294 case 2:
26295 - __asm__("lcall *(%%esi); cld\n\t"
26296 + __asm__("movw %w6, %%ds\n\t"
26297 + "lcall *%%ss:(%%esi); cld\n\t"
26298 + "push %%ss\n\t"
26299 + "pop %%ds\n\t"
26300 "jc 1f\n\t"
26301 "xor %%ah, %%ah\n"
26302 "1:"
26303 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26304 "c" (value),
26305 "b" (bx),
26306 "D" ((long)reg),
26307 - "S" (&pci_indirect));
26308 + "S" (&pci_indirect),
26309 + "r" (__PCIBIOS_DS));
26310 break;
26311 case 4:
26312 - __asm__("lcall *(%%esi); cld\n\t"
26313 + __asm__("movw %w6, %%ds\n\t"
26314 + "lcall *%%ss:(%%esi); cld\n\t"
26315 + "push %%ss\n\t"
26316 + "pop %%ds\n\t"
26317 "jc 1f\n\t"
26318 "xor %%ah, %%ah\n"
26319 "1:"
26320 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26321 "c" (value),
26322 "b" (bx),
26323 "D" ((long)reg),
26324 - "S" (&pci_indirect));
26325 + "S" (&pci_indirect),
26326 + "r" (__PCIBIOS_DS));
26327 break;
26328 }
26329
26330 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26331
26332 DBG("PCI: Fetching IRQ routing table... ");
26333 __asm__("push %%es\n\t"
26334 + "movw %w8, %%ds\n\t"
26335 "push %%ds\n\t"
26336 "pop %%es\n\t"
26337 - "lcall *(%%esi); cld\n\t"
26338 + "lcall *%%ss:(%%esi); cld\n\t"
26339 "pop %%es\n\t"
26340 + "push %%ss\n\t"
26341 + "pop %%ds\n"
26342 "jc 1f\n\t"
26343 "xor %%ah, %%ah\n"
26344 "1:"
26345 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26346 "1" (0),
26347 "D" ((long) &opt),
26348 "S" (&pci_indirect),
26349 - "m" (opt)
26350 + "m" (opt),
26351 + "r" (__PCIBIOS_DS)
26352 : "memory");
26353 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26354 if (ret & 0xff00)
26355 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26356 {
26357 int ret;
26358
26359 - __asm__("lcall *(%%esi); cld\n\t"
26360 + __asm__("movw %w5, %%ds\n\t"
26361 + "lcall *%%ss:(%%esi); cld\n\t"
26362 + "push %%ss\n\t"
26363 + "pop %%ds\n"
26364 "jc 1f\n\t"
26365 "xor %%ah, %%ah\n"
26366 "1:"
26367 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26368 : "0" (PCIBIOS_SET_PCI_HW_INT),
26369 "b" ((dev->bus->number << 8) | dev->devfn),
26370 "c" ((irq << 8) | (pin + 10)),
26371 - "S" (&pci_indirect));
26372 + "S" (&pci_indirect),
26373 + "r" (__PCIBIOS_DS));
26374 return !(ret & 0xff00);
26375 }
26376 EXPORT_SYMBOL(pcibios_set_irq_routing);
26377 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26378 index 40e4469..1ab536e 100644
26379 --- a/arch/x86/platform/efi/efi_32.c
26380 +++ b/arch/x86/platform/efi/efi_32.c
26381 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26382 {
26383 struct desc_ptr gdt_descr;
26384
26385 +#ifdef CONFIG_PAX_KERNEXEC
26386 + struct desc_struct d;
26387 +#endif
26388 +
26389 local_irq_save(efi_rt_eflags);
26390
26391 load_cr3(initial_page_table);
26392 __flush_tlb_all();
26393
26394 +#ifdef CONFIG_PAX_KERNEXEC
26395 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26396 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26397 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26398 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26399 +#endif
26400 +
26401 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26402 gdt_descr.size = GDT_SIZE - 1;
26403 load_gdt(&gdt_descr);
26404 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26405 {
26406 struct desc_ptr gdt_descr;
26407
26408 +#ifdef CONFIG_PAX_KERNEXEC
26409 + struct desc_struct d;
26410 +
26411 + memset(&d, 0, sizeof d);
26412 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26413 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26414 +#endif
26415 +
26416 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26417 gdt_descr.size = GDT_SIZE - 1;
26418 load_gdt(&gdt_descr);
26419 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26420 index fbe66e6..c5c0dd2 100644
26421 --- a/arch/x86/platform/efi/efi_stub_32.S
26422 +++ b/arch/x86/platform/efi/efi_stub_32.S
26423 @@ -6,7 +6,9 @@
26424 */
26425
26426 #include <linux/linkage.h>
26427 +#include <linux/init.h>
26428 #include <asm/page_types.h>
26429 +#include <asm/segment.h>
26430
26431 /*
26432 * efi_call_phys(void *, ...) is a function with variable parameters.
26433 @@ -20,7 +22,7 @@
26434 * service functions will comply with gcc calling convention, too.
26435 */
26436
26437 -.text
26438 +__INIT
26439 ENTRY(efi_call_phys)
26440 /*
26441 * 0. The function can only be called in Linux kernel. So CS has been
26442 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26443 * The mapping of lower virtual memory has been created in prelog and
26444 * epilog.
26445 */
26446 - movl $1f, %edx
26447 - subl $__PAGE_OFFSET, %edx
26448 - jmp *%edx
26449 + movl $(__KERNEXEC_EFI_DS), %edx
26450 + mov %edx, %ds
26451 + mov %edx, %es
26452 + mov %edx, %ss
26453 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26454 1:
26455
26456 /*
26457 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26458 * parameter 2, ..., param n. To make things easy, we save the return
26459 * address of efi_call_phys in a global variable.
26460 */
26461 - popl %edx
26462 - movl %edx, saved_return_addr
26463 - /* get the function pointer into ECX*/
26464 - popl %ecx
26465 - movl %ecx, efi_rt_function_ptr
26466 - movl $2f, %edx
26467 - subl $__PAGE_OFFSET, %edx
26468 - pushl %edx
26469 + popl (saved_return_addr)
26470 + popl (efi_rt_function_ptr)
26471
26472 /*
26473 * 3. Clear PG bit in %CR0.
26474 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26475 /*
26476 * 5. Call the physical function.
26477 */
26478 - jmp *%ecx
26479 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26480
26481 -2:
26482 /*
26483 * 6. After EFI runtime service returns, control will return to
26484 * following instruction. We'd better readjust stack pointer first.
26485 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26486 movl %cr0, %edx
26487 orl $0x80000000, %edx
26488 movl %edx, %cr0
26489 - jmp 1f
26490 -1:
26491 +
26492 /*
26493 * 8. Now restore the virtual mode from flat mode by
26494 * adding EIP with PAGE_OFFSET.
26495 */
26496 - movl $1f, %edx
26497 - jmp *%edx
26498 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26499 1:
26500 + movl $(__KERNEL_DS), %edx
26501 + mov %edx, %ds
26502 + mov %edx, %es
26503 + mov %edx, %ss
26504
26505 /*
26506 * 9. Balance the stack. And because EAX contain the return value,
26507 * we'd better not clobber it.
26508 */
26509 - leal efi_rt_function_ptr, %edx
26510 - movl (%edx), %ecx
26511 - pushl %ecx
26512 + pushl (efi_rt_function_ptr)
26513
26514 /*
26515 - * 10. Push the saved return address onto the stack and return.
26516 + * 10. Return to the saved return address.
26517 */
26518 - leal saved_return_addr, %edx
26519 - movl (%edx), %ecx
26520 - pushl %ecx
26521 - ret
26522 + jmpl *(saved_return_addr)
26523 ENDPROC(efi_call_phys)
26524 .previous
26525
26526 -.data
26527 +__INITDATA
26528 saved_return_addr:
26529 .long 0
26530 efi_rt_function_ptr:
26531 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26532 index 4c07cca..2c8427d 100644
26533 --- a/arch/x86/platform/efi/efi_stub_64.S
26534 +++ b/arch/x86/platform/efi/efi_stub_64.S
26535 @@ -7,6 +7,7 @@
26536 */
26537
26538 #include <linux/linkage.h>
26539 +#include <asm/alternative-asm.h>
26540
26541 #define SAVE_XMM \
26542 mov %rsp, %rax; \
26543 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26544 call *%rdi
26545 addq $32, %rsp
26546 RESTORE_XMM
26547 + pax_force_retaddr 0, 1
26548 ret
26549 ENDPROC(efi_call0)
26550
26551 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26552 call *%rdi
26553 addq $32, %rsp
26554 RESTORE_XMM
26555 + pax_force_retaddr 0, 1
26556 ret
26557 ENDPROC(efi_call1)
26558
26559 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26560 call *%rdi
26561 addq $32, %rsp
26562 RESTORE_XMM
26563 + pax_force_retaddr 0, 1
26564 ret
26565 ENDPROC(efi_call2)
26566
26567 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26568 call *%rdi
26569 addq $32, %rsp
26570 RESTORE_XMM
26571 + pax_force_retaddr 0, 1
26572 ret
26573 ENDPROC(efi_call3)
26574
26575 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26576 call *%rdi
26577 addq $32, %rsp
26578 RESTORE_XMM
26579 + pax_force_retaddr 0, 1
26580 ret
26581 ENDPROC(efi_call4)
26582
26583 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26584 call *%rdi
26585 addq $48, %rsp
26586 RESTORE_XMM
26587 + pax_force_retaddr 0, 1
26588 ret
26589 ENDPROC(efi_call5)
26590
26591 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26592 call *%rdi
26593 addq $48, %rsp
26594 RESTORE_XMM
26595 + pax_force_retaddr 0, 1
26596 ret
26597 ENDPROC(efi_call6)
26598 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26599 index 475e2cd..1b8e708 100644
26600 --- a/arch/x86/platform/mrst/mrst.c
26601 +++ b/arch/x86/platform/mrst/mrst.c
26602 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26603 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26604 int sfi_mrtc_num;
26605
26606 -static void mrst_power_off(void)
26607 +static __noreturn void mrst_power_off(void)
26608 {
26609 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26610 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
26611 + BUG();
26612 }
26613
26614 -static void mrst_reboot(void)
26615 +static __noreturn void mrst_reboot(void)
26616 {
26617 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26618 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
26619 else
26620 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26621 + BUG();
26622 }
26623
26624 /* parse all the mtimer info to a static mtimer array */
26625 diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
26626 index 3ae0e61..4202d86 100644
26627 --- a/arch/x86/platform/uv/tlb_uv.c
26628 +++ b/arch/x86/platform/uv/tlb_uv.c
26629 @@ -1424,6 +1424,8 @@ static ssize_t tunables_read(struct file *file, char __user *userbuf,
26630 * 0: display meaning of the statistics
26631 */
26632 static ssize_t ptc_proc_write(struct file *file, const char __user *user,
26633 + size_t count, loff_t *data) __size_overflow(3);
26634 +static ssize_t ptc_proc_write(struct file *file, const char __user *user,
26635 size_t count, loff_t *data)
26636 {
26637 int cpu;
26638 @@ -1539,6 +1541,8 @@ static int parse_tunables_write(struct bau_control *bcp, char *instr,
26639 * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
26640 */
26641 static ssize_t tunables_write(struct file *file, const char __user *user,
26642 + size_t count, loff_t *data) __size_overflow(3);
26643 +static ssize_t tunables_write(struct file *file, const char __user *user,
26644 size_t count, loff_t *data)
26645 {
26646 int cpu;
26647 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26648 index f10c0af..3ec1f95 100644
26649 --- a/arch/x86/power/cpu.c
26650 +++ b/arch/x86/power/cpu.c
26651 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
26652 static void fix_processor_context(void)
26653 {
26654 int cpu = smp_processor_id();
26655 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26656 + struct tss_struct *t = init_tss + cpu;
26657
26658 set_tss_desc(cpu, t); /*
26659 * This just modifies memory; should not be
26660 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
26661 */
26662
26663 #ifdef CONFIG_X86_64
26664 + pax_open_kernel();
26665 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26666 + pax_close_kernel();
26667
26668 syscall_init(); /* This sets MSR_*STAR and related */
26669 #endif
26670 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26671 index 5d17950..2253fc9 100644
26672 --- a/arch/x86/vdso/Makefile
26673 +++ b/arch/x86/vdso/Makefile
26674 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
26675 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26676 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26677
26678 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26679 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26680 GCOV_PROFILE := n
26681
26682 #
26683 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26684 index 468d591..8e80a0a 100644
26685 --- a/arch/x86/vdso/vdso32-setup.c
26686 +++ b/arch/x86/vdso/vdso32-setup.c
26687 @@ -25,6 +25,7 @@
26688 #include <asm/tlbflush.h>
26689 #include <asm/vdso.h>
26690 #include <asm/proto.h>
26691 +#include <asm/mman.h>
26692
26693 enum {
26694 VDSO_DISABLED = 0,
26695 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26696 void enable_sep_cpu(void)
26697 {
26698 int cpu = get_cpu();
26699 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26700 + struct tss_struct *tss = init_tss + cpu;
26701
26702 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26703 put_cpu();
26704 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26705 gate_vma.vm_start = FIXADDR_USER_START;
26706 gate_vma.vm_end = FIXADDR_USER_END;
26707 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26708 - gate_vma.vm_page_prot = __P101;
26709 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26710 /*
26711 * Make sure the vDSO gets into every core dump.
26712 * Dumping its contents makes post-mortem fully interpretable later
26713 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26714 if (compat)
26715 addr = VDSO_HIGH_BASE;
26716 else {
26717 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26718 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26719 if (IS_ERR_VALUE(addr)) {
26720 ret = addr;
26721 goto up_fail;
26722 }
26723 }
26724
26725 - current->mm->context.vdso = (void *)addr;
26726 + current->mm->context.vdso = addr;
26727
26728 if (compat_uses_vma || !compat) {
26729 /*
26730 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26731 }
26732
26733 current_thread_info()->sysenter_return =
26734 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26735 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26736
26737 up_fail:
26738 if (ret)
26739 - current->mm->context.vdso = NULL;
26740 + current->mm->context.vdso = 0;
26741
26742 up_write(&mm->mmap_sem);
26743
26744 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
26745
26746 const char *arch_vma_name(struct vm_area_struct *vma)
26747 {
26748 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26749 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26750 return "[vdso]";
26751 +
26752 +#ifdef CONFIG_PAX_SEGMEXEC
26753 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26754 + return "[vdso]";
26755 +#endif
26756 +
26757 return NULL;
26758 }
26759
26760 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26761 * Check to see if the corresponding task was created in compat vdso
26762 * mode.
26763 */
26764 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26765 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26766 return &gate_vma;
26767 return NULL;
26768 }
26769 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26770 index 153407c..611cba9 100644
26771 --- a/arch/x86/vdso/vma.c
26772 +++ b/arch/x86/vdso/vma.c
26773 @@ -16,8 +16,6 @@
26774 #include <asm/vdso.h>
26775 #include <asm/page.h>
26776
26777 -unsigned int __read_mostly vdso_enabled = 1;
26778 -
26779 extern char vdso_start[], vdso_end[];
26780 extern unsigned short vdso_sync_cpuid;
26781
26782 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26783 * unaligned here as a result of stack start randomization.
26784 */
26785 addr = PAGE_ALIGN(addr);
26786 - addr = align_addr(addr, NULL, ALIGN_VDSO);
26787
26788 return addr;
26789 }
26790 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26791 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26792 {
26793 struct mm_struct *mm = current->mm;
26794 - unsigned long addr;
26795 + unsigned long addr = 0;
26796 int ret;
26797
26798 - if (!vdso_enabled)
26799 - return 0;
26800 -
26801 down_write(&mm->mmap_sem);
26802 +
26803 +#ifdef CONFIG_PAX_RANDMMAP
26804 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26805 +#endif
26806 +
26807 addr = vdso_addr(mm->start_stack, vdso_size);
26808 + addr = align_addr(addr, NULL, ALIGN_VDSO);
26809 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26810 if (IS_ERR_VALUE(addr)) {
26811 ret = addr;
26812 goto up_fail;
26813 }
26814
26815 - current->mm->context.vdso = (void *)addr;
26816 + mm->context.vdso = addr;
26817
26818 ret = install_special_mapping(mm, addr, vdso_size,
26819 VM_READ|VM_EXEC|
26820 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
26821 VM_ALWAYSDUMP,
26822 vdso_pages);
26823 - if (ret) {
26824 - current->mm->context.vdso = NULL;
26825 - goto up_fail;
26826 - }
26827 +
26828 + if (ret)
26829 + mm->context.vdso = 0;
26830
26831 up_fail:
26832 up_write(&mm->mmap_sem);
26833 return ret;
26834 }
26835 -
26836 -static __init int vdso_setup(char *s)
26837 -{
26838 - vdso_enabled = simple_strtoul(s, NULL, 0);
26839 - return 0;
26840 -}
26841 -__setup("vdso=", vdso_setup);
26842 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26843 index 4172af8..2c8ed7f 100644
26844 --- a/arch/x86/xen/enlighten.c
26845 +++ b/arch/x86/xen/enlighten.c
26846 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26847
26848 struct shared_info xen_dummy_shared_info;
26849
26850 -void *xen_initial_gdt;
26851 -
26852 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
26853 __read_mostly int xen_have_vector_callback;
26854 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
26855 @@ -1029,30 +1027,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
26856 #endif
26857 };
26858
26859 -static void xen_reboot(int reason)
26860 +static __noreturn void xen_reboot(int reason)
26861 {
26862 struct sched_shutdown r = { .reason = reason };
26863
26864 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
26865 - BUG();
26866 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
26867 + BUG();
26868 }
26869
26870 -static void xen_restart(char *msg)
26871 +static __noreturn void xen_restart(char *msg)
26872 {
26873 xen_reboot(SHUTDOWN_reboot);
26874 }
26875
26876 -static void xen_emergency_restart(void)
26877 +static __noreturn void xen_emergency_restart(void)
26878 {
26879 xen_reboot(SHUTDOWN_reboot);
26880 }
26881
26882 -static void xen_machine_halt(void)
26883 +static __noreturn void xen_machine_halt(void)
26884 {
26885 xen_reboot(SHUTDOWN_poweroff);
26886 }
26887
26888 -static void xen_machine_power_off(void)
26889 +static __noreturn void xen_machine_power_off(void)
26890 {
26891 if (pm_power_off)
26892 pm_power_off();
26893 @@ -1155,7 +1153,17 @@ asmlinkage void __init xen_start_kernel(void)
26894 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
26895
26896 /* Work out if we support NX */
26897 - x86_configure_nx();
26898 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26899 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
26900 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
26901 + unsigned l, h;
26902 +
26903 + __supported_pte_mask |= _PAGE_NX;
26904 + rdmsr(MSR_EFER, l, h);
26905 + l |= EFER_NX;
26906 + wrmsr(MSR_EFER, l, h);
26907 + }
26908 +#endif
26909
26910 xen_setup_features();
26911
26912 @@ -1186,13 +1194,6 @@ asmlinkage void __init xen_start_kernel(void)
26913
26914 machine_ops = xen_machine_ops;
26915
26916 - /*
26917 - * The only reliable way to retain the initial address of the
26918 - * percpu gdt_page is to remember it here, so we can go and
26919 - * mark it RW later, when the initial percpu area is freed.
26920 - */
26921 - xen_initial_gdt = &per_cpu(gdt_page, 0);
26922 -
26923 xen_smp_init();
26924
26925 #ifdef CONFIG_ACPI_NUMA
26926 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
26927 index 95c1cf6..4bfa5be 100644
26928 --- a/arch/x86/xen/mmu.c
26929 +++ b/arch/x86/xen/mmu.c
26930 @@ -1733,6 +1733,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26931 convert_pfn_mfn(init_level4_pgt);
26932 convert_pfn_mfn(level3_ident_pgt);
26933 convert_pfn_mfn(level3_kernel_pgt);
26934 + convert_pfn_mfn(level3_vmalloc_start_pgt);
26935 + convert_pfn_mfn(level3_vmalloc_end_pgt);
26936 + convert_pfn_mfn(level3_vmemmap_pgt);
26937
26938 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
26939 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
26940 @@ -1751,7 +1754,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26941 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
26942 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
26943 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
26944 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
26945 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
26946 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
26947 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
26948 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
26949 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
26950 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
26951
26952 @@ -1958,6 +1965,7 @@ static void __init xen_post_allocator_init(void)
26953 pv_mmu_ops.set_pud = xen_set_pud;
26954 #if PAGETABLE_LEVELS == 4
26955 pv_mmu_ops.set_pgd = xen_set_pgd;
26956 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
26957 #endif
26958
26959 /* This will work as long as patching hasn't happened yet
26960 @@ -2039,6 +2047,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
26961 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
26962 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
26963 .set_pgd = xen_set_pgd_hyper,
26964 + .set_pgd_batched = xen_set_pgd_hyper,
26965
26966 .alloc_pud = xen_alloc_pmd_init,
26967 .release_pud = xen_release_pmd_init,
26968 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
26969 index f2ce60a..14e08dc 100644
26970 --- a/arch/x86/xen/smp.c
26971 +++ b/arch/x86/xen/smp.c
26972 @@ -209,11 +209,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
26973 {
26974 BUG_ON(smp_processor_id() != 0);
26975 native_smp_prepare_boot_cpu();
26976 -
26977 - /* We've switched to the "real" per-cpu gdt, so make sure the
26978 - old memory can be recycled */
26979 - make_lowmem_page_readwrite(xen_initial_gdt);
26980 -
26981 xen_filter_cpu_maps();
26982 xen_setup_vcpu_info_placement();
26983 }
26984 @@ -290,12 +285,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
26985 gdt = get_cpu_gdt_table(cpu);
26986
26987 ctxt->flags = VGCF_IN_KERNEL;
26988 - ctxt->user_regs.ds = __USER_DS;
26989 - ctxt->user_regs.es = __USER_DS;
26990 + ctxt->user_regs.ds = __KERNEL_DS;
26991 + ctxt->user_regs.es = __KERNEL_DS;
26992 ctxt->user_regs.ss = __KERNEL_DS;
26993 #ifdef CONFIG_X86_32
26994 ctxt->user_regs.fs = __KERNEL_PERCPU;
26995 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
26996 + savesegment(gs, ctxt->user_regs.gs);
26997 #else
26998 ctxt->gs_base_kernel = per_cpu_offset(cpu);
26999 #endif
27000 @@ -346,13 +341,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
27001 int rc;
27002
27003 per_cpu(current_task, cpu) = idle;
27004 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27005 #ifdef CONFIG_X86_32
27006 irq_ctx_init(cpu);
27007 #else
27008 clear_tsk_thread_flag(idle, TIF_FORK);
27009 - per_cpu(kernel_stack, cpu) =
27010 - (unsigned long)task_stack_page(idle) -
27011 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27012 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27013 #endif
27014 xen_setup_runstate_info(cpu);
27015 xen_setup_timer(cpu);
27016 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27017 index b040b0e..8cc4fe0 100644
27018 --- a/arch/x86/xen/xen-asm_32.S
27019 +++ b/arch/x86/xen/xen-asm_32.S
27020 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
27021 ESP_OFFSET=4 # bytes pushed onto stack
27022
27023 /*
27024 - * Store vcpu_info pointer for easy access. Do it this way to
27025 - * avoid having to reload %fs
27026 + * Store vcpu_info pointer for easy access.
27027 */
27028 #ifdef CONFIG_SMP
27029 - GET_THREAD_INFO(%eax)
27030 - movl TI_cpu(%eax), %eax
27031 - movl __per_cpu_offset(,%eax,4), %eax
27032 - mov xen_vcpu(%eax), %eax
27033 + push %fs
27034 + mov $(__KERNEL_PERCPU), %eax
27035 + mov %eax, %fs
27036 + mov PER_CPU_VAR(xen_vcpu), %eax
27037 + pop %fs
27038 #else
27039 movl xen_vcpu, %eax
27040 #endif
27041 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27042 index aaa7291..3f77960 100644
27043 --- a/arch/x86/xen/xen-head.S
27044 +++ b/arch/x86/xen/xen-head.S
27045 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27046 #ifdef CONFIG_X86_32
27047 mov %esi,xen_start_info
27048 mov $init_thread_union+THREAD_SIZE,%esp
27049 +#ifdef CONFIG_SMP
27050 + movl $cpu_gdt_table,%edi
27051 + movl $__per_cpu_load,%eax
27052 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27053 + rorl $16,%eax
27054 + movb %al,__KERNEL_PERCPU + 4(%edi)
27055 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27056 + movl $__per_cpu_end - 1,%eax
27057 + subl $__per_cpu_start,%eax
27058 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27059 +#endif
27060 #else
27061 mov %rsi,xen_start_info
27062 mov $init_thread_union+THREAD_SIZE,%rsp
27063 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27064 index b095739..8c17bcd 100644
27065 --- a/arch/x86/xen/xen-ops.h
27066 +++ b/arch/x86/xen/xen-ops.h
27067 @@ -10,8 +10,6 @@
27068 extern const char xen_hypervisor_callback[];
27069 extern const char xen_failsafe_callback[];
27070
27071 -extern void *xen_initial_gdt;
27072 -
27073 struct trap_info;
27074 void xen_copy_trap_info(struct trap_info *traps);
27075
27076 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27077 index 525bd3d..ef888b1 100644
27078 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27079 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27080 @@ -119,9 +119,9 @@
27081 ----------------------------------------------------------------------*/
27082
27083 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27084 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27085 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27086 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27087 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27088
27089 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27090 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27091 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27092 index 2f33760..835e50a 100644
27093 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27094 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27095 @@ -11,6 +11,7 @@
27096 #ifndef _XTENSA_CORE_H
27097 #define _XTENSA_CORE_H
27098
27099 +#include <linux/const.h>
27100
27101 /****************************************************************************
27102 Parameters Useful for Any Code, USER or PRIVILEGED
27103 @@ -112,9 +113,9 @@
27104 ----------------------------------------------------------------------*/
27105
27106 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27107 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27108 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27109 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27110 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27111
27112 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27113 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27114 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27115 index af00795..2bb8105 100644
27116 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27117 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27118 @@ -11,6 +11,7 @@
27119 #ifndef _XTENSA_CORE_CONFIGURATION_H
27120 #define _XTENSA_CORE_CONFIGURATION_H
27121
27122 +#include <linux/const.h>
27123
27124 /****************************************************************************
27125 Parameters Useful for Any Code, USER or PRIVILEGED
27126 @@ -118,9 +119,9 @@
27127 ----------------------------------------------------------------------*/
27128
27129 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27130 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27131 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27132 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27133 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27134
27135 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27136 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27137 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27138 index 58916af..9cb880b 100644
27139 --- a/block/blk-iopoll.c
27140 +++ b/block/blk-iopoll.c
27141 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27142 }
27143 EXPORT_SYMBOL(blk_iopoll_complete);
27144
27145 -static void blk_iopoll_softirq(struct softirq_action *h)
27146 +static void blk_iopoll_softirq(void)
27147 {
27148 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27149 int rearm = 0, budget = blk_iopoll_budget;
27150 diff --git a/block/blk-map.c b/block/blk-map.c
27151 index 623e1cd..ca1e109 100644
27152 --- a/block/blk-map.c
27153 +++ b/block/blk-map.c
27154 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27155 if (!len || !kbuf)
27156 return -EINVAL;
27157
27158 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27159 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27160 if (do_copy)
27161 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27162 else
27163 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27164 index 1366a89..e17f54b 100644
27165 --- a/block/blk-softirq.c
27166 +++ b/block/blk-softirq.c
27167 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27168 * Softirq action handler - move entries to local list and loop over them
27169 * while passing them to the queue registered handler.
27170 */
27171 -static void blk_done_softirq(struct softirq_action *h)
27172 +static void blk_done_softirq(void)
27173 {
27174 struct list_head *cpu_list, local_list;
27175
27176 diff --git a/block/bsg.c b/block/bsg.c
27177 index ff64ae3..593560c 100644
27178 --- a/block/bsg.c
27179 +++ b/block/bsg.c
27180 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27181 struct sg_io_v4 *hdr, struct bsg_device *bd,
27182 fmode_t has_write_perm)
27183 {
27184 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27185 + unsigned char *cmdptr;
27186 +
27187 if (hdr->request_len > BLK_MAX_CDB) {
27188 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27189 if (!rq->cmd)
27190 return -ENOMEM;
27191 - }
27192 + cmdptr = rq->cmd;
27193 + } else
27194 + cmdptr = tmpcmd;
27195
27196 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27197 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27198 hdr->request_len))
27199 return -EFAULT;
27200
27201 + if (cmdptr != rq->cmd)
27202 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27203 +
27204 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27205 if (blk_verify_command(rq->cmd, has_write_perm))
27206 return -EPERM;
27207 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27208 index 7c668c8..db3521c 100644
27209 --- a/block/compat_ioctl.c
27210 +++ b/block/compat_ioctl.c
27211 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27212 err |= __get_user(f->spec1, &uf->spec1);
27213 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27214 err |= __get_user(name, &uf->name);
27215 - f->name = compat_ptr(name);
27216 + f->name = (void __force_kernel *)compat_ptr(name);
27217 if (err) {
27218 err = -EFAULT;
27219 goto out;
27220 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27221 index 6296b40..417c00f 100644
27222 --- a/block/partitions/efi.c
27223 +++ b/block/partitions/efi.c
27224 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27225 if (!gpt)
27226 return NULL;
27227
27228 + if (!le32_to_cpu(gpt->num_partition_entries))
27229 + return NULL;
27230 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27231 + if (!pte)
27232 + return NULL;
27233 +
27234 count = le32_to_cpu(gpt->num_partition_entries) *
27235 le32_to_cpu(gpt->sizeof_partition_entry);
27236 - if (!count)
27237 - return NULL;
27238 - pte = kzalloc(count, GFP_KERNEL);
27239 - if (!pte)
27240 - return NULL;
27241 -
27242 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27243 (u8 *) pte,
27244 count) < count) {
27245 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27246 index 260fa80..e8f3caf 100644
27247 --- a/block/scsi_ioctl.c
27248 +++ b/block/scsi_ioctl.c
27249 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27250 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27251 struct sg_io_hdr *hdr, fmode_t mode)
27252 {
27253 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27254 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27255 + unsigned char *cmdptr;
27256 +
27257 + if (rq->cmd != rq->__cmd)
27258 + cmdptr = rq->cmd;
27259 + else
27260 + cmdptr = tmpcmd;
27261 +
27262 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27263 return -EFAULT;
27264 +
27265 + if (cmdptr != rq->cmd)
27266 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27267 +
27268 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27269 return -EPERM;
27270
27271 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27272 int err;
27273 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27274 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27275 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27276 + unsigned char *cmdptr;
27277
27278 if (!sic)
27279 return -EINVAL;
27280 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27281 */
27282 err = -EFAULT;
27283 rq->cmd_len = cmdlen;
27284 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27285 +
27286 + if (rq->cmd != rq->__cmd)
27287 + cmdptr = rq->cmd;
27288 + else
27289 + cmdptr = tmpcmd;
27290 +
27291 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27292 goto error;
27293
27294 + if (rq->cmd != cmdptr)
27295 + memcpy(rq->cmd, cmdptr, cmdlen);
27296 +
27297 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27298 goto error;
27299
27300 diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
27301 index a0f768c..1da9c73 100644
27302 --- a/crypto/ablkcipher.c
27303 +++ b/crypto/ablkcipher.c
27304 @@ -307,6 +307,8 @@ int ablkcipher_walk_phys(struct ablkcipher_request *req,
27305 EXPORT_SYMBOL_GPL(ablkcipher_walk_phys);
27306
27307 static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27308 + unsigned int keylen) __size_overflow(3);
27309 +static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27310 unsigned int keylen)
27311 {
27312 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
27313 @@ -329,6 +331,8 @@ static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27314 }
27315
27316 static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
27317 + unsigned int keylen) __size_overflow(3);
27318 +static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
27319 unsigned int keylen)
27320 {
27321 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
27322 diff --git a/crypto/aead.c b/crypto/aead.c
27323 index 04add3dc..983032f 100644
27324 --- a/crypto/aead.c
27325 +++ b/crypto/aead.c
27326 @@ -27,6 +27,8 @@
27327 #include "internal.h"
27328
27329 static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27330 + unsigned int keylen) __size_overflow(3);
27331 +static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27332 unsigned int keylen)
27333 {
27334 struct aead_alg *aead = crypto_aead_alg(tfm);
27335 @@ -48,6 +50,7 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27336 return ret;
27337 }
27338
27339 +static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27340 static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen)
27341 {
27342 struct aead_alg *aead = crypto_aead_alg(tfm);
27343 diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
27344 index 1e61d1a..cf06b86 100644
27345 --- a/crypto/blkcipher.c
27346 +++ b/crypto/blkcipher.c
27347 @@ -359,6 +359,8 @@ int blkcipher_walk_virt_block(struct blkcipher_desc *desc,
27348 EXPORT_SYMBOL_GPL(blkcipher_walk_virt_block);
27349
27350 static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27351 + unsigned int keylen) __size_overflow(3);
27352 +static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27353 unsigned int keylen)
27354 {
27355 struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
27356 @@ -380,6 +382,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27357 return ret;
27358 }
27359
27360 +static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27361 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
27362 {
27363 struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
27364 diff --git a/crypto/cipher.c b/crypto/cipher.c
27365 index 39541e0..802d956 100644
27366 --- a/crypto/cipher.c
27367 +++ b/crypto/cipher.c
27368 @@ -21,6 +21,8 @@
27369 #include "internal.h"
27370
27371 static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27372 + unsigned int keylen) __size_overflow(3);
27373 +static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27374 unsigned int keylen)
27375 {
27376 struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
27377 @@ -43,6 +45,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27378
27379 }
27380
27381 +static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27382 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
27383 {
27384 struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
27385 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27386 index 671d4d6..5f24030 100644
27387 --- a/crypto/cryptd.c
27388 +++ b/crypto/cryptd.c
27389 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27390
27391 struct cryptd_blkcipher_request_ctx {
27392 crypto_completion_t complete;
27393 -};
27394 +} __no_const;
27395
27396 struct cryptd_hash_ctx {
27397 struct crypto_shash *child;
27398 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27399
27400 struct cryptd_aead_request_ctx {
27401 crypto_completion_t complete;
27402 -};
27403 +} __no_const;
27404
27405 static void cryptd_queue_worker(struct work_struct *work);
27406
27407 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27408 index 5d41894..22021e4 100644
27409 --- a/drivers/acpi/apei/cper.c
27410 +++ b/drivers/acpi/apei/cper.c
27411 @@ -38,12 +38,12 @@
27412 */
27413 u64 cper_next_record_id(void)
27414 {
27415 - static atomic64_t seq;
27416 + static atomic64_unchecked_t seq;
27417
27418 - if (!atomic64_read(&seq))
27419 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27420 + if (!atomic64_read_unchecked(&seq))
27421 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27422
27423 - return atomic64_inc_return(&seq);
27424 + return atomic64_inc_return_unchecked(&seq);
27425 }
27426 EXPORT_SYMBOL_GPL(cper_next_record_id);
27427
27428 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
27429 index 86933ca..5cb1a69 100644
27430 --- a/drivers/acpi/battery.c
27431 +++ b/drivers/acpi/battery.c
27432 @@ -787,6 +787,9 @@ static int acpi_battery_print_alarm(struct seq_file *seq, int result)
27433
27434 static ssize_t acpi_battery_write_alarm(struct file *file,
27435 const char __user * buffer,
27436 + size_t count, loff_t * ppos) __size_overflow(3);
27437 +static ssize_t acpi_battery_write_alarm(struct file *file,
27438 + const char __user * buffer,
27439 size_t count, loff_t * ppos)
27440 {
27441 int result = 0;
27442 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27443 index b258cab..3fb7da7 100644
27444 --- a/drivers/acpi/ec_sys.c
27445 +++ b/drivers/acpi/ec_sys.c
27446 @@ -12,6 +12,7 @@
27447 #include <linux/acpi.h>
27448 #include <linux/debugfs.h>
27449 #include <linux/module.h>
27450 +#include <linux/uaccess.h>
27451 #include "internal.h"
27452
27453 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27454 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27455 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27456 */
27457 unsigned int size = EC_SPACE_SIZE;
27458 - u8 *data = (u8 *) buf;
27459 + u8 data;
27460 loff_t init_off = *off;
27461 int err = 0;
27462
27463 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27464 size = count;
27465
27466 while (size) {
27467 - err = ec_read(*off, &data[*off - init_off]);
27468 + err = ec_read(*off, &data);
27469 if (err)
27470 return err;
27471 + if (put_user(data, &buf[*off - init_off]))
27472 + return -EFAULT;
27473 *off += 1;
27474 size--;
27475 }
27476 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27477
27478 unsigned int size = count;
27479 loff_t init_off = *off;
27480 - u8 *data = (u8 *) buf;
27481 int err = 0;
27482
27483 if (*off >= EC_SPACE_SIZE)
27484 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27485 }
27486
27487 while (size) {
27488 - u8 byte_write = data[*off - init_off];
27489 + u8 byte_write;
27490 + if (get_user(byte_write, &buf[*off - init_off]))
27491 + return -EFAULT;
27492 err = ec_write(*off, byte_write);
27493 if (err)
27494 return err;
27495 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27496 index 251c7b62..000462d 100644
27497 --- a/drivers/acpi/proc.c
27498 +++ b/drivers/acpi/proc.c
27499 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27500 size_t count, loff_t * ppos)
27501 {
27502 struct list_head *node, *next;
27503 - char strbuf[5];
27504 - char str[5] = "";
27505 - unsigned int len = count;
27506 + char strbuf[5] = {0};
27507
27508 - if (len > 4)
27509 - len = 4;
27510 - if (len < 0)
27511 + if (count > 4)
27512 + count = 4;
27513 + if (copy_from_user(strbuf, buffer, count))
27514 return -EFAULT;
27515 -
27516 - if (copy_from_user(strbuf, buffer, len))
27517 - return -EFAULT;
27518 - strbuf[len] = '\0';
27519 - sscanf(strbuf, "%s", str);
27520 + strbuf[count] = '\0';
27521
27522 mutex_lock(&acpi_device_lock);
27523 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27524 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27525 if (!dev->wakeup.flags.valid)
27526 continue;
27527
27528 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27529 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27530 if (device_can_wakeup(&dev->dev)) {
27531 bool enable = !device_may_wakeup(&dev->dev);
27532 device_set_wakeup_enable(&dev->dev, enable);
27533 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27534 index 8ae05ce..7dbbed9 100644
27535 --- a/drivers/acpi/processor_driver.c
27536 +++ b/drivers/acpi/processor_driver.c
27537 @@ -555,7 +555,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27538 return 0;
27539 #endif
27540
27541 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27542 + BUG_ON(pr->id >= nr_cpu_ids);
27543
27544 /*
27545 * Buggy BIOS check
27546 diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
27547 index 6e36d0c..f319944 100644
27548 --- a/drivers/acpi/sbs.c
27549 +++ b/drivers/acpi/sbs.c
27550 @@ -655,6 +655,9 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
27551
27552 static ssize_t
27553 acpi_battery_write_alarm(struct file *file, const char __user * buffer,
27554 + size_t count, loff_t * ppos) __size_overflow(3);
27555 +static ssize_t
27556 +acpi_battery_write_alarm(struct file *file, const char __user * buffer,
27557 size_t count, loff_t * ppos)
27558 {
27559 struct seq_file *seq = file->private_data;
27560 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27561 index c06e0ec..a2c06ba 100644
27562 --- a/drivers/ata/libata-core.c
27563 +++ b/drivers/ata/libata-core.c
27564 @@ -4736,7 +4736,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27565 struct ata_port *ap;
27566 unsigned int tag;
27567
27568 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27569 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27570 ap = qc->ap;
27571
27572 qc->flags = 0;
27573 @@ -4752,7 +4752,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27574 struct ata_port *ap;
27575 struct ata_link *link;
27576
27577 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27578 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27579 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27580 ap = qc->ap;
27581 link = qc->dev->link;
27582 @@ -5816,6 +5816,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27583 return;
27584
27585 spin_lock(&lock);
27586 + pax_open_kernel();
27587
27588 for (cur = ops->inherits; cur; cur = cur->inherits) {
27589 void **inherit = (void **)cur;
27590 @@ -5829,8 +5830,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27591 if (IS_ERR(*pp))
27592 *pp = NULL;
27593
27594 - ops->inherits = NULL;
27595 + *(struct ata_port_operations **)&ops->inherits = NULL;
27596
27597 + pax_close_kernel();
27598 spin_unlock(&lock);
27599 }
27600
27601 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27602 index 048589f..4002b98 100644
27603 --- a/drivers/ata/pata_arasan_cf.c
27604 +++ b/drivers/ata/pata_arasan_cf.c
27605 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27606 /* Handle platform specific quirks */
27607 if (pdata->quirk) {
27608 if (pdata->quirk & CF_BROKEN_PIO) {
27609 - ap->ops->set_piomode = NULL;
27610 + pax_open_kernel();
27611 + *(void **)&ap->ops->set_piomode = NULL;
27612 + pax_close_kernel();
27613 ap->pio_mask = 0;
27614 }
27615 if (pdata->quirk & CF_BROKEN_MWDMA)
27616 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27617 index f9b983a..887b9d8 100644
27618 --- a/drivers/atm/adummy.c
27619 +++ b/drivers/atm/adummy.c
27620 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27621 vcc->pop(vcc, skb);
27622 else
27623 dev_kfree_skb_any(skb);
27624 - atomic_inc(&vcc->stats->tx);
27625 + atomic_inc_unchecked(&vcc->stats->tx);
27626
27627 return 0;
27628 }
27629 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27630 index f8f41e0..1f987dd 100644
27631 --- a/drivers/atm/ambassador.c
27632 +++ b/drivers/atm/ambassador.c
27633 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27634 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27635
27636 // VC layer stats
27637 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27638 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27639
27640 // free the descriptor
27641 kfree (tx_descr);
27642 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27643 dump_skb ("<<<", vc, skb);
27644
27645 // VC layer stats
27646 - atomic_inc(&atm_vcc->stats->rx);
27647 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27648 __net_timestamp(skb);
27649 // end of our responsibility
27650 atm_vcc->push (atm_vcc, skb);
27651 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27652 } else {
27653 PRINTK (KERN_INFO, "dropped over-size frame");
27654 // should we count this?
27655 - atomic_inc(&atm_vcc->stats->rx_drop);
27656 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27657 }
27658
27659 } else {
27660 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27661 }
27662
27663 if (check_area (skb->data, skb->len)) {
27664 - atomic_inc(&atm_vcc->stats->tx_err);
27665 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27666 return -ENOMEM; // ?
27667 }
27668
27669 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27670 index b22d71c..d6e1049 100644
27671 --- a/drivers/atm/atmtcp.c
27672 +++ b/drivers/atm/atmtcp.c
27673 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27674 if (vcc->pop) vcc->pop(vcc,skb);
27675 else dev_kfree_skb(skb);
27676 if (dev_data) return 0;
27677 - atomic_inc(&vcc->stats->tx_err);
27678 + atomic_inc_unchecked(&vcc->stats->tx_err);
27679 return -ENOLINK;
27680 }
27681 size = skb->len+sizeof(struct atmtcp_hdr);
27682 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27683 if (!new_skb) {
27684 if (vcc->pop) vcc->pop(vcc,skb);
27685 else dev_kfree_skb(skb);
27686 - atomic_inc(&vcc->stats->tx_err);
27687 + atomic_inc_unchecked(&vcc->stats->tx_err);
27688 return -ENOBUFS;
27689 }
27690 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27691 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27692 if (vcc->pop) vcc->pop(vcc,skb);
27693 else dev_kfree_skb(skb);
27694 out_vcc->push(out_vcc,new_skb);
27695 - atomic_inc(&vcc->stats->tx);
27696 - atomic_inc(&out_vcc->stats->rx);
27697 + atomic_inc_unchecked(&vcc->stats->tx);
27698 + atomic_inc_unchecked(&out_vcc->stats->rx);
27699 return 0;
27700 }
27701
27702 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27703 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27704 read_unlock(&vcc_sklist_lock);
27705 if (!out_vcc) {
27706 - atomic_inc(&vcc->stats->tx_err);
27707 + atomic_inc_unchecked(&vcc->stats->tx_err);
27708 goto done;
27709 }
27710 skb_pull(skb,sizeof(struct atmtcp_hdr));
27711 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27712 __net_timestamp(new_skb);
27713 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27714 out_vcc->push(out_vcc,new_skb);
27715 - atomic_inc(&vcc->stats->tx);
27716 - atomic_inc(&out_vcc->stats->rx);
27717 + atomic_inc_unchecked(&vcc->stats->tx);
27718 + atomic_inc_unchecked(&out_vcc->stats->rx);
27719 done:
27720 if (vcc->pop) vcc->pop(vcc,skb);
27721 else dev_kfree_skb(skb);
27722 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27723 index 956e9ac..133516d 100644
27724 --- a/drivers/atm/eni.c
27725 +++ b/drivers/atm/eni.c
27726 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27727 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27728 vcc->dev->number);
27729 length = 0;
27730 - atomic_inc(&vcc->stats->rx_err);
27731 + atomic_inc_unchecked(&vcc->stats->rx_err);
27732 }
27733 else {
27734 length = ATM_CELL_SIZE-1; /* no HEC */
27735 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27736 size);
27737 }
27738 eff = length = 0;
27739 - atomic_inc(&vcc->stats->rx_err);
27740 + atomic_inc_unchecked(&vcc->stats->rx_err);
27741 }
27742 else {
27743 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27744 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27745 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27746 vcc->dev->number,vcc->vci,length,size << 2,descr);
27747 length = eff = 0;
27748 - atomic_inc(&vcc->stats->rx_err);
27749 + atomic_inc_unchecked(&vcc->stats->rx_err);
27750 }
27751 }
27752 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27753 @@ -771,7 +771,7 @@ rx_dequeued++;
27754 vcc->push(vcc,skb);
27755 pushed++;
27756 }
27757 - atomic_inc(&vcc->stats->rx);
27758 + atomic_inc_unchecked(&vcc->stats->rx);
27759 }
27760 wake_up(&eni_dev->rx_wait);
27761 }
27762 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
27763 PCI_DMA_TODEVICE);
27764 if (vcc->pop) vcc->pop(vcc,skb);
27765 else dev_kfree_skb_irq(skb);
27766 - atomic_inc(&vcc->stats->tx);
27767 + atomic_inc_unchecked(&vcc->stats->tx);
27768 wake_up(&eni_dev->tx_wait);
27769 dma_complete++;
27770 }
27771 @@ -1569,7 +1569,7 @@ tx_complete++;
27772 /*--------------------------------- entries ---------------------------------*/
27773
27774
27775 -static const char *media_name[] __devinitdata = {
27776 +static const char *media_name[] __devinitconst = {
27777 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27778 "UTP", "05?", "06?", "07?", /* 4- 7 */
27779 "TAXI","09?", "10?", "11?", /* 8-11 */
27780 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27781 index 5072f8a..fa52520d 100644
27782 --- a/drivers/atm/firestream.c
27783 +++ b/drivers/atm/firestream.c
27784 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27785 }
27786 }
27787
27788 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27789 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27790
27791 fs_dprintk (FS_DEBUG_TXMEM, "i");
27792 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27793 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27794 #endif
27795 skb_put (skb, qe->p1 & 0xffff);
27796 ATM_SKB(skb)->vcc = atm_vcc;
27797 - atomic_inc(&atm_vcc->stats->rx);
27798 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27799 __net_timestamp(skb);
27800 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27801 atm_vcc->push (atm_vcc, skb);
27802 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27803 kfree (pe);
27804 }
27805 if (atm_vcc)
27806 - atomic_inc(&atm_vcc->stats->rx_drop);
27807 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27808 break;
27809 case 0x1f: /* Reassembly abort: no buffers. */
27810 /* Silently increment error counter. */
27811 if (atm_vcc)
27812 - atomic_inc(&atm_vcc->stats->rx_drop);
27813 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27814 break;
27815 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27816 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27817 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27818 index 361f5ae..7fc552d 100644
27819 --- a/drivers/atm/fore200e.c
27820 +++ b/drivers/atm/fore200e.c
27821 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27822 #endif
27823 /* check error condition */
27824 if (*entry->status & STATUS_ERROR)
27825 - atomic_inc(&vcc->stats->tx_err);
27826 + atomic_inc_unchecked(&vcc->stats->tx_err);
27827 else
27828 - atomic_inc(&vcc->stats->tx);
27829 + atomic_inc_unchecked(&vcc->stats->tx);
27830 }
27831 }
27832
27833 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27834 if (skb == NULL) {
27835 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27836
27837 - atomic_inc(&vcc->stats->rx_drop);
27838 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27839 return -ENOMEM;
27840 }
27841
27842 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27843
27844 dev_kfree_skb_any(skb);
27845
27846 - atomic_inc(&vcc->stats->rx_drop);
27847 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27848 return -ENOMEM;
27849 }
27850
27851 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27852
27853 vcc->push(vcc, skb);
27854 - atomic_inc(&vcc->stats->rx);
27855 + atomic_inc_unchecked(&vcc->stats->rx);
27856
27857 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27858
27859 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27860 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27861 fore200e->atm_dev->number,
27862 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27863 - atomic_inc(&vcc->stats->rx_err);
27864 + atomic_inc_unchecked(&vcc->stats->rx_err);
27865 }
27866 }
27867
27868 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27869 goto retry_here;
27870 }
27871
27872 - atomic_inc(&vcc->stats->tx_err);
27873 + atomic_inc_unchecked(&vcc->stats->tx_err);
27874
27875 fore200e->tx_sat++;
27876 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27877 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27878 index b182c2f..1c6fa8a 100644
27879 --- a/drivers/atm/he.c
27880 +++ b/drivers/atm/he.c
27881 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27882
27883 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27884 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27885 - atomic_inc(&vcc->stats->rx_drop);
27886 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27887 goto return_host_buffers;
27888 }
27889
27890 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27891 RBRQ_LEN_ERR(he_dev->rbrq_head)
27892 ? "LEN_ERR" : "",
27893 vcc->vpi, vcc->vci);
27894 - atomic_inc(&vcc->stats->rx_err);
27895 + atomic_inc_unchecked(&vcc->stats->rx_err);
27896 goto return_host_buffers;
27897 }
27898
27899 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27900 vcc->push(vcc, skb);
27901 spin_lock(&he_dev->global_lock);
27902
27903 - atomic_inc(&vcc->stats->rx);
27904 + atomic_inc_unchecked(&vcc->stats->rx);
27905
27906 return_host_buffers:
27907 ++pdus_assembled;
27908 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27909 tpd->vcc->pop(tpd->vcc, tpd->skb);
27910 else
27911 dev_kfree_skb_any(tpd->skb);
27912 - atomic_inc(&tpd->vcc->stats->tx_err);
27913 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27914 }
27915 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27916 return;
27917 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27918 vcc->pop(vcc, skb);
27919 else
27920 dev_kfree_skb_any(skb);
27921 - atomic_inc(&vcc->stats->tx_err);
27922 + atomic_inc_unchecked(&vcc->stats->tx_err);
27923 return -EINVAL;
27924 }
27925
27926 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27927 vcc->pop(vcc, skb);
27928 else
27929 dev_kfree_skb_any(skb);
27930 - atomic_inc(&vcc->stats->tx_err);
27931 + atomic_inc_unchecked(&vcc->stats->tx_err);
27932 return -EINVAL;
27933 }
27934 #endif
27935 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27936 vcc->pop(vcc, skb);
27937 else
27938 dev_kfree_skb_any(skb);
27939 - atomic_inc(&vcc->stats->tx_err);
27940 + atomic_inc_unchecked(&vcc->stats->tx_err);
27941 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27942 return -ENOMEM;
27943 }
27944 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27945 vcc->pop(vcc, skb);
27946 else
27947 dev_kfree_skb_any(skb);
27948 - atomic_inc(&vcc->stats->tx_err);
27949 + atomic_inc_unchecked(&vcc->stats->tx_err);
27950 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27951 return -ENOMEM;
27952 }
27953 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27954 __enqueue_tpd(he_dev, tpd, cid);
27955 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27956
27957 - atomic_inc(&vcc->stats->tx);
27958 + atomic_inc_unchecked(&vcc->stats->tx);
27959
27960 return 0;
27961 }
27962 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
27963 index b812103..e391a49 100644
27964 --- a/drivers/atm/horizon.c
27965 +++ b/drivers/atm/horizon.c
27966 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
27967 {
27968 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
27969 // VC layer stats
27970 - atomic_inc(&vcc->stats->rx);
27971 + atomic_inc_unchecked(&vcc->stats->rx);
27972 __net_timestamp(skb);
27973 // end of our responsibility
27974 vcc->push (vcc, skb);
27975 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
27976 dev->tx_iovec = NULL;
27977
27978 // VC layer stats
27979 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27980 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27981
27982 // free the skb
27983 hrz_kfree_skb (skb);
27984 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
27985 index 1c05212..c28e200 100644
27986 --- a/drivers/atm/idt77252.c
27987 +++ b/drivers/atm/idt77252.c
27988 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
27989 else
27990 dev_kfree_skb(skb);
27991
27992 - atomic_inc(&vcc->stats->tx);
27993 + atomic_inc_unchecked(&vcc->stats->tx);
27994 }
27995
27996 atomic_dec(&scq->used);
27997 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27998 if ((sb = dev_alloc_skb(64)) == NULL) {
27999 printk("%s: Can't allocate buffers for aal0.\n",
28000 card->name);
28001 - atomic_add(i, &vcc->stats->rx_drop);
28002 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28003 break;
28004 }
28005 if (!atm_charge(vcc, sb->truesize)) {
28006 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28007 card->name);
28008 - atomic_add(i - 1, &vcc->stats->rx_drop);
28009 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28010 dev_kfree_skb(sb);
28011 break;
28012 }
28013 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28014 ATM_SKB(sb)->vcc = vcc;
28015 __net_timestamp(sb);
28016 vcc->push(vcc, sb);
28017 - atomic_inc(&vcc->stats->rx);
28018 + atomic_inc_unchecked(&vcc->stats->rx);
28019
28020 cell += ATM_CELL_PAYLOAD;
28021 }
28022 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28023 "(CDC: %08x)\n",
28024 card->name, len, rpp->len, readl(SAR_REG_CDC));
28025 recycle_rx_pool_skb(card, rpp);
28026 - atomic_inc(&vcc->stats->rx_err);
28027 + atomic_inc_unchecked(&vcc->stats->rx_err);
28028 return;
28029 }
28030 if (stat & SAR_RSQE_CRC) {
28031 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28032 recycle_rx_pool_skb(card, rpp);
28033 - atomic_inc(&vcc->stats->rx_err);
28034 + atomic_inc_unchecked(&vcc->stats->rx_err);
28035 return;
28036 }
28037 if (skb_queue_len(&rpp->queue) > 1) {
28038 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28039 RXPRINTK("%s: Can't alloc RX skb.\n",
28040 card->name);
28041 recycle_rx_pool_skb(card, rpp);
28042 - atomic_inc(&vcc->stats->rx_err);
28043 + atomic_inc_unchecked(&vcc->stats->rx_err);
28044 return;
28045 }
28046 if (!atm_charge(vcc, skb->truesize)) {
28047 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28048 __net_timestamp(skb);
28049
28050 vcc->push(vcc, skb);
28051 - atomic_inc(&vcc->stats->rx);
28052 + atomic_inc_unchecked(&vcc->stats->rx);
28053
28054 return;
28055 }
28056 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28057 __net_timestamp(skb);
28058
28059 vcc->push(vcc, skb);
28060 - atomic_inc(&vcc->stats->rx);
28061 + atomic_inc_unchecked(&vcc->stats->rx);
28062
28063 if (skb->truesize > SAR_FB_SIZE_3)
28064 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28065 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28066 if (vcc->qos.aal != ATM_AAL0) {
28067 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28068 card->name, vpi, vci);
28069 - atomic_inc(&vcc->stats->rx_drop);
28070 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28071 goto drop;
28072 }
28073
28074 if ((sb = dev_alloc_skb(64)) == NULL) {
28075 printk("%s: Can't allocate buffers for AAL0.\n",
28076 card->name);
28077 - atomic_inc(&vcc->stats->rx_err);
28078 + atomic_inc_unchecked(&vcc->stats->rx_err);
28079 goto drop;
28080 }
28081
28082 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28083 ATM_SKB(sb)->vcc = vcc;
28084 __net_timestamp(sb);
28085 vcc->push(vcc, sb);
28086 - atomic_inc(&vcc->stats->rx);
28087 + atomic_inc_unchecked(&vcc->stats->rx);
28088
28089 drop:
28090 skb_pull(queue, 64);
28091 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28092
28093 if (vc == NULL) {
28094 printk("%s: NULL connection in send().\n", card->name);
28095 - atomic_inc(&vcc->stats->tx_err);
28096 + atomic_inc_unchecked(&vcc->stats->tx_err);
28097 dev_kfree_skb(skb);
28098 return -EINVAL;
28099 }
28100 if (!test_bit(VCF_TX, &vc->flags)) {
28101 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28102 - atomic_inc(&vcc->stats->tx_err);
28103 + atomic_inc_unchecked(&vcc->stats->tx_err);
28104 dev_kfree_skb(skb);
28105 return -EINVAL;
28106 }
28107 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28108 break;
28109 default:
28110 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28111 - atomic_inc(&vcc->stats->tx_err);
28112 + atomic_inc_unchecked(&vcc->stats->tx_err);
28113 dev_kfree_skb(skb);
28114 return -EINVAL;
28115 }
28116
28117 if (skb_shinfo(skb)->nr_frags != 0) {
28118 printk("%s: No scatter-gather yet.\n", card->name);
28119 - atomic_inc(&vcc->stats->tx_err);
28120 + atomic_inc_unchecked(&vcc->stats->tx_err);
28121 dev_kfree_skb(skb);
28122 return -EINVAL;
28123 }
28124 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28125
28126 err = queue_skb(card, vc, skb, oam);
28127 if (err) {
28128 - atomic_inc(&vcc->stats->tx_err);
28129 + atomic_inc_unchecked(&vcc->stats->tx_err);
28130 dev_kfree_skb(skb);
28131 return err;
28132 }
28133 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28134 skb = dev_alloc_skb(64);
28135 if (!skb) {
28136 printk("%s: Out of memory in send_oam().\n", card->name);
28137 - atomic_inc(&vcc->stats->tx_err);
28138 + atomic_inc_unchecked(&vcc->stats->tx_err);
28139 return -ENOMEM;
28140 }
28141 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28142 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28143 index 9e373ba..cf93727 100644
28144 --- a/drivers/atm/iphase.c
28145 +++ b/drivers/atm/iphase.c
28146 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
28147 status = (u_short) (buf_desc_ptr->desc_mode);
28148 if (status & (RX_CER | RX_PTE | RX_OFL))
28149 {
28150 - atomic_inc(&vcc->stats->rx_err);
28151 + atomic_inc_unchecked(&vcc->stats->rx_err);
28152 IF_ERR(printk("IA: bad packet, dropping it");)
28153 if (status & RX_CER) {
28154 IF_ERR(printk(" cause: packet CRC error\n");)
28155 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
28156 len = dma_addr - buf_addr;
28157 if (len > iadev->rx_buf_sz) {
28158 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28159 - atomic_inc(&vcc->stats->rx_err);
28160 + atomic_inc_unchecked(&vcc->stats->rx_err);
28161 goto out_free_desc;
28162 }
28163
28164 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28165 ia_vcc = INPH_IA_VCC(vcc);
28166 if (ia_vcc == NULL)
28167 {
28168 - atomic_inc(&vcc->stats->rx_err);
28169 + atomic_inc_unchecked(&vcc->stats->rx_err);
28170 atm_return(vcc, skb->truesize);
28171 dev_kfree_skb_any(skb);
28172 goto INCR_DLE;
28173 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28174 if ((length > iadev->rx_buf_sz) || (length >
28175 (skb->len - sizeof(struct cpcs_trailer))))
28176 {
28177 - atomic_inc(&vcc->stats->rx_err);
28178 + atomic_inc_unchecked(&vcc->stats->rx_err);
28179 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28180 length, skb->len);)
28181 atm_return(vcc, skb->truesize);
28182 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28183
28184 IF_RX(printk("rx_dle_intr: skb push");)
28185 vcc->push(vcc,skb);
28186 - atomic_inc(&vcc->stats->rx);
28187 + atomic_inc_unchecked(&vcc->stats->rx);
28188 iadev->rx_pkt_cnt++;
28189 }
28190 INCR_DLE:
28191 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28192 {
28193 struct k_sonet_stats *stats;
28194 stats = &PRIV(_ia_dev[board])->sonet_stats;
28195 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28196 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28197 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28198 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28199 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28200 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28201 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28202 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28203 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28204 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28205 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28206 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28207 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28208 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28209 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28210 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28211 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28212 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28213 }
28214 ia_cmds.status = 0;
28215 break;
28216 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28217 if ((desc == 0) || (desc > iadev->num_tx_desc))
28218 {
28219 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28220 - atomic_inc(&vcc->stats->tx);
28221 + atomic_inc_unchecked(&vcc->stats->tx);
28222 if (vcc->pop)
28223 vcc->pop(vcc, skb);
28224 else
28225 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28226 ATM_DESC(skb) = vcc->vci;
28227 skb_queue_tail(&iadev->tx_dma_q, skb);
28228
28229 - atomic_inc(&vcc->stats->tx);
28230 + atomic_inc_unchecked(&vcc->stats->tx);
28231 iadev->tx_pkt_cnt++;
28232 /* Increment transaction counter */
28233 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28234
28235 #if 0
28236 /* add flow control logic */
28237 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28238 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28239 if (iavcc->vc_desc_cnt > 10) {
28240 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28241 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28242 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28243 index f556969..0da15eb 100644
28244 --- a/drivers/atm/lanai.c
28245 +++ b/drivers/atm/lanai.c
28246 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28247 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28248 lanai_endtx(lanai, lvcc);
28249 lanai_free_skb(lvcc->tx.atmvcc, skb);
28250 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28251 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28252 }
28253
28254 /* Try to fill the buffer - don't call unless there is backlog */
28255 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28256 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28257 __net_timestamp(skb);
28258 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28259 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28260 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28261 out:
28262 lvcc->rx.buf.ptr = end;
28263 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28264 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28265 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28266 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28267 lanai->stats.service_rxnotaal5++;
28268 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28269 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28270 return 0;
28271 }
28272 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28273 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28274 int bytes;
28275 read_unlock(&vcc_sklist_lock);
28276 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28277 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28278 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28279 lvcc->stats.x.aal5.service_trash++;
28280 bytes = (SERVICE_GET_END(s) * 16) -
28281 (((unsigned long) lvcc->rx.buf.ptr) -
28282 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28283 }
28284 if (s & SERVICE_STREAM) {
28285 read_unlock(&vcc_sklist_lock);
28286 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28287 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28288 lvcc->stats.x.aal5.service_stream++;
28289 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28290 "PDU on VCI %d!\n", lanai->number, vci);
28291 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28292 return 0;
28293 }
28294 DPRINTK("got rx crc error on vci %d\n", vci);
28295 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28296 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28297 lvcc->stats.x.aal5.service_rxcrc++;
28298 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28299 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28300 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28301 index 1c70c45..300718d 100644
28302 --- a/drivers/atm/nicstar.c
28303 +++ b/drivers/atm/nicstar.c
28304 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28305 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28306 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28307 card->index);
28308 - atomic_inc(&vcc->stats->tx_err);
28309 + atomic_inc_unchecked(&vcc->stats->tx_err);
28310 dev_kfree_skb_any(skb);
28311 return -EINVAL;
28312 }
28313 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28314 if (!vc->tx) {
28315 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28316 card->index);
28317 - atomic_inc(&vcc->stats->tx_err);
28318 + atomic_inc_unchecked(&vcc->stats->tx_err);
28319 dev_kfree_skb_any(skb);
28320 return -EINVAL;
28321 }
28322 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28323 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28324 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28325 card->index);
28326 - atomic_inc(&vcc->stats->tx_err);
28327 + atomic_inc_unchecked(&vcc->stats->tx_err);
28328 dev_kfree_skb_any(skb);
28329 return -EINVAL;
28330 }
28331
28332 if (skb_shinfo(skb)->nr_frags != 0) {
28333 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28334 - atomic_inc(&vcc->stats->tx_err);
28335 + atomic_inc_unchecked(&vcc->stats->tx_err);
28336 dev_kfree_skb_any(skb);
28337 return -EINVAL;
28338 }
28339 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28340 }
28341
28342 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28343 - atomic_inc(&vcc->stats->tx_err);
28344 + atomic_inc_unchecked(&vcc->stats->tx_err);
28345 dev_kfree_skb_any(skb);
28346 return -EIO;
28347 }
28348 - atomic_inc(&vcc->stats->tx);
28349 + atomic_inc_unchecked(&vcc->stats->tx);
28350
28351 return 0;
28352 }
28353 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28354 printk
28355 ("nicstar%d: Can't allocate buffers for aal0.\n",
28356 card->index);
28357 - atomic_add(i, &vcc->stats->rx_drop);
28358 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28359 break;
28360 }
28361 if (!atm_charge(vcc, sb->truesize)) {
28362 RXPRINTK
28363 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28364 card->index);
28365 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28366 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28367 dev_kfree_skb_any(sb);
28368 break;
28369 }
28370 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28371 ATM_SKB(sb)->vcc = vcc;
28372 __net_timestamp(sb);
28373 vcc->push(vcc, sb);
28374 - atomic_inc(&vcc->stats->rx);
28375 + atomic_inc_unchecked(&vcc->stats->rx);
28376 cell += ATM_CELL_PAYLOAD;
28377 }
28378
28379 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28380 if (iovb == NULL) {
28381 printk("nicstar%d: Out of iovec buffers.\n",
28382 card->index);
28383 - atomic_inc(&vcc->stats->rx_drop);
28384 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28385 recycle_rx_buf(card, skb);
28386 return;
28387 }
28388 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28389 small or large buffer itself. */
28390 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28391 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28392 - atomic_inc(&vcc->stats->rx_err);
28393 + atomic_inc_unchecked(&vcc->stats->rx_err);
28394 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28395 NS_MAX_IOVECS);
28396 NS_PRV_IOVCNT(iovb) = 0;
28397 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28398 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28399 card->index);
28400 which_list(card, skb);
28401 - atomic_inc(&vcc->stats->rx_err);
28402 + atomic_inc_unchecked(&vcc->stats->rx_err);
28403 recycle_rx_buf(card, skb);
28404 vc->rx_iov = NULL;
28405 recycle_iov_buf(card, iovb);
28406 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28407 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28408 card->index);
28409 which_list(card, skb);
28410 - atomic_inc(&vcc->stats->rx_err);
28411 + atomic_inc_unchecked(&vcc->stats->rx_err);
28412 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28413 NS_PRV_IOVCNT(iovb));
28414 vc->rx_iov = NULL;
28415 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28416 printk(" - PDU size mismatch.\n");
28417 else
28418 printk(".\n");
28419 - atomic_inc(&vcc->stats->rx_err);
28420 + atomic_inc_unchecked(&vcc->stats->rx_err);
28421 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28422 NS_PRV_IOVCNT(iovb));
28423 vc->rx_iov = NULL;
28424 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28425 /* skb points to a small buffer */
28426 if (!atm_charge(vcc, skb->truesize)) {
28427 push_rxbufs(card, skb);
28428 - atomic_inc(&vcc->stats->rx_drop);
28429 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28430 } else {
28431 skb_put(skb, len);
28432 dequeue_sm_buf(card, skb);
28433 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28434 ATM_SKB(skb)->vcc = vcc;
28435 __net_timestamp(skb);
28436 vcc->push(vcc, skb);
28437 - atomic_inc(&vcc->stats->rx);
28438 + atomic_inc_unchecked(&vcc->stats->rx);
28439 }
28440 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28441 struct sk_buff *sb;
28442 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28443 if (len <= NS_SMBUFSIZE) {
28444 if (!atm_charge(vcc, sb->truesize)) {
28445 push_rxbufs(card, sb);
28446 - atomic_inc(&vcc->stats->rx_drop);
28447 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28448 } else {
28449 skb_put(sb, len);
28450 dequeue_sm_buf(card, sb);
28451 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28452 ATM_SKB(sb)->vcc = vcc;
28453 __net_timestamp(sb);
28454 vcc->push(vcc, sb);
28455 - atomic_inc(&vcc->stats->rx);
28456 + atomic_inc_unchecked(&vcc->stats->rx);
28457 }
28458
28459 push_rxbufs(card, skb);
28460 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28461
28462 if (!atm_charge(vcc, skb->truesize)) {
28463 push_rxbufs(card, skb);
28464 - atomic_inc(&vcc->stats->rx_drop);
28465 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28466 } else {
28467 dequeue_lg_buf(card, skb);
28468 #ifdef NS_USE_DESTRUCTORS
28469 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28470 ATM_SKB(skb)->vcc = vcc;
28471 __net_timestamp(skb);
28472 vcc->push(vcc, skb);
28473 - atomic_inc(&vcc->stats->rx);
28474 + atomic_inc_unchecked(&vcc->stats->rx);
28475 }
28476
28477 push_rxbufs(card, sb);
28478 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28479 printk
28480 ("nicstar%d: Out of huge buffers.\n",
28481 card->index);
28482 - atomic_inc(&vcc->stats->rx_drop);
28483 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28484 recycle_iovec_rx_bufs(card,
28485 (struct iovec *)
28486 iovb->data,
28487 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28488 card->hbpool.count++;
28489 } else
28490 dev_kfree_skb_any(hb);
28491 - atomic_inc(&vcc->stats->rx_drop);
28492 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28493 } else {
28494 /* Copy the small buffer to the huge buffer */
28495 sb = (struct sk_buff *)iov->iov_base;
28496 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28497 #endif /* NS_USE_DESTRUCTORS */
28498 __net_timestamp(hb);
28499 vcc->push(vcc, hb);
28500 - atomic_inc(&vcc->stats->rx);
28501 + atomic_inc_unchecked(&vcc->stats->rx);
28502 }
28503 }
28504
28505 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28506 index e8cd652..bbbd1fc 100644
28507 --- a/drivers/atm/solos-pci.c
28508 +++ b/drivers/atm/solos-pci.c
28509 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28510 }
28511 atm_charge(vcc, skb->truesize);
28512 vcc->push(vcc, skb);
28513 - atomic_inc(&vcc->stats->rx);
28514 + atomic_inc_unchecked(&vcc->stats->rx);
28515 break;
28516
28517 case PKT_STATUS:
28518 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28519 vcc = SKB_CB(oldskb)->vcc;
28520
28521 if (vcc) {
28522 - atomic_inc(&vcc->stats->tx);
28523 + atomic_inc_unchecked(&vcc->stats->tx);
28524 solos_pop(vcc, oldskb);
28525 } else
28526 dev_kfree_skb_irq(oldskb);
28527 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28528 index 90f1ccc..04c4a1e 100644
28529 --- a/drivers/atm/suni.c
28530 +++ b/drivers/atm/suni.c
28531 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28532
28533
28534 #define ADD_LIMITED(s,v) \
28535 - atomic_add((v),&stats->s); \
28536 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28537 + atomic_add_unchecked((v),&stats->s); \
28538 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28539
28540
28541 static void suni_hz(unsigned long from_timer)
28542 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28543 index 5120a96..e2572bd 100644
28544 --- a/drivers/atm/uPD98402.c
28545 +++ b/drivers/atm/uPD98402.c
28546 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28547 struct sonet_stats tmp;
28548 int error = 0;
28549
28550 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28551 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28552 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28553 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28554 if (zero && !error) {
28555 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28556
28557
28558 #define ADD_LIMITED(s,v) \
28559 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28560 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28561 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28562 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28563 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28564 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28565
28566
28567 static void stat_event(struct atm_dev *dev)
28568 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28569 if (reason & uPD98402_INT_PFM) stat_event(dev);
28570 if (reason & uPD98402_INT_PCO) {
28571 (void) GET(PCOCR); /* clear interrupt cause */
28572 - atomic_add(GET(HECCT),
28573 + atomic_add_unchecked(GET(HECCT),
28574 &PRIV(dev)->sonet_stats.uncorr_hcs);
28575 }
28576 if ((reason & uPD98402_INT_RFO) &&
28577 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28578 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28579 uPD98402_INT_LOS),PIMR); /* enable them */
28580 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28581 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28582 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28583 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28584 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28585 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28586 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28587 return 0;
28588 }
28589
28590 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28591 index d889f56..17eb71e 100644
28592 --- a/drivers/atm/zatm.c
28593 +++ b/drivers/atm/zatm.c
28594 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28595 }
28596 if (!size) {
28597 dev_kfree_skb_irq(skb);
28598 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28599 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28600 continue;
28601 }
28602 if (!atm_charge(vcc,skb->truesize)) {
28603 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28604 skb->len = size;
28605 ATM_SKB(skb)->vcc = vcc;
28606 vcc->push(vcc,skb);
28607 - atomic_inc(&vcc->stats->rx);
28608 + atomic_inc_unchecked(&vcc->stats->rx);
28609 }
28610 zout(pos & 0xffff,MTA(mbx));
28611 #if 0 /* probably a stupid idea */
28612 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28613 skb_queue_head(&zatm_vcc->backlog,skb);
28614 break;
28615 }
28616 - atomic_inc(&vcc->stats->tx);
28617 + atomic_inc_unchecked(&vcc->stats->tx);
28618 wake_up(&zatm_vcc->tx_wait);
28619 }
28620
28621 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28622 index 8493536..31adee0 100644
28623 --- a/drivers/base/devtmpfs.c
28624 +++ b/drivers/base/devtmpfs.c
28625 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28626 if (!thread)
28627 return 0;
28628
28629 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28630 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28631 if (err)
28632 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28633 else
28634 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28635 index caf995f..6f76697 100644
28636 --- a/drivers/base/power/wakeup.c
28637 +++ b/drivers/base/power/wakeup.c
28638 @@ -30,14 +30,14 @@ bool events_check_enabled;
28639 * They need to be modified together atomically, so it's better to use one
28640 * atomic variable to hold them both.
28641 */
28642 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28643 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28644
28645 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28646 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28647
28648 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28649 {
28650 - unsigned int comb = atomic_read(&combined_event_count);
28651 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28652
28653 *cnt = (comb >> IN_PROGRESS_BITS);
28654 *inpr = comb & MAX_IN_PROGRESS;
28655 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28656 ws->last_time = ktime_get();
28657
28658 /* Increment the counter of events in progress. */
28659 - atomic_inc(&combined_event_count);
28660 + atomic_inc_unchecked(&combined_event_count);
28661 }
28662
28663 /**
28664 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28665 * Increment the counter of registered wakeup events and decrement the
28666 * couter of wakeup events in progress simultaneously.
28667 */
28668 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28669 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28670 }
28671
28672 /**
28673 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28674 index b0f553b..77b928b 100644
28675 --- a/drivers/block/cciss.c
28676 +++ b/drivers/block/cciss.c
28677 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28678 int err;
28679 u32 cp;
28680
28681 + memset(&arg64, 0, sizeof(arg64));
28682 +
28683 err = 0;
28684 err |=
28685 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28686 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28687 while (!list_empty(&h->reqQ)) {
28688 c = list_entry(h->reqQ.next, CommandList_struct, list);
28689 /* can't do anything if fifo is full */
28690 - if ((h->access.fifo_full(h))) {
28691 + if ((h->access->fifo_full(h))) {
28692 dev_warn(&h->pdev->dev, "fifo full\n");
28693 break;
28694 }
28695 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28696 h->Qdepth--;
28697
28698 /* Tell the controller execute command */
28699 - h->access.submit_command(h, c);
28700 + h->access->submit_command(h, c);
28701
28702 /* Put job onto the completed Q */
28703 addQ(&h->cmpQ, c);
28704 @@ -3443,17 +3445,17 @@ startio:
28705
28706 static inline unsigned long get_next_completion(ctlr_info_t *h)
28707 {
28708 - return h->access.command_completed(h);
28709 + return h->access->command_completed(h);
28710 }
28711
28712 static inline int interrupt_pending(ctlr_info_t *h)
28713 {
28714 - return h->access.intr_pending(h);
28715 + return h->access->intr_pending(h);
28716 }
28717
28718 static inline long interrupt_not_for_us(ctlr_info_t *h)
28719 {
28720 - return ((h->access.intr_pending(h) == 0) ||
28721 + return ((h->access->intr_pending(h) == 0) ||
28722 (h->interrupts_enabled == 0));
28723 }
28724
28725 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28726 u32 a;
28727
28728 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28729 - return h->access.command_completed(h);
28730 + return h->access->command_completed(h);
28731
28732 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28733 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28734 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28735 trans_support & CFGTBL_Trans_use_short_tags);
28736
28737 /* Change the access methods to the performant access methods */
28738 - h->access = SA5_performant_access;
28739 + h->access = &SA5_performant_access;
28740 h->transMethod = CFGTBL_Trans_Performant;
28741
28742 return;
28743 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28744 if (prod_index < 0)
28745 return -ENODEV;
28746 h->product_name = products[prod_index].product_name;
28747 - h->access = *(products[prod_index].access);
28748 + h->access = products[prod_index].access;
28749
28750 if (cciss_board_disabled(h)) {
28751 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28752 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28753 }
28754
28755 /* make sure the board interrupts are off */
28756 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28757 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28758 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28759 if (rc)
28760 goto clean2;
28761 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28762 * fake ones to scoop up any residual completions.
28763 */
28764 spin_lock_irqsave(&h->lock, flags);
28765 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28766 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28767 spin_unlock_irqrestore(&h->lock, flags);
28768 free_irq(h->intr[h->intr_mode], h);
28769 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28770 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28771 dev_info(&h->pdev->dev, "Board READY.\n");
28772 dev_info(&h->pdev->dev,
28773 "Waiting for stale completions to drain.\n");
28774 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28775 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28776 msleep(10000);
28777 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28778 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28779
28780 rc = controller_reset_failed(h->cfgtable);
28781 if (rc)
28782 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28783 cciss_scsi_setup(h);
28784
28785 /* Turn the interrupts on so we can service requests */
28786 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28787 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28788
28789 /* Get the firmware version */
28790 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28791 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28792 kfree(flush_buf);
28793 if (return_code != IO_OK)
28794 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28795 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28796 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28797 free_irq(h->intr[h->intr_mode], h);
28798 }
28799
28800 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28801 index 7fda30e..eb5dfe0 100644
28802 --- a/drivers/block/cciss.h
28803 +++ b/drivers/block/cciss.h
28804 @@ -101,7 +101,7 @@ struct ctlr_info
28805 /* information about each logical volume */
28806 drive_info_struct *drv[CISS_MAX_LUN];
28807
28808 - struct access_method access;
28809 + struct access_method *access;
28810
28811 /* queue and queue Info */
28812 struct list_head reqQ;
28813 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28814 index 9125bbe..eede5c8 100644
28815 --- a/drivers/block/cpqarray.c
28816 +++ b/drivers/block/cpqarray.c
28817 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28818 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28819 goto Enomem4;
28820 }
28821 - hba[i]->access.set_intr_mask(hba[i], 0);
28822 + hba[i]->access->set_intr_mask(hba[i], 0);
28823 if (request_irq(hba[i]->intr, do_ida_intr,
28824 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28825 {
28826 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28827 add_timer(&hba[i]->timer);
28828
28829 /* Enable IRQ now that spinlock and rate limit timer are set up */
28830 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28831 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28832
28833 for(j=0; j<NWD; j++) {
28834 struct gendisk *disk = ida_gendisk[i][j];
28835 @@ -694,7 +694,7 @@ DBGINFO(
28836 for(i=0; i<NR_PRODUCTS; i++) {
28837 if (board_id == products[i].board_id) {
28838 c->product_name = products[i].product_name;
28839 - c->access = *(products[i].access);
28840 + c->access = products[i].access;
28841 break;
28842 }
28843 }
28844 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28845 hba[ctlr]->intr = intr;
28846 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28847 hba[ctlr]->product_name = products[j].product_name;
28848 - hba[ctlr]->access = *(products[j].access);
28849 + hba[ctlr]->access = products[j].access;
28850 hba[ctlr]->ctlr = ctlr;
28851 hba[ctlr]->board_id = board_id;
28852 hba[ctlr]->pci_dev = NULL; /* not PCI */
28853 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28854
28855 while((c = h->reqQ) != NULL) {
28856 /* Can't do anything if we're busy */
28857 - if (h->access.fifo_full(h) == 0)
28858 + if (h->access->fifo_full(h) == 0)
28859 return;
28860
28861 /* Get the first entry from the request Q */
28862 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28863 h->Qdepth--;
28864
28865 /* Tell the controller to do our bidding */
28866 - h->access.submit_command(h, c);
28867 + h->access->submit_command(h, c);
28868
28869 /* Get onto the completion Q */
28870 addQ(&h->cmpQ, c);
28871 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28872 unsigned long flags;
28873 __u32 a,a1;
28874
28875 - istat = h->access.intr_pending(h);
28876 + istat = h->access->intr_pending(h);
28877 /* Is this interrupt for us? */
28878 if (istat == 0)
28879 return IRQ_NONE;
28880 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28881 */
28882 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28883 if (istat & FIFO_NOT_EMPTY) {
28884 - while((a = h->access.command_completed(h))) {
28885 + while((a = h->access->command_completed(h))) {
28886 a1 = a; a &= ~3;
28887 if ((c = h->cmpQ) == NULL)
28888 {
28889 @@ -1449,11 +1449,11 @@ static int sendcmd(
28890 /*
28891 * Disable interrupt
28892 */
28893 - info_p->access.set_intr_mask(info_p, 0);
28894 + info_p->access->set_intr_mask(info_p, 0);
28895 /* Make sure there is room in the command FIFO */
28896 /* Actually it should be completely empty at this time. */
28897 for (i = 200000; i > 0; i--) {
28898 - temp = info_p->access.fifo_full(info_p);
28899 + temp = info_p->access->fifo_full(info_p);
28900 if (temp != 0) {
28901 break;
28902 }
28903 @@ -1466,7 +1466,7 @@ DBG(
28904 /*
28905 * Send the cmd
28906 */
28907 - info_p->access.submit_command(info_p, c);
28908 + info_p->access->submit_command(info_p, c);
28909 complete = pollcomplete(ctlr);
28910
28911 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28912 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28913 * we check the new geometry. Then turn interrupts back on when
28914 * we're done.
28915 */
28916 - host->access.set_intr_mask(host, 0);
28917 + host->access->set_intr_mask(host, 0);
28918 getgeometry(ctlr);
28919 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28920 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28921
28922 for(i=0; i<NWD; i++) {
28923 struct gendisk *disk = ida_gendisk[ctlr][i];
28924 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28925 /* Wait (up to 2 seconds) for a command to complete */
28926
28927 for (i = 200000; i > 0; i--) {
28928 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
28929 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
28930 if (done == 0) {
28931 udelay(10); /* a short fixed delay */
28932 } else
28933 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28934 index be73e9d..7fbf140 100644
28935 --- a/drivers/block/cpqarray.h
28936 +++ b/drivers/block/cpqarray.h
28937 @@ -99,7 +99,7 @@ struct ctlr_info {
28938 drv_info_t drv[NWD];
28939 struct proc_dir_entry *proc;
28940
28941 - struct access_method access;
28942 + struct access_method *access;
28943
28944 cmdlist_t *reqQ;
28945 cmdlist_t *cmpQ;
28946 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
28947 index 8d68056..e67050f 100644
28948 --- a/drivers/block/drbd/drbd_int.h
28949 +++ b/drivers/block/drbd/drbd_int.h
28950 @@ -736,7 +736,7 @@ struct drbd_request;
28951 struct drbd_epoch {
28952 struct list_head list;
28953 unsigned int barrier_nr;
28954 - atomic_t epoch_size; /* increased on every request added. */
28955 + atomic_unchecked_t epoch_size; /* increased on every request added. */
28956 atomic_t active; /* increased on every req. added, and dec on every finished. */
28957 unsigned long flags;
28958 };
28959 @@ -1108,7 +1108,7 @@ struct drbd_conf {
28960 void *int_dig_in;
28961 void *int_dig_vv;
28962 wait_queue_head_t seq_wait;
28963 - atomic_t packet_seq;
28964 + atomic_unchecked_t packet_seq;
28965 unsigned int peer_seq;
28966 spinlock_t peer_seq_lock;
28967 unsigned int minor;
28968 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
28969
28970 static inline void drbd_tcp_cork(struct socket *sock)
28971 {
28972 - int __user val = 1;
28973 + int val = 1;
28974 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28975 - (char __user *)&val, sizeof(val));
28976 + (char __force_user *)&val, sizeof(val));
28977 }
28978
28979 static inline void drbd_tcp_uncork(struct socket *sock)
28980 {
28981 - int __user val = 0;
28982 + int val = 0;
28983 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28984 - (char __user *)&val, sizeof(val));
28985 + (char __force_user *)&val, sizeof(val));
28986 }
28987
28988 static inline void drbd_tcp_nodelay(struct socket *sock)
28989 {
28990 - int __user val = 1;
28991 + int val = 1;
28992 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
28993 - (char __user *)&val, sizeof(val));
28994 + (char __force_user *)&val, sizeof(val));
28995 }
28996
28997 static inline void drbd_tcp_quickack(struct socket *sock)
28998 {
28999 - int __user val = 2;
29000 + int val = 2;
29001 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29002 - (char __user *)&val, sizeof(val));
29003 + (char __force_user *)&val, sizeof(val));
29004 }
29005
29006 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29007 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29008 index 211fc44..c5116f1 100644
29009 --- a/drivers/block/drbd/drbd_main.c
29010 +++ b/drivers/block/drbd/drbd_main.c
29011 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29012 p.sector = sector;
29013 p.block_id = block_id;
29014 p.blksize = blksize;
29015 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29016 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29017
29018 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29019 return false;
29020 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29021 p.sector = cpu_to_be64(req->sector);
29022 p.block_id = (unsigned long)req;
29023 p.seq_num = cpu_to_be32(req->seq_num =
29024 - atomic_add_return(1, &mdev->packet_seq));
29025 + atomic_add_return_unchecked(1, &mdev->packet_seq));
29026
29027 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29028
29029 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29030 atomic_set(&mdev->unacked_cnt, 0);
29031 atomic_set(&mdev->local_cnt, 0);
29032 atomic_set(&mdev->net_cnt, 0);
29033 - atomic_set(&mdev->packet_seq, 0);
29034 + atomic_set_unchecked(&mdev->packet_seq, 0);
29035 atomic_set(&mdev->pp_in_use, 0);
29036 atomic_set(&mdev->pp_in_use_by_net, 0);
29037 atomic_set(&mdev->rs_sect_in, 0);
29038 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29039 mdev->receiver.t_state);
29040
29041 /* no need to lock it, I'm the only thread alive */
29042 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29043 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29044 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29045 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29046 mdev->al_writ_cnt =
29047 mdev->bm_writ_cnt =
29048 mdev->read_cnt =
29049 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29050 index af2a250..219c74b 100644
29051 --- a/drivers/block/drbd/drbd_nl.c
29052 +++ b/drivers/block/drbd/drbd_nl.c
29053 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29054 module_put(THIS_MODULE);
29055 }
29056
29057 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29058 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29059
29060 static unsigned short *
29061 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29062 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29063 cn_reply->id.idx = CN_IDX_DRBD;
29064 cn_reply->id.val = CN_VAL_DRBD;
29065
29066 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29067 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29068 cn_reply->ack = 0; /* not used here. */
29069 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29070 (int)((char *)tl - (char *)reply->tag_list);
29071 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29072 cn_reply->id.idx = CN_IDX_DRBD;
29073 cn_reply->id.val = CN_VAL_DRBD;
29074
29075 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29076 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29077 cn_reply->ack = 0; /* not used here. */
29078 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29079 (int)((char *)tl - (char *)reply->tag_list);
29080 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29081 cn_reply->id.idx = CN_IDX_DRBD;
29082 cn_reply->id.val = CN_VAL_DRBD;
29083
29084 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29085 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29086 cn_reply->ack = 0; // not used here.
29087 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29088 (int)((char*)tl - (char*)reply->tag_list);
29089 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29090 cn_reply->id.idx = CN_IDX_DRBD;
29091 cn_reply->id.val = CN_VAL_DRBD;
29092
29093 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29094 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29095 cn_reply->ack = 0; /* not used here. */
29096 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29097 (int)((char *)tl - (char *)reply->tag_list);
29098 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29099 index 43beaca..4a5b1dd 100644
29100 --- a/drivers/block/drbd/drbd_receiver.c
29101 +++ b/drivers/block/drbd/drbd_receiver.c
29102 @@ -894,7 +894,7 @@ retry:
29103 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29104 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29105
29106 - atomic_set(&mdev->packet_seq, 0);
29107 + atomic_set_unchecked(&mdev->packet_seq, 0);
29108 mdev->peer_seq = 0;
29109
29110 drbd_thread_start(&mdev->asender);
29111 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29112 do {
29113 next_epoch = NULL;
29114
29115 - epoch_size = atomic_read(&epoch->epoch_size);
29116 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29117
29118 switch (ev & ~EV_CLEANUP) {
29119 case EV_PUT:
29120 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29121 rv = FE_DESTROYED;
29122 } else {
29123 epoch->flags = 0;
29124 - atomic_set(&epoch->epoch_size, 0);
29125 + atomic_set_unchecked(&epoch->epoch_size, 0);
29126 /* atomic_set(&epoch->active, 0); is already zero */
29127 if (rv == FE_STILL_LIVE)
29128 rv = FE_RECYCLED;
29129 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29130 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29131 drbd_flush(mdev);
29132
29133 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29134 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29135 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29136 if (epoch)
29137 break;
29138 }
29139
29140 epoch = mdev->current_epoch;
29141 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29142 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29143
29144 D_ASSERT(atomic_read(&epoch->active) == 0);
29145 D_ASSERT(epoch->flags == 0);
29146 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29147 }
29148
29149 epoch->flags = 0;
29150 - atomic_set(&epoch->epoch_size, 0);
29151 + atomic_set_unchecked(&epoch->epoch_size, 0);
29152 atomic_set(&epoch->active, 0);
29153
29154 spin_lock(&mdev->epoch_lock);
29155 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29156 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29157 list_add(&epoch->list, &mdev->current_epoch->list);
29158 mdev->current_epoch = epoch;
29159 mdev->epochs++;
29160 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29161 spin_unlock(&mdev->peer_seq_lock);
29162
29163 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29164 - atomic_inc(&mdev->current_epoch->epoch_size);
29165 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29166 return drbd_drain_block(mdev, data_size);
29167 }
29168
29169 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29170
29171 spin_lock(&mdev->epoch_lock);
29172 e->epoch = mdev->current_epoch;
29173 - atomic_inc(&e->epoch->epoch_size);
29174 + atomic_inc_unchecked(&e->epoch->epoch_size);
29175 atomic_inc(&e->epoch->active);
29176 spin_unlock(&mdev->epoch_lock);
29177
29178 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29179 D_ASSERT(list_empty(&mdev->done_ee));
29180
29181 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29182 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29183 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29184 D_ASSERT(list_empty(&mdev->current_epoch->list));
29185 }
29186
29187 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29188 index cd50435..ba1ffb5 100644
29189 --- a/drivers/block/loop.c
29190 +++ b/drivers/block/loop.c
29191 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29192 mm_segment_t old_fs = get_fs();
29193
29194 set_fs(get_ds());
29195 - bw = file->f_op->write(file, buf, len, &pos);
29196 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29197 set_fs(old_fs);
29198 if (likely(bw == len))
29199 return 0;
29200 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29201 index 4364303..9adf4ee 100644
29202 --- a/drivers/char/Kconfig
29203 +++ b/drivers/char/Kconfig
29204 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29205
29206 config DEVKMEM
29207 bool "/dev/kmem virtual device support"
29208 - default y
29209 + default n
29210 + depends on !GRKERNSEC_KMEM
29211 help
29212 Say Y here if you want to support the /dev/kmem device. The
29213 /dev/kmem device is rarely used, but can be used for certain
29214 @@ -596,6 +597,7 @@ config DEVPORT
29215 bool
29216 depends on !M68K
29217 depends on ISA || PCI
29218 + depends on !GRKERNSEC_KMEM
29219 default y
29220
29221 source "drivers/s390/char/Kconfig"
29222 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29223 index 2e04433..22afc64 100644
29224 --- a/drivers/char/agp/frontend.c
29225 +++ b/drivers/char/agp/frontend.c
29226 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29227 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29228 return -EFAULT;
29229
29230 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29231 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29232 return -EFAULT;
29233
29234 client = agp_find_client_by_pid(reserve.pid);
29235 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
29236 index 095ab90..afad0a4 100644
29237 --- a/drivers/char/briq_panel.c
29238 +++ b/drivers/char/briq_panel.c
29239 @@ -9,6 +9,7 @@
29240 #include <linux/types.h>
29241 #include <linux/errno.h>
29242 #include <linux/tty.h>
29243 +#include <linux/mutex.h>
29244 #include <linux/timer.h>
29245 #include <linux/kernel.h>
29246 #include <linux/wait.h>
29247 @@ -34,6 +35,7 @@ static int vfd_is_open;
29248 static unsigned char vfd[40];
29249 static int vfd_cursor;
29250 static unsigned char ledpb, led;
29251 +static DEFINE_MUTEX(vfd_mutex);
29252
29253 static void update_vfd(void)
29254 {
29255 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29256 if (!vfd_is_open)
29257 return -EBUSY;
29258
29259 + mutex_lock(&vfd_mutex);
29260 for (;;) {
29261 char c;
29262 if (!indx)
29263 break;
29264 - if (get_user(c, buf))
29265 + if (get_user(c, buf)) {
29266 + mutex_unlock(&vfd_mutex);
29267 return -EFAULT;
29268 + }
29269 if (esc) {
29270 set_led(c);
29271 esc = 0;
29272 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29273 buf++;
29274 }
29275 update_vfd();
29276 + mutex_unlock(&vfd_mutex);
29277
29278 return len;
29279 }
29280 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29281 index f773a9d..65cd683 100644
29282 --- a/drivers/char/genrtc.c
29283 +++ b/drivers/char/genrtc.c
29284 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
29285 switch (cmd) {
29286
29287 case RTC_PLL_GET:
29288 + memset(&pll, 0, sizeof(pll));
29289 if (get_rtc_pll(&pll))
29290 return -EINVAL;
29291 else
29292 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29293 index 0833896..cccce52 100644
29294 --- a/drivers/char/hpet.c
29295 +++ b/drivers/char/hpet.c
29296 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29297 }
29298
29299 static int
29300 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29301 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29302 struct hpet_info *info)
29303 {
29304 struct hpet_timer __iomem *timer;
29305 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29306 index 58c0e63..46c16bf 100644
29307 --- a/drivers/char/ipmi/ipmi_msghandler.c
29308 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29309 @@ -415,7 +415,7 @@ struct ipmi_smi {
29310 struct proc_dir_entry *proc_dir;
29311 char proc_dir_name[10];
29312
29313 - atomic_t stats[IPMI_NUM_STATS];
29314 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29315
29316 /*
29317 * run_to_completion duplicate of smb_info, smi_info
29318 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29319
29320
29321 #define ipmi_inc_stat(intf, stat) \
29322 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29323 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29324 #define ipmi_get_stat(intf, stat) \
29325 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29326 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29327
29328 static int is_lan_addr(struct ipmi_addr *addr)
29329 {
29330 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29331 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29332 init_waitqueue_head(&intf->waitq);
29333 for (i = 0; i < IPMI_NUM_STATS; i++)
29334 - atomic_set(&intf->stats[i], 0);
29335 + atomic_set_unchecked(&intf->stats[i], 0);
29336
29337 intf->proc_dir = NULL;
29338
29339 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29340 index 50fcf9c..91b5528 100644
29341 --- a/drivers/char/ipmi/ipmi_si_intf.c
29342 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29343 @@ -277,7 +277,7 @@ struct smi_info {
29344 unsigned char slave_addr;
29345
29346 /* Counters and things for the proc filesystem. */
29347 - atomic_t stats[SI_NUM_STATS];
29348 + atomic_unchecked_t stats[SI_NUM_STATS];
29349
29350 struct task_struct *thread;
29351
29352 @@ -286,9 +286,9 @@ struct smi_info {
29353 };
29354
29355 #define smi_inc_stat(smi, stat) \
29356 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29357 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29358 #define smi_get_stat(smi, stat) \
29359 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29360 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29361
29362 #define SI_MAX_PARMS 4
29363
29364 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
29365 atomic_set(&new_smi->req_events, 0);
29366 new_smi->run_to_completion = 0;
29367 for (i = 0; i < SI_NUM_STATS; i++)
29368 - atomic_set(&new_smi->stats[i], 0);
29369 + atomic_set_unchecked(&new_smi->stats[i], 0);
29370
29371 new_smi->interrupt_disabled = 1;
29372 atomic_set(&new_smi->stop_operation, 0);
29373 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29374 index 1aeaaba..e018570 100644
29375 --- a/drivers/char/mbcs.c
29376 +++ b/drivers/char/mbcs.c
29377 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
29378 return 0;
29379 }
29380
29381 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29382 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29383 {
29384 .part_num = MBCS_PART_NUM,
29385 .mfg_num = MBCS_MFG_NUM,
29386 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29387 index d6e9d08..4493e89 100644
29388 --- a/drivers/char/mem.c
29389 +++ b/drivers/char/mem.c
29390 @@ -18,6 +18,7 @@
29391 #include <linux/raw.h>
29392 #include <linux/tty.h>
29393 #include <linux/capability.h>
29394 +#include <linux/security.h>
29395 #include <linux/ptrace.h>
29396 #include <linux/device.h>
29397 #include <linux/highmem.h>
29398 @@ -35,6 +36,10 @@
29399 # include <linux/efi.h>
29400 #endif
29401
29402 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29403 +extern const struct file_operations grsec_fops;
29404 +#endif
29405 +
29406 static inline unsigned long size_inside_page(unsigned long start,
29407 unsigned long size)
29408 {
29409 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29410
29411 while (cursor < to) {
29412 if (!devmem_is_allowed(pfn)) {
29413 +#ifdef CONFIG_GRKERNSEC_KMEM
29414 + gr_handle_mem_readwrite(from, to);
29415 +#else
29416 printk(KERN_INFO
29417 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29418 current->comm, from, to);
29419 +#endif
29420 return 0;
29421 }
29422 cursor += PAGE_SIZE;
29423 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29424 }
29425 return 1;
29426 }
29427 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29428 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29429 +{
29430 + return 0;
29431 +}
29432 #else
29433 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29434 {
29435 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29436
29437 while (count > 0) {
29438 unsigned long remaining;
29439 + char *temp;
29440
29441 sz = size_inside_page(p, count);
29442
29443 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29444 if (!ptr)
29445 return -EFAULT;
29446
29447 - remaining = copy_to_user(buf, ptr, sz);
29448 +#ifdef CONFIG_PAX_USERCOPY
29449 + temp = kmalloc(sz, GFP_KERNEL);
29450 + if (!temp) {
29451 + unxlate_dev_mem_ptr(p, ptr);
29452 + return -ENOMEM;
29453 + }
29454 + memcpy(temp, ptr, sz);
29455 +#else
29456 + temp = ptr;
29457 +#endif
29458 +
29459 + remaining = copy_to_user(buf, temp, sz);
29460 +
29461 +#ifdef CONFIG_PAX_USERCOPY
29462 + kfree(temp);
29463 +#endif
29464 +
29465 unxlate_dev_mem_ptr(p, ptr);
29466 if (remaining)
29467 return -EFAULT;
29468 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29469 size_t count, loff_t *ppos)
29470 {
29471 unsigned long p = *ppos;
29472 - ssize_t low_count, read, sz;
29473 + ssize_t low_count, read, sz, err = 0;
29474 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29475 - int err = 0;
29476
29477 read = 0;
29478 if (p < (unsigned long) high_memory) {
29479 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29480 }
29481 #endif
29482 while (low_count > 0) {
29483 + char *temp;
29484 +
29485 sz = size_inside_page(p, low_count);
29486
29487 /*
29488 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29489 */
29490 kbuf = xlate_dev_kmem_ptr((char *)p);
29491
29492 - if (copy_to_user(buf, kbuf, sz))
29493 +#ifdef CONFIG_PAX_USERCOPY
29494 + temp = kmalloc(sz, GFP_KERNEL);
29495 + if (!temp)
29496 + return -ENOMEM;
29497 + memcpy(temp, kbuf, sz);
29498 +#else
29499 + temp = kbuf;
29500 +#endif
29501 +
29502 + err = copy_to_user(buf, temp, sz);
29503 +
29504 +#ifdef CONFIG_PAX_USERCOPY
29505 + kfree(temp);
29506 +#endif
29507 +
29508 + if (err)
29509 return -EFAULT;
29510 buf += sz;
29511 p += sz;
29512 @@ -867,6 +914,9 @@ static const struct memdev {
29513 #ifdef CONFIG_CRASH_DUMP
29514 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29515 #endif
29516 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29517 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29518 +#endif
29519 };
29520
29521 static int memory_open(struct inode *inode, struct file *filp)
29522 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29523 index da3cfee..a5a6606 100644
29524 --- a/drivers/char/nvram.c
29525 +++ b/drivers/char/nvram.c
29526 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29527
29528 spin_unlock_irq(&rtc_lock);
29529
29530 - if (copy_to_user(buf, contents, tmp - contents))
29531 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29532 return -EFAULT;
29533
29534 *ppos = i;
29535 diff --git a/drivers/char/random.c b/drivers/char/random.c
29536 index 54ca8b2..4a092ed 100644
29537 --- a/drivers/char/random.c
29538 +++ b/drivers/char/random.c
29539 @@ -261,8 +261,13 @@
29540 /*
29541 * Configuration information
29542 */
29543 +#ifdef CONFIG_GRKERNSEC_RANDNET
29544 +#define INPUT_POOL_WORDS 512
29545 +#define OUTPUT_POOL_WORDS 128
29546 +#else
29547 #define INPUT_POOL_WORDS 128
29548 #define OUTPUT_POOL_WORDS 32
29549 +#endif
29550 #define SEC_XFER_SIZE 512
29551 #define EXTRACT_SIZE 10
29552
29553 @@ -300,10 +305,17 @@ static struct poolinfo {
29554 int poolwords;
29555 int tap1, tap2, tap3, tap4, tap5;
29556 } poolinfo_table[] = {
29557 +#ifdef CONFIG_GRKERNSEC_RANDNET
29558 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29559 + { 512, 411, 308, 208, 104, 1 },
29560 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29561 + { 128, 103, 76, 51, 25, 1 },
29562 +#else
29563 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29564 { 128, 103, 76, 51, 25, 1 },
29565 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29566 { 32, 26, 20, 14, 7, 1 },
29567 +#endif
29568 #if 0
29569 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29570 { 2048, 1638, 1231, 819, 411, 1 },
29571 @@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29572
29573 extract_buf(r, tmp);
29574 i = min_t(int, nbytes, EXTRACT_SIZE);
29575 - if (copy_to_user(buf, tmp, i)) {
29576 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29577 ret = -EFAULT;
29578 break;
29579 }
29580 @@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29581 #include <linux/sysctl.h>
29582
29583 static int min_read_thresh = 8, min_write_thresh;
29584 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29585 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29586 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29587 static char sysctl_bootid[16];
29588
29589 @@ -1260,10 +1272,15 @@ static int proc_do_uuid(ctl_table *table, int write,
29590 uuid = table->data;
29591 if (!uuid) {
29592 uuid = tmp_uuid;
29593 - uuid[8] = 0;
29594 - }
29595 - if (uuid[8] == 0)
29596 generate_random_uuid(uuid);
29597 + } else {
29598 + static DEFINE_SPINLOCK(bootid_spinlock);
29599 +
29600 + spin_lock(&bootid_spinlock);
29601 + if (!uuid[8])
29602 + generate_random_uuid(uuid);
29603 + spin_unlock(&bootid_spinlock);
29604 + }
29605
29606 sprintf(buf, "%pU", uuid);
29607
29608 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29609 index 1ee8ce7..b778bef 100644
29610 --- a/drivers/char/sonypi.c
29611 +++ b/drivers/char/sonypi.c
29612 @@ -55,6 +55,7 @@
29613 #include <asm/uaccess.h>
29614 #include <asm/io.h>
29615 #include <asm/system.h>
29616 +#include <asm/local.h>
29617
29618 #include <linux/sonypi.h>
29619
29620 @@ -491,7 +492,7 @@ static struct sonypi_device {
29621 spinlock_t fifo_lock;
29622 wait_queue_head_t fifo_proc_list;
29623 struct fasync_struct *fifo_async;
29624 - int open_count;
29625 + local_t open_count;
29626 int model;
29627 struct input_dev *input_jog_dev;
29628 struct input_dev *input_key_dev;
29629 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29630 static int sonypi_misc_release(struct inode *inode, struct file *file)
29631 {
29632 mutex_lock(&sonypi_device.lock);
29633 - sonypi_device.open_count--;
29634 + local_dec(&sonypi_device.open_count);
29635 mutex_unlock(&sonypi_device.lock);
29636 return 0;
29637 }
29638 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29639 {
29640 mutex_lock(&sonypi_device.lock);
29641 /* Flush input queue on first open */
29642 - if (!sonypi_device.open_count)
29643 + if (!local_read(&sonypi_device.open_count))
29644 kfifo_reset(&sonypi_device.fifo);
29645 - sonypi_device.open_count++;
29646 + local_inc(&sonypi_device.open_count);
29647 mutex_unlock(&sonypi_device.lock);
29648
29649 return 0;
29650 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29651 index ad7c732..5aa8054 100644
29652 --- a/drivers/char/tpm/tpm.c
29653 +++ b/drivers/char/tpm/tpm.c
29654 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29655 chip->vendor.req_complete_val)
29656 goto out_recv;
29657
29658 - if ((status == chip->vendor.req_canceled)) {
29659 + if (status == chip->vendor.req_canceled) {
29660 dev_err(chip->dev, "Operation Canceled\n");
29661 rc = -ECANCELED;
29662 goto out;
29663 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29664 index 0636520..169c1d0 100644
29665 --- a/drivers/char/tpm/tpm_bios.c
29666 +++ b/drivers/char/tpm/tpm_bios.c
29667 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29668 event = addr;
29669
29670 if ((event->event_type == 0 && event->event_size == 0) ||
29671 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29672 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29673 return NULL;
29674
29675 return addr;
29676 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29677 return NULL;
29678
29679 if ((event->event_type == 0 && event->event_size == 0) ||
29680 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29681 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29682 return NULL;
29683
29684 (*pos)++;
29685 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29686 int i;
29687
29688 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29689 - seq_putc(m, data[i]);
29690 + if (!seq_putc(m, data[i]))
29691 + return -EFAULT;
29692
29693 return 0;
29694 }
29695 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29696 log->bios_event_log_end = log->bios_event_log + len;
29697
29698 virt = acpi_os_map_memory(start, len);
29699 + if (!virt) {
29700 + kfree(log->bios_event_log);
29701 + log->bios_event_log = NULL;
29702 + return -EFAULT;
29703 + }
29704
29705 - memcpy(log->bios_event_log, virt, len);
29706 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29707
29708 acpi_os_unmap_memory(virt, len);
29709 return 0;
29710 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29711 index b58b561..c9088c8 100644
29712 --- a/drivers/char/virtio_console.c
29713 +++ b/drivers/char/virtio_console.c
29714 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29715 if (to_user) {
29716 ssize_t ret;
29717
29718 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29719 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29720 if (ret)
29721 return -EFAULT;
29722 } else {
29723 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29724 if (!port_has_data(port) && !port->host_connected)
29725 return 0;
29726
29727 - return fill_readbuf(port, ubuf, count, true);
29728 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29729 }
29730
29731 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29732 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
29733 index c9eee6d..f9d5280 100644
29734 --- a/drivers/edac/amd64_edac.c
29735 +++ b/drivers/edac/amd64_edac.c
29736 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
29737 * PCI core identifies what devices are on a system during boot, and then
29738 * inquiry this table to see if this driver is for a given device found.
29739 */
29740 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
29741 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
29742 {
29743 .vendor = PCI_VENDOR_ID_AMD,
29744 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
29745 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
29746 index e47e73b..348e0bd 100644
29747 --- a/drivers/edac/amd76x_edac.c
29748 +++ b/drivers/edac/amd76x_edac.c
29749 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
29750 edac_mc_free(mci);
29751 }
29752
29753 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
29754 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
29755 {
29756 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29757 AMD762},
29758 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
29759 index 1af531a..3a8ff27 100644
29760 --- a/drivers/edac/e752x_edac.c
29761 +++ b/drivers/edac/e752x_edac.c
29762 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
29763 edac_mc_free(mci);
29764 }
29765
29766 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
29767 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
29768 {
29769 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29770 E7520},
29771 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
29772 index 6ffb6d2..383d8d7 100644
29773 --- a/drivers/edac/e7xxx_edac.c
29774 +++ b/drivers/edac/e7xxx_edac.c
29775 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
29776 edac_mc_free(mci);
29777 }
29778
29779 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
29780 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
29781 {
29782 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29783 E7205},
29784 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29785 index 97f5064..202b6e6 100644
29786 --- a/drivers/edac/edac_pci_sysfs.c
29787 +++ b/drivers/edac/edac_pci_sysfs.c
29788 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29789 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29790 static int edac_pci_poll_msec = 1000; /* one second workq period */
29791
29792 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29793 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29794 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29795 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29796
29797 static struct kobject *edac_pci_top_main_kobj;
29798 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29799 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29800 edac_printk(KERN_CRIT, EDAC_PCI,
29801 "Signaled System Error on %s\n",
29802 pci_name(dev));
29803 - atomic_inc(&pci_nonparity_count);
29804 + atomic_inc_unchecked(&pci_nonparity_count);
29805 }
29806
29807 if (status & (PCI_STATUS_PARITY)) {
29808 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29809 "Master Data Parity Error on %s\n",
29810 pci_name(dev));
29811
29812 - atomic_inc(&pci_parity_count);
29813 + atomic_inc_unchecked(&pci_parity_count);
29814 }
29815
29816 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29817 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29818 "Detected Parity Error on %s\n",
29819 pci_name(dev));
29820
29821 - atomic_inc(&pci_parity_count);
29822 + atomic_inc_unchecked(&pci_parity_count);
29823 }
29824 }
29825
29826 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29827 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29828 "Signaled System Error on %s\n",
29829 pci_name(dev));
29830 - atomic_inc(&pci_nonparity_count);
29831 + atomic_inc_unchecked(&pci_nonparity_count);
29832 }
29833
29834 if (status & (PCI_STATUS_PARITY)) {
29835 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29836 "Master Data Parity Error on "
29837 "%s\n", pci_name(dev));
29838
29839 - atomic_inc(&pci_parity_count);
29840 + atomic_inc_unchecked(&pci_parity_count);
29841 }
29842
29843 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29844 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29845 "Detected Parity Error on %s\n",
29846 pci_name(dev));
29847
29848 - atomic_inc(&pci_parity_count);
29849 + atomic_inc_unchecked(&pci_parity_count);
29850 }
29851 }
29852 }
29853 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29854 if (!check_pci_errors)
29855 return;
29856
29857 - before_count = atomic_read(&pci_parity_count);
29858 + before_count = atomic_read_unchecked(&pci_parity_count);
29859
29860 /* scan all PCI devices looking for a Parity Error on devices and
29861 * bridges.
29862 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29863 /* Only if operator has selected panic on PCI Error */
29864 if (edac_pci_get_panic_on_pe()) {
29865 /* If the count is different 'after' from 'before' */
29866 - if (before_count != atomic_read(&pci_parity_count))
29867 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29868 panic("EDAC: PCI Parity Error");
29869 }
29870 }
29871 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
29872 index c0510b3..6e2a954 100644
29873 --- a/drivers/edac/i3000_edac.c
29874 +++ b/drivers/edac/i3000_edac.c
29875 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
29876 edac_mc_free(mci);
29877 }
29878
29879 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
29880 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
29881 {
29882 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29883 I3000},
29884 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
29885 index 73f55e200..5faaf59 100644
29886 --- a/drivers/edac/i3200_edac.c
29887 +++ b/drivers/edac/i3200_edac.c
29888 @@ -445,7 +445,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
29889 edac_mc_free(mci);
29890 }
29891
29892 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
29893 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
29894 {
29895 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29896 I3200},
29897 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
29898 index 4dc3ac2..67d05a6 100644
29899 --- a/drivers/edac/i5000_edac.c
29900 +++ b/drivers/edac/i5000_edac.c
29901 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
29902 *
29903 * The "E500P" device is the first device supported.
29904 */
29905 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
29906 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
29907 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
29908 .driver_data = I5000P},
29909
29910 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
29911 index bcbdeec..9886d16 100644
29912 --- a/drivers/edac/i5100_edac.c
29913 +++ b/drivers/edac/i5100_edac.c
29914 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
29915 edac_mc_free(mci);
29916 }
29917
29918 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
29919 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
29920 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
29921 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
29922 { 0, }
29923 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
29924 index 74d6ec34..baff517 100644
29925 --- a/drivers/edac/i5400_edac.c
29926 +++ b/drivers/edac/i5400_edac.c
29927 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
29928 *
29929 * The "E500P" device is the first device supported.
29930 */
29931 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
29932 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
29933 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
29934 {0,} /* 0 terminated list. */
29935 };
29936 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
29937 index 6104dba..e7ea8e1 100644
29938 --- a/drivers/edac/i7300_edac.c
29939 +++ b/drivers/edac/i7300_edac.c
29940 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
29941 *
29942 * Has only 8086:360c PCI ID
29943 */
29944 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
29945 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
29946 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
29947 {0,} /* 0 terminated list. */
29948 };
29949 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
29950 index 8568d9b..42b2fa8 100644
29951 --- a/drivers/edac/i7core_edac.c
29952 +++ b/drivers/edac/i7core_edac.c
29953 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
29954 /*
29955 * pci_device_id table for which devices we are looking for
29956 */
29957 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
29958 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
29959 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
29960 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
29961 {0,} /* 0 terminated list. */
29962 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
29963 index 4329d39..f3022ef 100644
29964 --- a/drivers/edac/i82443bxgx_edac.c
29965 +++ b/drivers/edac/i82443bxgx_edac.c
29966 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
29967
29968 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
29969
29970 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
29971 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
29972 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
29973 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
29974 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
29975 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
29976 index 931a057..fd28340 100644
29977 --- a/drivers/edac/i82860_edac.c
29978 +++ b/drivers/edac/i82860_edac.c
29979 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
29980 edac_mc_free(mci);
29981 }
29982
29983 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
29984 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
29985 {
29986 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29987 I82860},
29988 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
29989 index 33864c6..01edc61 100644
29990 --- a/drivers/edac/i82875p_edac.c
29991 +++ b/drivers/edac/i82875p_edac.c
29992 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
29993 edac_mc_free(mci);
29994 }
29995
29996 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
29997 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
29998 {
29999 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30000 I82875P},
30001 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
30002 index 4184e01..dcb2cd3 100644
30003 --- a/drivers/edac/i82975x_edac.c
30004 +++ b/drivers/edac/i82975x_edac.c
30005 @@ -612,7 +612,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
30006 edac_mc_free(mci);
30007 }
30008
30009 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
30010 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
30011 {
30012 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30013 I82975X
30014 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30015 index 0106747..0b40417 100644
30016 --- a/drivers/edac/mce_amd.h
30017 +++ b/drivers/edac/mce_amd.h
30018 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
30019 bool (*dc_mce)(u16, u8);
30020 bool (*ic_mce)(u16, u8);
30021 bool (*nb_mce)(u16, u8);
30022 -};
30023 +} __no_const;
30024
30025 void amd_report_gart_errors(bool);
30026 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30027 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
30028 index e294e1b..a41b05b 100644
30029 --- a/drivers/edac/r82600_edac.c
30030 +++ b/drivers/edac/r82600_edac.c
30031 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
30032 edac_mc_free(mci);
30033 }
30034
30035 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
30036 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
30037 {
30038 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
30039 },
30040 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
30041 index 1dc118d..8c68af9 100644
30042 --- a/drivers/edac/sb_edac.c
30043 +++ b/drivers/edac/sb_edac.c
30044 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
30045 /*
30046 * pci_device_id table for which devices we are looking for
30047 */
30048 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
30049 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
30050 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
30051 {0,} /* 0 terminated list. */
30052 };
30053 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
30054 index b6f47de..c5acf3a 100644
30055 --- a/drivers/edac/x38_edac.c
30056 +++ b/drivers/edac/x38_edac.c
30057 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
30058 edac_mc_free(mci);
30059 }
30060
30061 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
30062 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
30063 {
30064 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30065 X38},
30066 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30067 index 85661b0..c784559a 100644
30068 --- a/drivers/firewire/core-card.c
30069 +++ b/drivers/firewire/core-card.c
30070 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
30071
30072 void fw_core_remove_card(struct fw_card *card)
30073 {
30074 - struct fw_card_driver dummy_driver = dummy_driver_template;
30075 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30076
30077 card->driver->update_phy_reg(card, 4,
30078 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30079 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30080 index 4799393..37bd3ab 100644
30081 --- a/drivers/firewire/core-cdev.c
30082 +++ b/drivers/firewire/core-cdev.c
30083 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
30084 int ret;
30085
30086 if ((request->channels == 0 && request->bandwidth == 0) ||
30087 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30088 - request->bandwidth < 0)
30089 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30090 return -EINVAL;
30091
30092 r = kmalloc(sizeof(*r), GFP_KERNEL);
30093 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30094 index 855ab3f..11f4bbd 100644
30095 --- a/drivers/firewire/core-transaction.c
30096 +++ b/drivers/firewire/core-transaction.c
30097 @@ -37,6 +37,7 @@
30098 #include <linux/timer.h>
30099 #include <linux/types.h>
30100 #include <linux/workqueue.h>
30101 +#include <linux/sched.h>
30102
30103 #include <asm/byteorder.h>
30104
30105 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30106 index b45be57..5fad18b 100644
30107 --- a/drivers/firewire/core.h
30108 +++ b/drivers/firewire/core.h
30109 @@ -101,6 +101,7 @@ struct fw_card_driver {
30110
30111 int (*stop_iso)(struct fw_iso_context *ctx);
30112 };
30113 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30114
30115 void fw_card_initialize(struct fw_card *card,
30116 const struct fw_card_driver *driver, struct device *device);
30117 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30118 index 153980b..4b4d046 100644
30119 --- a/drivers/firmware/dmi_scan.c
30120 +++ b/drivers/firmware/dmi_scan.c
30121 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
30122 }
30123 }
30124 else {
30125 - /*
30126 - * no iounmap() for that ioremap(); it would be a no-op, but
30127 - * it's so early in setup that sucker gets confused into doing
30128 - * what it shouldn't if we actually call it.
30129 - */
30130 p = dmi_ioremap(0xF0000, 0x10000);
30131 if (p == NULL)
30132 goto error;
30133 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30134 if (buf == NULL)
30135 return -1;
30136
30137 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30138 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30139
30140 iounmap(buf);
30141 return 0;
30142 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30143 index 82d5c20..44a7177 100644
30144 --- a/drivers/gpio/gpio-vr41xx.c
30145 +++ b/drivers/gpio/gpio-vr41xx.c
30146 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30147 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30148 maskl, pendl, maskh, pendh);
30149
30150 - atomic_inc(&irq_err_count);
30151 + atomic_inc_unchecked(&irq_err_count);
30152
30153 return -EINVAL;
30154 }
30155 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30156 index 84a4a80..ce0306e 100644
30157 --- a/drivers/gpu/drm/drm_crtc_helper.c
30158 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30159 @@ -280,7 +280,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30160 struct drm_crtc *tmp;
30161 int crtc_mask = 1;
30162
30163 - WARN(!crtc, "checking null crtc?\n");
30164 + BUG_ON(!crtc);
30165
30166 dev = crtc->dev;
30167
30168 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30169 index ebf7d3f..d64c436 100644
30170 --- a/drivers/gpu/drm/drm_drv.c
30171 +++ b/drivers/gpu/drm/drm_drv.c
30172 @@ -312,7 +312,7 @@ module_exit(drm_core_exit);
30173 /**
30174 * Copy and IOCTL return string to user space
30175 */
30176 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30177 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30178 {
30179 int len;
30180
30181 @@ -391,7 +391,7 @@ long drm_ioctl(struct file *filp,
30182
30183 dev = file_priv->minor->dev;
30184 atomic_inc(&dev->ioctl_count);
30185 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30186 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30187 ++file_priv->ioctl_count;
30188
30189 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30190 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30191 index 6263b01..7987f55 100644
30192 --- a/drivers/gpu/drm/drm_fops.c
30193 +++ b/drivers/gpu/drm/drm_fops.c
30194 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30195 }
30196
30197 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30198 - atomic_set(&dev->counts[i], 0);
30199 + atomic_set_unchecked(&dev->counts[i], 0);
30200
30201 dev->sigdata.lock = NULL;
30202
30203 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
30204
30205 retcode = drm_open_helper(inode, filp, dev);
30206 if (!retcode) {
30207 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30208 - if (!dev->open_count++)
30209 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30210 + if (local_inc_return(&dev->open_count) == 1)
30211 retcode = drm_setup(dev);
30212 }
30213 if (!retcode) {
30214 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
30215
30216 mutex_lock(&drm_global_mutex);
30217
30218 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30219 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30220
30221 if (dev->driver->preclose)
30222 dev->driver->preclose(dev, file_priv);
30223 @@ -482,10 +482,10 @@ int drm_release(struct inode *inode, struct file *filp)
30224 * Begin inline drm_release
30225 */
30226
30227 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30228 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30229 task_pid_nr(current),
30230 (long)old_encode_dev(file_priv->minor->device),
30231 - dev->open_count);
30232 + local_read(&dev->open_count));
30233
30234 /* Release any auth tokens that might point to this file_priv,
30235 (do that under the drm_global_mutex) */
30236 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
30237 * End inline drm_release
30238 */
30239
30240 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30241 - if (!--dev->open_count) {
30242 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30243 + if (local_dec_and_test(&dev->open_count)) {
30244 if (atomic_read(&dev->ioctl_count)) {
30245 DRM_ERROR("Device busy: %d\n",
30246 atomic_read(&dev->ioctl_count));
30247 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30248 index c87dc96..326055d 100644
30249 --- a/drivers/gpu/drm/drm_global.c
30250 +++ b/drivers/gpu/drm/drm_global.c
30251 @@ -36,7 +36,7 @@
30252 struct drm_global_item {
30253 struct mutex mutex;
30254 void *object;
30255 - int refcount;
30256 + atomic_t refcount;
30257 };
30258
30259 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30260 @@ -49,7 +49,7 @@ void drm_global_init(void)
30261 struct drm_global_item *item = &glob[i];
30262 mutex_init(&item->mutex);
30263 item->object = NULL;
30264 - item->refcount = 0;
30265 + atomic_set(&item->refcount, 0);
30266 }
30267 }
30268
30269 @@ -59,7 +59,7 @@ void drm_global_release(void)
30270 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30271 struct drm_global_item *item = &glob[i];
30272 BUG_ON(item->object != NULL);
30273 - BUG_ON(item->refcount != 0);
30274 + BUG_ON(atomic_read(&item->refcount) != 0);
30275 }
30276 }
30277
30278 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30279 void *object;
30280
30281 mutex_lock(&item->mutex);
30282 - if (item->refcount == 0) {
30283 + if (atomic_read(&item->refcount) == 0) {
30284 item->object = kzalloc(ref->size, GFP_KERNEL);
30285 if (unlikely(item->object == NULL)) {
30286 ret = -ENOMEM;
30287 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30288 goto out_err;
30289
30290 }
30291 - ++item->refcount;
30292 + atomic_inc(&item->refcount);
30293 ref->object = item->object;
30294 object = item->object;
30295 mutex_unlock(&item->mutex);
30296 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30297 struct drm_global_item *item = &glob[ref->global_type];
30298
30299 mutex_lock(&item->mutex);
30300 - BUG_ON(item->refcount == 0);
30301 + BUG_ON(atomic_read(&item->refcount) == 0);
30302 BUG_ON(ref->object != item->object);
30303 - if (--item->refcount == 0) {
30304 + if (atomic_dec_and_test(&item->refcount)) {
30305 ref->release(ref);
30306 item->object = NULL;
30307 }
30308 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30309 index ab1162d..42587b2 100644
30310 --- a/drivers/gpu/drm/drm_info.c
30311 +++ b/drivers/gpu/drm/drm_info.c
30312 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30313 struct drm_local_map *map;
30314 struct drm_map_list *r_list;
30315
30316 - /* Hardcoded from _DRM_FRAME_BUFFER,
30317 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30318 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30319 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30320 + static const char * const types[] = {
30321 + [_DRM_FRAME_BUFFER] = "FB",
30322 + [_DRM_REGISTERS] = "REG",
30323 + [_DRM_SHM] = "SHM",
30324 + [_DRM_AGP] = "AGP",
30325 + [_DRM_SCATTER_GATHER] = "SG",
30326 + [_DRM_CONSISTENT] = "PCI",
30327 + [_DRM_GEM] = "GEM" };
30328 const char *type;
30329 int i;
30330
30331 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30332 map = r_list->map;
30333 if (!map)
30334 continue;
30335 - if (map->type < 0 || map->type > 5)
30336 + if (map->type >= ARRAY_SIZE(types))
30337 type = "??";
30338 else
30339 type = types[map->type];
30340 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30341 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30342 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30343 vma->vm_flags & VM_IO ? 'i' : '-',
30344 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30345 + 0);
30346 +#else
30347 vma->vm_pgoff);
30348 +#endif
30349
30350 #if defined(__i386__)
30351 pgprot = pgprot_val(vma->vm_page_prot);
30352 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30353 index 637fcc3..e890b33 100644
30354 --- a/drivers/gpu/drm/drm_ioc32.c
30355 +++ b/drivers/gpu/drm/drm_ioc32.c
30356 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30357 request = compat_alloc_user_space(nbytes);
30358 if (!access_ok(VERIFY_WRITE, request, nbytes))
30359 return -EFAULT;
30360 - list = (struct drm_buf_desc *) (request + 1);
30361 + list = (struct drm_buf_desc __user *) (request + 1);
30362
30363 if (__put_user(count, &request->count)
30364 || __put_user(list, &request->list))
30365 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30366 request = compat_alloc_user_space(nbytes);
30367 if (!access_ok(VERIFY_WRITE, request, nbytes))
30368 return -EFAULT;
30369 - list = (struct drm_buf_pub *) (request + 1);
30370 + list = (struct drm_buf_pub __user *) (request + 1);
30371
30372 if (__put_user(count, &request->count)
30373 || __put_user(list, &request->list))
30374 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30375 index 956fd38..e52167a 100644
30376 --- a/drivers/gpu/drm/drm_ioctl.c
30377 +++ b/drivers/gpu/drm/drm_ioctl.c
30378 @@ -251,7 +251,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30379 stats->data[i].value =
30380 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30381 else
30382 - stats->data[i].value = atomic_read(&dev->counts[i]);
30383 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30384 stats->data[i].type = dev->types[i];
30385 }
30386
30387 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30388 index c79c713..2048588 100644
30389 --- a/drivers/gpu/drm/drm_lock.c
30390 +++ b/drivers/gpu/drm/drm_lock.c
30391 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30392 if (drm_lock_take(&master->lock, lock->context)) {
30393 master->lock.file_priv = file_priv;
30394 master->lock.lock_time = jiffies;
30395 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30396 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30397 break; /* Got lock */
30398 }
30399
30400 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30401 return -EINVAL;
30402 }
30403
30404 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30405 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30406
30407 if (drm_lock_free(&master->lock, lock->context)) {
30408 /* FIXME: Should really bail out here. */
30409 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30410 index 7f4b4e1..bf4def2 100644
30411 --- a/drivers/gpu/drm/i810/i810_dma.c
30412 +++ b/drivers/gpu/drm/i810/i810_dma.c
30413 @@ -948,8 +948,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30414 dma->buflist[vertex->idx],
30415 vertex->discard, vertex->used);
30416
30417 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30418 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30419 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30420 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30421 sarea_priv->last_enqueue = dev_priv->counter - 1;
30422 sarea_priv->last_dispatch = (int)hw_status[5];
30423
30424 @@ -1109,8 +1109,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30425 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30426 mc->last_render);
30427
30428 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30429 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30430 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30431 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30432 sarea_priv->last_enqueue = dev_priv->counter - 1;
30433 sarea_priv->last_dispatch = (int)hw_status[5];
30434
30435 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30436 index c9339f4..f5e1b9d 100644
30437 --- a/drivers/gpu/drm/i810/i810_drv.h
30438 +++ b/drivers/gpu/drm/i810/i810_drv.h
30439 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30440 int page_flipping;
30441
30442 wait_queue_head_t irq_queue;
30443 - atomic_t irq_received;
30444 - atomic_t irq_emitted;
30445 + atomic_unchecked_t irq_received;
30446 + atomic_unchecked_t irq_emitted;
30447
30448 int front_offset;
30449 } drm_i810_private_t;
30450 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30451 index deaa657..e0fd296 100644
30452 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30453 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30454 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30455 I915_READ(GTIMR));
30456 }
30457 seq_printf(m, "Interrupts received: %d\n",
30458 - atomic_read(&dev_priv->irq_received));
30459 + atomic_read_unchecked(&dev_priv->irq_received));
30460 for (i = 0; i < I915_NUM_RINGS; i++) {
30461 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30462 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30463 @@ -1321,7 +1321,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30464 return ret;
30465
30466 if (opregion->header)
30467 - seq_write(m, opregion->header, OPREGION_SIZE);
30468 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30469
30470 mutex_unlock(&dev->struct_mutex);
30471
30472 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30473 index ddfe3d9..f6e6b21 100644
30474 --- a/drivers/gpu/drm/i915/i915_dma.c
30475 +++ b/drivers/gpu/drm/i915/i915_dma.c
30476 @@ -1175,7 +1175,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30477 bool can_switch;
30478
30479 spin_lock(&dev->count_lock);
30480 - can_switch = (dev->open_count == 0);
30481 + can_switch = (local_read(&dev->open_count) == 0);
30482 spin_unlock(&dev->count_lock);
30483 return can_switch;
30484 }
30485 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30486 index 9689ca3..294f9c1 100644
30487 --- a/drivers/gpu/drm/i915/i915_drv.h
30488 +++ b/drivers/gpu/drm/i915/i915_drv.h
30489 @@ -231,7 +231,7 @@ struct drm_i915_display_funcs {
30490 /* render clock increase/decrease */
30491 /* display clock increase/decrease */
30492 /* pll clock increase/decrease */
30493 -};
30494 +} __no_const;
30495
30496 struct intel_device_info {
30497 u8 gen;
30498 @@ -320,7 +320,7 @@ typedef struct drm_i915_private {
30499 int current_page;
30500 int page_flipping;
30501
30502 - atomic_t irq_received;
30503 + atomic_unchecked_t irq_received;
30504
30505 /* protects the irq masks */
30506 spinlock_t irq_lock;
30507 @@ -896,7 +896,7 @@ struct drm_i915_gem_object {
30508 * will be page flipped away on the next vblank. When it
30509 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30510 */
30511 - atomic_t pending_flip;
30512 + atomic_unchecked_t pending_flip;
30513 };
30514
30515 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30516 @@ -1276,7 +1276,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30517 extern void intel_teardown_gmbus(struct drm_device *dev);
30518 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30519 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30520 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30521 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30522 {
30523 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30524 }
30525 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30526 index e159e33..cdcc663 100644
30527 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30528 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30529 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30530 i915_gem_clflush_object(obj);
30531
30532 if (obj->base.pending_write_domain)
30533 - cd->flips |= atomic_read(&obj->pending_flip);
30534 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30535
30536 /* The actual obj->write_domain will be updated with
30537 * pending_write_domain after we emit the accumulated flush for all
30538 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30539
30540 static int
30541 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30542 - int count)
30543 + unsigned int count)
30544 {
30545 - int i;
30546 + unsigned int i;
30547
30548 for (i = 0; i < count; i++) {
30549 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30550 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30551 index 5bd4361..0241a42 100644
30552 --- a/drivers/gpu/drm/i915/i915_irq.c
30553 +++ b/drivers/gpu/drm/i915/i915_irq.c
30554 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30555 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30556 struct drm_i915_master_private *master_priv;
30557
30558 - atomic_inc(&dev_priv->irq_received);
30559 + atomic_inc_unchecked(&dev_priv->irq_received);
30560
30561 /* disable master interrupt before clearing iir */
30562 de_ier = I915_READ(DEIER);
30563 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30564 struct drm_i915_master_private *master_priv;
30565 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30566
30567 - atomic_inc(&dev_priv->irq_received);
30568 + atomic_inc_unchecked(&dev_priv->irq_received);
30569
30570 if (IS_GEN6(dev))
30571 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30572 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30573 int ret = IRQ_NONE, pipe;
30574 bool blc_event = false;
30575
30576 - atomic_inc(&dev_priv->irq_received);
30577 + atomic_inc_unchecked(&dev_priv->irq_received);
30578
30579 iir = I915_READ(IIR);
30580
30581 @@ -1743,7 +1743,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30582 {
30583 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30584
30585 - atomic_set(&dev_priv->irq_received, 0);
30586 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30587
30588 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30589 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30590 @@ -1932,7 +1932,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30591 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30592 int pipe;
30593
30594 - atomic_set(&dev_priv->irq_received, 0);
30595 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30596
30597 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30598 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30599 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30600 index 2163818..cede019 100644
30601 --- a/drivers/gpu/drm/i915/intel_display.c
30602 +++ b/drivers/gpu/drm/i915/intel_display.c
30603 @@ -2238,7 +2238,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
30604
30605 wait_event(dev_priv->pending_flip_queue,
30606 atomic_read(&dev_priv->mm.wedged) ||
30607 - atomic_read(&obj->pending_flip) == 0);
30608 + atomic_read_unchecked(&obj->pending_flip) == 0);
30609
30610 /* Big Hammer, we also need to ensure that any pending
30611 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30612 @@ -2859,7 +2859,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30613 obj = to_intel_framebuffer(crtc->fb)->obj;
30614 dev_priv = crtc->dev->dev_private;
30615 wait_event(dev_priv->pending_flip_queue,
30616 - atomic_read(&obj->pending_flip) == 0);
30617 + atomic_read_unchecked(&obj->pending_flip) == 0);
30618 }
30619
30620 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30621 @@ -7171,7 +7171,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30622
30623 atomic_clear_mask(1 << intel_crtc->plane,
30624 &obj->pending_flip.counter);
30625 - if (atomic_read(&obj->pending_flip) == 0)
30626 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30627 wake_up(&dev_priv->pending_flip_queue);
30628
30629 schedule_work(&work->work);
30630 @@ -7354,7 +7354,13 @@ static int intel_gen6_queue_flip(struct drm_device *dev,
30631 OUT_RING(fb->pitches[0] | obj->tiling_mode);
30632 OUT_RING(obj->gtt_offset);
30633
30634 - pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
30635 + /* Contrary to the suggestions in the documentation,
30636 + * "Enable Panel Fitter" does not seem to be required when page
30637 + * flipping with a non-native mode, and worse causes a normal
30638 + * modeset to fail.
30639 + * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
30640 + */
30641 + pf = 0;
30642 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
30643 OUT_RING(pf | pipesrc);
30644 ADVANCE_LP_RING();
30645 @@ -7461,7 +7467,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30646 /* Block clients from rendering to the new back buffer until
30647 * the flip occurs and the object is no longer visible.
30648 */
30649 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30650 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30651
30652 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30653 if (ret)
30654 @@ -7475,7 +7481,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30655 return 0;
30656
30657 cleanup_pending:
30658 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30659 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30660 drm_gem_object_unreference(&work->old_fb_obj->base);
30661 drm_gem_object_unreference(&obj->base);
30662 mutex_unlock(&dev->struct_mutex);
30663 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30664 index 54558a0..2d97005 100644
30665 --- a/drivers/gpu/drm/mga/mga_drv.h
30666 +++ b/drivers/gpu/drm/mga/mga_drv.h
30667 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30668 u32 clear_cmd;
30669 u32 maccess;
30670
30671 - atomic_t vbl_received; /**< Number of vblanks received. */
30672 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30673 wait_queue_head_t fence_queue;
30674 - atomic_t last_fence_retired;
30675 + atomic_unchecked_t last_fence_retired;
30676 u32 next_fence_to_post;
30677
30678 unsigned int fb_cpp;
30679 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30680 index 2581202..f230a8d9 100644
30681 --- a/drivers/gpu/drm/mga/mga_irq.c
30682 +++ b/drivers/gpu/drm/mga/mga_irq.c
30683 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30684 if (crtc != 0)
30685 return 0;
30686
30687 - return atomic_read(&dev_priv->vbl_received);
30688 + return atomic_read_unchecked(&dev_priv->vbl_received);
30689 }
30690
30691
30692 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30693 /* VBLANK interrupt */
30694 if (status & MGA_VLINEPEN) {
30695 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30696 - atomic_inc(&dev_priv->vbl_received);
30697 + atomic_inc_unchecked(&dev_priv->vbl_received);
30698 drm_handle_vblank(dev, 0);
30699 handled = 1;
30700 }
30701 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30702 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30703 MGA_WRITE(MGA_PRIMEND, prim_end);
30704
30705 - atomic_inc(&dev_priv->last_fence_retired);
30706 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30707 DRM_WAKEUP(&dev_priv->fence_queue);
30708 handled = 1;
30709 }
30710 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30711 * using fences.
30712 */
30713 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30714 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30715 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30716 - *sequence) <= (1 << 23)));
30717
30718 *sequence = cur_fence;
30719 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30720 index e5cbead..6c354a3 100644
30721 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30722 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30723 @@ -199,7 +199,7 @@ struct methods {
30724 const char desc[8];
30725 void (*loadbios)(struct drm_device *, uint8_t *);
30726 const bool rw;
30727 -};
30728 +} __do_const;
30729
30730 static struct methods shadow_methods[] = {
30731 { "PRAMIN", load_vbios_pramin, true },
30732 @@ -5290,7 +5290,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30733 struct bit_table {
30734 const char id;
30735 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30736 -};
30737 +} __no_const;
30738
30739 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30740
30741 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30742 index b827098..c31a797 100644
30743 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30744 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30745 @@ -242,7 +242,7 @@ struct nouveau_channel {
30746 struct list_head pending;
30747 uint32_t sequence;
30748 uint32_t sequence_ack;
30749 - atomic_t last_sequence_irq;
30750 + atomic_unchecked_t last_sequence_irq;
30751 struct nouveau_vma vma;
30752 } fence;
30753
30754 @@ -323,7 +323,7 @@ struct nouveau_exec_engine {
30755 u32 handle, u16 class);
30756 void (*set_tile_region)(struct drm_device *dev, int i);
30757 void (*tlb_flush)(struct drm_device *, int engine);
30758 -};
30759 +} __no_const;
30760
30761 struct nouveau_instmem_engine {
30762 void *priv;
30763 @@ -345,13 +345,13 @@ struct nouveau_instmem_engine {
30764 struct nouveau_mc_engine {
30765 int (*init)(struct drm_device *dev);
30766 void (*takedown)(struct drm_device *dev);
30767 -};
30768 +} __no_const;
30769
30770 struct nouveau_timer_engine {
30771 int (*init)(struct drm_device *dev);
30772 void (*takedown)(struct drm_device *dev);
30773 uint64_t (*read)(struct drm_device *dev);
30774 -};
30775 +} __no_const;
30776
30777 struct nouveau_fb_engine {
30778 int num_tiles;
30779 @@ -566,7 +566,7 @@ struct nouveau_vram_engine {
30780 void (*put)(struct drm_device *, struct nouveau_mem **);
30781
30782 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30783 -};
30784 +} __no_const;
30785
30786 struct nouveau_engine {
30787 struct nouveau_instmem_engine instmem;
30788 @@ -714,7 +714,7 @@ struct drm_nouveau_private {
30789 struct drm_global_reference mem_global_ref;
30790 struct ttm_bo_global_ref bo_global_ref;
30791 struct ttm_bo_device bdev;
30792 - atomic_t validate_sequence;
30793 + atomic_unchecked_t validate_sequence;
30794 } ttm;
30795
30796 struct {
30797 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30798 index 2f6daae..c9d7b9e 100644
30799 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30800 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30801 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30802 if (USE_REFCNT(dev))
30803 sequence = nvchan_rd32(chan, 0x48);
30804 else
30805 - sequence = atomic_read(&chan->fence.last_sequence_irq);
30806 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30807
30808 if (chan->fence.sequence_ack == sequence)
30809 goto out;
30810 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30811 return ret;
30812 }
30813
30814 - atomic_set(&chan->fence.last_sequence_irq, 0);
30815 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30816 return 0;
30817 }
30818
30819 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30820 index 7ce3fde..cb3ea04 100644
30821 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30822 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30823 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30824 int trycnt = 0;
30825 int ret, i;
30826
30827 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30828 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30829 retry:
30830 if (++trycnt > 100000) {
30831 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30832 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30833 index f80c5e0..936baa7 100644
30834 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30835 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30836 @@ -543,7 +543,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30837 bool can_switch;
30838
30839 spin_lock(&dev->count_lock);
30840 - can_switch = (dev->open_count == 0);
30841 + can_switch = (local_read(&dev->open_count) == 0);
30842 spin_unlock(&dev->count_lock);
30843 return can_switch;
30844 }
30845 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30846 index dbdea8e..cd6eeeb 100644
30847 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
30848 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30849 @@ -554,7 +554,7 @@ static int
30850 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30851 u32 class, u32 mthd, u32 data)
30852 {
30853 - atomic_set(&chan->fence.last_sequence_irq, data);
30854 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30855 return 0;
30856 }
30857
30858 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30859 index bcac90b..53bfc76 100644
30860 --- a/drivers/gpu/drm/r128/r128_cce.c
30861 +++ b/drivers/gpu/drm/r128/r128_cce.c
30862 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30863
30864 /* GH: Simple idle check.
30865 */
30866 - atomic_set(&dev_priv->idle_count, 0);
30867 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30868
30869 /* We don't support anything other than bus-mastering ring mode,
30870 * but the ring can be in either AGP or PCI space for the ring
30871 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30872 index 930c71b..499aded 100644
30873 --- a/drivers/gpu/drm/r128/r128_drv.h
30874 +++ b/drivers/gpu/drm/r128/r128_drv.h
30875 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30876 int is_pci;
30877 unsigned long cce_buffers_offset;
30878
30879 - atomic_t idle_count;
30880 + atomic_unchecked_t idle_count;
30881
30882 int page_flipping;
30883 int current_page;
30884 u32 crtc_offset;
30885 u32 crtc_offset_cntl;
30886
30887 - atomic_t vbl_received;
30888 + atomic_unchecked_t vbl_received;
30889
30890 u32 color_fmt;
30891 unsigned int front_offset;
30892 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30893 index 429d5a0..7e899ed 100644
30894 --- a/drivers/gpu/drm/r128/r128_irq.c
30895 +++ b/drivers/gpu/drm/r128/r128_irq.c
30896 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30897 if (crtc != 0)
30898 return 0;
30899
30900 - return atomic_read(&dev_priv->vbl_received);
30901 + return atomic_read_unchecked(&dev_priv->vbl_received);
30902 }
30903
30904 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30905 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30906 /* VBLANK interrupt */
30907 if (status & R128_CRTC_VBLANK_INT) {
30908 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30909 - atomic_inc(&dev_priv->vbl_received);
30910 + atomic_inc_unchecked(&dev_priv->vbl_received);
30911 drm_handle_vblank(dev, 0);
30912 return IRQ_HANDLED;
30913 }
30914 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30915 index a9e33ce..09edd4b 100644
30916 --- a/drivers/gpu/drm/r128/r128_state.c
30917 +++ b/drivers/gpu/drm/r128/r128_state.c
30918 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30919
30920 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30921 {
30922 - if (atomic_read(&dev_priv->idle_count) == 0)
30923 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30924 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30925 else
30926 - atomic_set(&dev_priv->idle_count, 0);
30927 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30928 }
30929
30930 #endif
30931 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30932 index 5a82b6b..9e69c73 100644
30933 --- a/drivers/gpu/drm/radeon/mkregtable.c
30934 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30935 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30936 regex_t mask_rex;
30937 regmatch_t match[4];
30938 char buf[1024];
30939 - size_t end;
30940 + long end;
30941 int len;
30942 int done = 0;
30943 int r;
30944 unsigned o;
30945 struct offset *offset;
30946 char last_reg_s[10];
30947 - int last_reg;
30948 + unsigned long last_reg;
30949
30950 if (regcomp
30951 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30952 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30953 index 1668ec1..30ebdab 100644
30954 --- a/drivers/gpu/drm/radeon/radeon.h
30955 +++ b/drivers/gpu/drm/radeon/radeon.h
30956 @@ -250,7 +250,7 @@ struct radeon_fence_driver {
30957 uint32_t scratch_reg;
30958 uint64_t gpu_addr;
30959 volatile uint32_t *cpu_addr;
30960 - atomic_t seq;
30961 + atomic_unchecked_t seq;
30962 uint32_t last_seq;
30963 unsigned long last_jiffies;
30964 unsigned long last_timeout;
30965 @@ -752,7 +752,7 @@ struct r600_blit_cp_primitives {
30966 int x2, int y2);
30967 void (*draw_auto)(struct radeon_device *rdev);
30968 void (*set_default_state)(struct radeon_device *rdev);
30969 -};
30970 +} __no_const;
30971
30972 struct r600_blit {
30973 struct mutex mutex;
30974 @@ -1201,7 +1201,7 @@ struct radeon_asic {
30975 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
30976 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30977 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30978 -};
30979 +} __no_const;
30980
30981 /*
30982 * Asic structures
30983 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30984 index 49f7cb7..2fcb48f 100644
30985 --- a/drivers/gpu/drm/radeon/radeon_device.c
30986 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30987 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30988 bool can_switch;
30989
30990 spin_lock(&dev->count_lock);
30991 - can_switch = (dev->open_count == 0);
30992 + can_switch = (local_read(&dev->open_count) == 0);
30993 spin_unlock(&dev->count_lock);
30994 return can_switch;
30995 }
30996 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30997 index a1b59ca..86f2d44 100644
30998 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30999 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31000 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31001
31002 /* SW interrupt */
31003 wait_queue_head_t swi_queue;
31004 - atomic_t swi_emitted;
31005 + atomic_unchecked_t swi_emitted;
31006 int vblank_crtc;
31007 uint32_t irq_enable_reg;
31008 uint32_t r500_disp_irq_reg;
31009 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
31010 index 4bd36a3..e66fe9c 100644
31011 --- a/drivers/gpu/drm/radeon/radeon_fence.c
31012 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
31013 @@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
31014 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
31015 return 0;
31016 }
31017 - fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
31018 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
31019 if (!rdev->ring[fence->ring].ready)
31020 /* FIXME: cp is not running assume everythings is done right
31021 * away
31022 @@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
31023 }
31024 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
31025 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
31026 - radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
31027 + radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
31028 rdev->fence_drv[ring].initialized = true;
31029 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
31030 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
31031 @@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
31032 rdev->fence_drv[ring].scratch_reg = -1;
31033 rdev->fence_drv[ring].cpu_addr = NULL;
31034 rdev->fence_drv[ring].gpu_addr = 0;
31035 - atomic_set(&rdev->fence_drv[ring].seq, 0);
31036 + atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
31037 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
31038 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
31039 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
31040 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31041 index 48b7cea..342236f 100644
31042 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31043 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31044 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31045 request = compat_alloc_user_space(sizeof(*request));
31046 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31047 || __put_user(req32.param, &request->param)
31048 - || __put_user((void __user *)(unsigned long)req32.value,
31049 + || __put_user((unsigned long)req32.value,
31050 &request->value))
31051 return -EFAULT;
31052
31053 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31054 index 00da384..32f972d 100644
31055 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31056 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31057 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31058 unsigned int ret;
31059 RING_LOCALS;
31060
31061 - atomic_inc(&dev_priv->swi_emitted);
31062 - ret = atomic_read(&dev_priv->swi_emitted);
31063 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31064 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31065
31066 BEGIN_RING(4);
31067 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31068 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31069 drm_radeon_private_t *dev_priv =
31070 (drm_radeon_private_t *) dev->dev_private;
31071
31072 - atomic_set(&dev_priv->swi_emitted, 0);
31073 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31074 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31075
31076 dev->max_vblank_count = 0x001fffff;
31077 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31078 index e8422ae..d22d4a8 100644
31079 --- a/drivers/gpu/drm/radeon/radeon_state.c
31080 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31081 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31082 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31083 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31084
31085 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31086 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31087 sarea_priv->nbox * sizeof(depth_boxes[0])))
31088 return -EFAULT;
31089
31090 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31091 {
31092 drm_radeon_private_t *dev_priv = dev->dev_private;
31093 drm_radeon_getparam_t *param = data;
31094 - int value;
31095 + int value = 0;
31096
31097 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31098
31099 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31100 index c421e77..e6bf2e8 100644
31101 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31102 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31103 @@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31104 }
31105 if (unlikely(ttm_vm_ops == NULL)) {
31106 ttm_vm_ops = vma->vm_ops;
31107 - radeon_ttm_vm_ops = *ttm_vm_ops;
31108 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31109 + pax_open_kernel();
31110 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31111 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31112 + pax_close_kernel();
31113 }
31114 vma->vm_ops = &radeon_ttm_vm_ops;
31115 return 0;
31116 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31117 index f68dff2..8df955c 100644
31118 --- a/drivers/gpu/drm/radeon/rs690.c
31119 +++ b/drivers/gpu/drm/radeon/rs690.c
31120 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31121 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31122 rdev->pm.sideport_bandwidth.full)
31123 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31124 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31125 + read_delay_latency.full = dfixed_const(800 * 1000);
31126 read_delay_latency.full = dfixed_div(read_delay_latency,
31127 rdev->pm.igp_sideport_mclk);
31128 + a.full = dfixed_const(370);
31129 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31130 } else {
31131 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31132 rdev->pm.k8_bandwidth.full)
31133 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31134 index 499debd..66fce72 100644
31135 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31136 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31137 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
31138 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31139 struct shrink_control *sc)
31140 {
31141 - static atomic_t start_pool = ATOMIC_INIT(0);
31142 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31143 unsigned i;
31144 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31145 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31146 struct ttm_page_pool *pool;
31147 int shrink_pages = sc->nr_to_scan;
31148
31149 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31150 index 88edacc..1e5412b 100644
31151 --- a/drivers/gpu/drm/via/via_drv.h
31152 +++ b/drivers/gpu/drm/via/via_drv.h
31153 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31154 typedef uint32_t maskarray_t[5];
31155
31156 typedef struct drm_via_irq {
31157 - atomic_t irq_received;
31158 + atomic_unchecked_t irq_received;
31159 uint32_t pending_mask;
31160 uint32_t enable_mask;
31161 wait_queue_head_t irq_queue;
31162 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31163 struct timeval last_vblank;
31164 int last_vblank_valid;
31165 unsigned usec_per_vblank;
31166 - atomic_t vbl_received;
31167 + atomic_unchecked_t vbl_received;
31168 drm_via_state_t hc_state;
31169 char pci_buf[VIA_PCI_BUF_SIZE];
31170 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31171 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31172 index d391f48..10c8ca3 100644
31173 --- a/drivers/gpu/drm/via/via_irq.c
31174 +++ b/drivers/gpu/drm/via/via_irq.c
31175 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31176 if (crtc != 0)
31177 return 0;
31178
31179 - return atomic_read(&dev_priv->vbl_received);
31180 + return atomic_read_unchecked(&dev_priv->vbl_received);
31181 }
31182
31183 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31184 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31185
31186 status = VIA_READ(VIA_REG_INTERRUPT);
31187 if (status & VIA_IRQ_VBLANK_PENDING) {
31188 - atomic_inc(&dev_priv->vbl_received);
31189 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31190 + atomic_inc_unchecked(&dev_priv->vbl_received);
31191 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31192 do_gettimeofday(&cur_vblank);
31193 if (dev_priv->last_vblank_valid) {
31194 dev_priv->usec_per_vblank =
31195 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31196 dev_priv->last_vblank = cur_vblank;
31197 dev_priv->last_vblank_valid = 1;
31198 }
31199 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31200 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31201 DRM_DEBUG("US per vblank is: %u\n",
31202 dev_priv->usec_per_vblank);
31203 }
31204 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31205
31206 for (i = 0; i < dev_priv->num_irqs; ++i) {
31207 if (status & cur_irq->pending_mask) {
31208 - atomic_inc(&cur_irq->irq_received);
31209 + atomic_inc_unchecked(&cur_irq->irq_received);
31210 DRM_WAKEUP(&cur_irq->irq_queue);
31211 handled = 1;
31212 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31213 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31214 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31215 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31216 masks[irq][4]));
31217 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31218 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31219 } else {
31220 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31221 (((cur_irq_sequence =
31222 - atomic_read(&cur_irq->irq_received)) -
31223 + atomic_read_unchecked(&cur_irq->irq_received)) -
31224 *sequence) <= (1 << 23)));
31225 }
31226 *sequence = cur_irq_sequence;
31227 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31228 }
31229
31230 for (i = 0; i < dev_priv->num_irqs; ++i) {
31231 - atomic_set(&cur_irq->irq_received, 0);
31232 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31233 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31234 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31235 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31236 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31237 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31238 case VIA_IRQ_RELATIVE:
31239 irqwait->request.sequence +=
31240 - atomic_read(&cur_irq->irq_received);
31241 + atomic_read_unchecked(&cur_irq->irq_received);
31242 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31243 case VIA_IRQ_ABSOLUTE:
31244 break;
31245 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31246 index dc27970..f18b008 100644
31247 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31248 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31249 @@ -260,7 +260,7 @@ struct vmw_private {
31250 * Fencing and IRQs.
31251 */
31252
31253 - atomic_t marker_seq;
31254 + atomic_unchecked_t marker_seq;
31255 wait_queue_head_t fence_queue;
31256 wait_queue_head_t fifo_queue;
31257 int fence_queue_waiters; /* Protected by hw_mutex */
31258 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31259 index a0c2f12..68ae6cb 100644
31260 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31261 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31262 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31263 (unsigned int) min,
31264 (unsigned int) fifo->capabilities);
31265
31266 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31267 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31268 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31269 vmw_marker_queue_init(&fifo->marker_queue);
31270 return vmw_fifo_send_fence(dev_priv, &dummy);
31271 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31272 if (reserveable)
31273 iowrite32(bytes, fifo_mem +
31274 SVGA_FIFO_RESERVED);
31275 - return fifo_mem + (next_cmd >> 2);
31276 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31277 } else {
31278 need_bounce = true;
31279 }
31280 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31281
31282 fm = vmw_fifo_reserve(dev_priv, bytes);
31283 if (unlikely(fm == NULL)) {
31284 - *seqno = atomic_read(&dev_priv->marker_seq);
31285 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31286 ret = -ENOMEM;
31287 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31288 false, 3*HZ);
31289 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31290 }
31291
31292 do {
31293 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31294 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31295 } while (*seqno == 0);
31296
31297 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31298 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31299 index cabc95f..14b3d77 100644
31300 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31301 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31302 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31303 * emitted. Then the fence is stale and signaled.
31304 */
31305
31306 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31307 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31308 > VMW_FENCE_WRAP);
31309
31310 return ret;
31311 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31312
31313 if (fifo_idle)
31314 down_read(&fifo_state->rwsem);
31315 - signal_seq = atomic_read(&dev_priv->marker_seq);
31316 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31317 ret = 0;
31318
31319 for (;;) {
31320 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31321 index 8a8725c..afed796 100644
31322 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31323 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31324 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31325 while (!vmw_lag_lt(queue, us)) {
31326 spin_lock(&queue->lock);
31327 if (list_empty(&queue->head))
31328 - seqno = atomic_read(&dev_priv->marker_seq);
31329 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31330 else {
31331 marker = list_first_entry(&queue->head,
31332 struct vmw_marker, head);
31333 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31334 index 75dbe34..f9204a8 100644
31335 --- a/drivers/hid/hid-core.c
31336 +++ b/drivers/hid/hid-core.c
31337 @@ -2021,7 +2021,7 @@ static bool hid_ignore(struct hid_device *hdev)
31338
31339 int hid_add_device(struct hid_device *hdev)
31340 {
31341 - static atomic_t id = ATOMIC_INIT(0);
31342 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31343 int ret;
31344
31345 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31346 @@ -2036,7 +2036,7 @@ int hid_add_device(struct hid_device *hdev)
31347 /* XXX hack, any other cleaner solution after the driver core
31348 * is converted to allow more than 20 bytes as the device name? */
31349 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31350 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31351 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31352
31353 hid_debug_register(hdev, dev_name(&hdev->dev));
31354 ret = device_add(&hdev->dev);
31355 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31356 index b1ec0e2..c295a61 100644
31357 --- a/drivers/hid/usbhid/hiddev.c
31358 +++ b/drivers/hid/usbhid/hiddev.c
31359 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31360 break;
31361
31362 case HIDIOCAPPLICATION:
31363 - if (arg < 0 || arg >= hid->maxapplication)
31364 + if (arg >= hid->maxapplication)
31365 break;
31366
31367 for (i = 0; i < hid->maxcollection; i++)
31368 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31369 index 4065374..10ed7dc 100644
31370 --- a/drivers/hv/channel.c
31371 +++ b/drivers/hv/channel.c
31372 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31373 int ret = 0;
31374 int t;
31375
31376 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31377 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31378 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31379 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31380
31381 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31382 if (ret)
31383 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31384 index 12aa97f..c0679f7 100644
31385 --- a/drivers/hv/hv.c
31386 +++ b/drivers/hv/hv.c
31387 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31388 u64 output_address = (output) ? virt_to_phys(output) : 0;
31389 u32 output_address_hi = output_address >> 32;
31390 u32 output_address_lo = output_address & 0xFFFFFFFF;
31391 - void *hypercall_page = hv_context.hypercall_page;
31392 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31393
31394 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31395 "=a"(hv_status_lo) : "d" (control_hi),
31396 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31397 index 6d7d286..92b0873 100644
31398 --- a/drivers/hv/hyperv_vmbus.h
31399 +++ b/drivers/hv/hyperv_vmbus.h
31400 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
31401 struct vmbus_connection {
31402 enum vmbus_connect_state conn_state;
31403
31404 - atomic_t next_gpadl_handle;
31405 + atomic_unchecked_t next_gpadl_handle;
31406
31407 /*
31408 * Represents channel interrupts. Each bit position represents a
31409 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31410 index a220e57..428f54d 100644
31411 --- a/drivers/hv/vmbus_drv.c
31412 +++ b/drivers/hv/vmbus_drv.c
31413 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31414 {
31415 int ret = 0;
31416
31417 - static atomic_t device_num = ATOMIC_INIT(0);
31418 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31419
31420 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31421 - atomic_inc_return(&device_num));
31422 + atomic_inc_return_unchecked(&device_num));
31423
31424 child_device_obj->device.bus = &hv_bus;
31425 child_device_obj->device.parent = &hv_acpi_dev->dev;
31426 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31427 index 554f046..f8b4729 100644
31428 --- a/drivers/hwmon/acpi_power_meter.c
31429 +++ b/drivers/hwmon/acpi_power_meter.c
31430 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31431 return res;
31432
31433 temp /= 1000;
31434 - if (temp < 0)
31435 - return -EINVAL;
31436
31437 mutex_lock(&resource->lock);
31438 resource->trip[attr->index - 7] = temp;
31439 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31440 index 91fdd1f..b66a686 100644
31441 --- a/drivers/hwmon/sht15.c
31442 +++ b/drivers/hwmon/sht15.c
31443 @@ -166,7 +166,7 @@ struct sht15_data {
31444 int supply_uV;
31445 bool supply_uV_valid;
31446 struct work_struct update_supply_work;
31447 - atomic_t interrupt_handled;
31448 + atomic_unchecked_t interrupt_handled;
31449 };
31450
31451 /**
31452 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31453 return ret;
31454
31455 gpio_direction_input(data->pdata->gpio_data);
31456 - atomic_set(&data->interrupt_handled, 0);
31457 + atomic_set_unchecked(&data->interrupt_handled, 0);
31458
31459 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31460 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31461 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31462 /* Only relevant if the interrupt hasn't occurred. */
31463 - if (!atomic_read(&data->interrupt_handled))
31464 + if (!atomic_read_unchecked(&data->interrupt_handled))
31465 schedule_work(&data->read_work);
31466 }
31467 ret = wait_event_timeout(data->wait_queue,
31468 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31469
31470 /* First disable the interrupt */
31471 disable_irq_nosync(irq);
31472 - atomic_inc(&data->interrupt_handled);
31473 + atomic_inc_unchecked(&data->interrupt_handled);
31474 /* Then schedule a reading work struct */
31475 if (data->state != SHT15_READING_NOTHING)
31476 schedule_work(&data->read_work);
31477 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31478 * If not, then start the interrupt again - care here as could
31479 * have gone low in meantime so verify it hasn't!
31480 */
31481 - atomic_set(&data->interrupt_handled, 0);
31482 + atomic_set_unchecked(&data->interrupt_handled, 0);
31483 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31484 /* If still not occurred or another handler has been scheduled */
31485 if (gpio_get_value(data->pdata->gpio_data)
31486 - || atomic_read(&data->interrupt_handled))
31487 + || atomic_read_unchecked(&data->interrupt_handled))
31488 return;
31489 }
31490
31491 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31492 index 378fcb5..5e91fa8 100644
31493 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31494 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31495 @@ -43,7 +43,7 @@
31496 extern struct i2c_adapter amd756_smbus;
31497
31498 static struct i2c_adapter *s4882_adapter;
31499 -static struct i2c_algorithm *s4882_algo;
31500 +static i2c_algorithm_no_const *s4882_algo;
31501
31502 /* Wrapper access functions for multiplexed SMBus */
31503 static DEFINE_MUTEX(amd756_lock);
31504 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31505 index 29015eb..af2d8e9 100644
31506 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31507 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31508 @@ -41,7 +41,7 @@
31509 extern struct i2c_adapter *nforce2_smbus;
31510
31511 static struct i2c_adapter *s4985_adapter;
31512 -static struct i2c_algorithm *s4985_algo;
31513 +static i2c_algorithm_no_const *s4985_algo;
31514
31515 /* Wrapper access functions for multiplexed SMBus */
31516 static DEFINE_MUTEX(nforce2_lock);
31517 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31518 index d7a4833..7fae376 100644
31519 --- a/drivers/i2c/i2c-mux.c
31520 +++ b/drivers/i2c/i2c-mux.c
31521 @@ -28,7 +28,7 @@
31522 /* multiplexer per channel data */
31523 struct i2c_mux_priv {
31524 struct i2c_adapter adap;
31525 - struct i2c_algorithm algo;
31526 + i2c_algorithm_no_const algo;
31527
31528 struct i2c_adapter *parent;
31529 void *mux_dev; /* the mux chip/device */
31530 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31531 index 57d00ca..0145194 100644
31532 --- a/drivers/ide/aec62xx.c
31533 +++ b/drivers/ide/aec62xx.c
31534 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31535 .cable_detect = atp86x_cable_detect,
31536 };
31537
31538 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31539 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31540 { /* 0: AEC6210 */
31541 .name = DRV_NAME,
31542 .init_chipset = init_chipset_aec62xx,
31543 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31544 index 2c8016a..911a27c 100644
31545 --- a/drivers/ide/alim15x3.c
31546 +++ b/drivers/ide/alim15x3.c
31547 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31548 .dma_sff_read_status = ide_dma_sff_read_status,
31549 };
31550
31551 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31552 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31553 .name = DRV_NAME,
31554 .init_chipset = init_chipset_ali15x3,
31555 .init_hwif = init_hwif_ali15x3,
31556 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31557 index 3747b25..56fc995 100644
31558 --- a/drivers/ide/amd74xx.c
31559 +++ b/drivers/ide/amd74xx.c
31560 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31561 .udma_mask = udma, \
31562 }
31563
31564 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31565 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31566 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31567 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31568 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31569 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31570 index 15f0ead..cb43480 100644
31571 --- a/drivers/ide/atiixp.c
31572 +++ b/drivers/ide/atiixp.c
31573 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31574 .cable_detect = atiixp_cable_detect,
31575 };
31576
31577 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31578 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31579 { /* 0: IXP200/300/400/700 */
31580 .name = DRV_NAME,
31581 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31582 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31583 index 5f80312..d1fc438 100644
31584 --- a/drivers/ide/cmd64x.c
31585 +++ b/drivers/ide/cmd64x.c
31586 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31587 .dma_sff_read_status = ide_dma_sff_read_status,
31588 };
31589
31590 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31591 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31592 { /* 0: CMD643 */
31593 .name = DRV_NAME,
31594 .init_chipset = init_chipset_cmd64x,
31595 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31596 index 2c1e5f7..1444762 100644
31597 --- a/drivers/ide/cs5520.c
31598 +++ b/drivers/ide/cs5520.c
31599 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31600 .set_dma_mode = cs5520_set_dma_mode,
31601 };
31602
31603 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31604 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31605 .name = DRV_NAME,
31606 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31607 .port_ops = &cs5520_port_ops,
31608 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31609 index 4dc4eb9..49b40ad 100644
31610 --- a/drivers/ide/cs5530.c
31611 +++ b/drivers/ide/cs5530.c
31612 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31613 .udma_filter = cs5530_udma_filter,
31614 };
31615
31616 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31617 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31618 .name = DRV_NAME,
31619 .init_chipset = init_chipset_cs5530,
31620 .init_hwif = init_hwif_cs5530,
31621 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31622 index 5059faf..18d4c85 100644
31623 --- a/drivers/ide/cs5535.c
31624 +++ b/drivers/ide/cs5535.c
31625 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31626 .cable_detect = cs5535_cable_detect,
31627 };
31628
31629 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31630 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31631 .name = DRV_NAME,
31632 .port_ops = &cs5535_port_ops,
31633 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31634 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31635 index 847553f..3ffb49d 100644
31636 --- a/drivers/ide/cy82c693.c
31637 +++ b/drivers/ide/cy82c693.c
31638 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31639 .set_dma_mode = cy82c693_set_dma_mode,
31640 };
31641
31642 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31643 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31644 .name = DRV_NAME,
31645 .init_iops = init_iops_cy82c693,
31646 .port_ops = &cy82c693_port_ops,
31647 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31648 index 58c51cd..4aec3b8 100644
31649 --- a/drivers/ide/hpt366.c
31650 +++ b/drivers/ide/hpt366.c
31651 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31652 }
31653 };
31654
31655 -static const struct hpt_info hpt36x __devinitdata = {
31656 +static const struct hpt_info hpt36x __devinitconst = {
31657 .chip_name = "HPT36x",
31658 .chip_type = HPT36x,
31659 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31660 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31661 .timings = &hpt36x_timings
31662 };
31663
31664 -static const struct hpt_info hpt370 __devinitdata = {
31665 +static const struct hpt_info hpt370 __devinitconst = {
31666 .chip_name = "HPT370",
31667 .chip_type = HPT370,
31668 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31669 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31670 .timings = &hpt37x_timings
31671 };
31672
31673 -static const struct hpt_info hpt370a __devinitdata = {
31674 +static const struct hpt_info hpt370a __devinitconst = {
31675 .chip_name = "HPT370A",
31676 .chip_type = HPT370A,
31677 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31678 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31679 .timings = &hpt37x_timings
31680 };
31681
31682 -static const struct hpt_info hpt374 __devinitdata = {
31683 +static const struct hpt_info hpt374 __devinitconst = {
31684 .chip_name = "HPT374",
31685 .chip_type = HPT374,
31686 .udma_mask = ATA_UDMA5,
31687 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31688 .timings = &hpt37x_timings
31689 };
31690
31691 -static const struct hpt_info hpt372 __devinitdata = {
31692 +static const struct hpt_info hpt372 __devinitconst = {
31693 .chip_name = "HPT372",
31694 .chip_type = HPT372,
31695 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31696 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31697 .timings = &hpt37x_timings
31698 };
31699
31700 -static const struct hpt_info hpt372a __devinitdata = {
31701 +static const struct hpt_info hpt372a __devinitconst = {
31702 .chip_name = "HPT372A",
31703 .chip_type = HPT372A,
31704 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31705 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31706 .timings = &hpt37x_timings
31707 };
31708
31709 -static const struct hpt_info hpt302 __devinitdata = {
31710 +static const struct hpt_info hpt302 __devinitconst = {
31711 .chip_name = "HPT302",
31712 .chip_type = HPT302,
31713 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31714 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31715 .timings = &hpt37x_timings
31716 };
31717
31718 -static const struct hpt_info hpt371 __devinitdata = {
31719 +static const struct hpt_info hpt371 __devinitconst = {
31720 .chip_name = "HPT371",
31721 .chip_type = HPT371,
31722 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31723 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31724 .timings = &hpt37x_timings
31725 };
31726
31727 -static const struct hpt_info hpt372n __devinitdata = {
31728 +static const struct hpt_info hpt372n __devinitconst = {
31729 .chip_name = "HPT372N",
31730 .chip_type = HPT372N,
31731 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31732 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31733 .timings = &hpt37x_timings
31734 };
31735
31736 -static const struct hpt_info hpt302n __devinitdata = {
31737 +static const struct hpt_info hpt302n __devinitconst = {
31738 .chip_name = "HPT302N",
31739 .chip_type = HPT302N,
31740 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31741 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31742 .timings = &hpt37x_timings
31743 };
31744
31745 -static const struct hpt_info hpt371n __devinitdata = {
31746 +static const struct hpt_info hpt371n __devinitconst = {
31747 .chip_name = "HPT371N",
31748 .chip_type = HPT371N,
31749 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31750 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31751 .dma_sff_read_status = ide_dma_sff_read_status,
31752 };
31753
31754 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31755 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31756 { /* 0: HPT36x */
31757 .name = DRV_NAME,
31758 .init_chipset = init_chipset_hpt366,
31759 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31760 index 8126824..55a2798 100644
31761 --- a/drivers/ide/ide-cd.c
31762 +++ b/drivers/ide/ide-cd.c
31763 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31764 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31765 if ((unsigned long)buf & alignment
31766 || blk_rq_bytes(rq) & q->dma_pad_mask
31767 - || object_is_on_stack(buf))
31768 + || object_starts_on_stack(buf))
31769 drive->dma = 0;
31770 }
31771 }
31772 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31773 index 7f56b73..dab5b67 100644
31774 --- a/drivers/ide/ide-pci-generic.c
31775 +++ b/drivers/ide/ide-pci-generic.c
31776 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31777 .udma_mask = ATA_UDMA6, \
31778 }
31779
31780 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31781 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31782 /* 0: Unknown */
31783 DECLARE_GENERIC_PCI_DEV(0),
31784
31785 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31786 index 560e66d..d5dd180 100644
31787 --- a/drivers/ide/it8172.c
31788 +++ b/drivers/ide/it8172.c
31789 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31790 .set_dma_mode = it8172_set_dma_mode,
31791 };
31792
31793 -static const struct ide_port_info it8172_port_info __devinitdata = {
31794 +static const struct ide_port_info it8172_port_info __devinitconst = {
31795 .name = DRV_NAME,
31796 .port_ops = &it8172_port_ops,
31797 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31798 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31799 index 46816ba..1847aeb 100644
31800 --- a/drivers/ide/it8213.c
31801 +++ b/drivers/ide/it8213.c
31802 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31803 .cable_detect = it8213_cable_detect,
31804 };
31805
31806 -static const struct ide_port_info it8213_chipset __devinitdata = {
31807 +static const struct ide_port_info it8213_chipset __devinitconst = {
31808 .name = DRV_NAME,
31809 .enablebits = { {0x41, 0x80, 0x80} },
31810 .port_ops = &it8213_port_ops,
31811 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31812 index 2e3169f..c5611db 100644
31813 --- a/drivers/ide/it821x.c
31814 +++ b/drivers/ide/it821x.c
31815 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31816 .cable_detect = it821x_cable_detect,
31817 };
31818
31819 -static const struct ide_port_info it821x_chipset __devinitdata = {
31820 +static const struct ide_port_info it821x_chipset __devinitconst = {
31821 .name = DRV_NAME,
31822 .init_chipset = init_chipset_it821x,
31823 .init_hwif = init_hwif_it821x,
31824 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31825 index 74c2c4a..efddd7d 100644
31826 --- a/drivers/ide/jmicron.c
31827 +++ b/drivers/ide/jmicron.c
31828 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31829 .cable_detect = jmicron_cable_detect,
31830 };
31831
31832 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31833 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31834 .name = DRV_NAME,
31835 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31836 .port_ops = &jmicron_port_ops,
31837 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31838 index 95327a2..73f78d8 100644
31839 --- a/drivers/ide/ns87415.c
31840 +++ b/drivers/ide/ns87415.c
31841 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31842 .dma_sff_read_status = superio_dma_sff_read_status,
31843 };
31844
31845 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31846 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31847 .name = DRV_NAME,
31848 .init_hwif = init_hwif_ns87415,
31849 .tp_ops = &ns87415_tp_ops,
31850 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31851 index 1a53a4c..39edc66 100644
31852 --- a/drivers/ide/opti621.c
31853 +++ b/drivers/ide/opti621.c
31854 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31855 .set_pio_mode = opti621_set_pio_mode,
31856 };
31857
31858 -static const struct ide_port_info opti621_chipset __devinitdata = {
31859 +static const struct ide_port_info opti621_chipset __devinitconst = {
31860 .name = DRV_NAME,
31861 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31862 .port_ops = &opti621_port_ops,
31863 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31864 index 9546fe2..2e5ceb6 100644
31865 --- a/drivers/ide/pdc202xx_new.c
31866 +++ b/drivers/ide/pdc202xx_new.c
31867 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31868 .udma_mask = udma, \
31869 }
31870
31871 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31872 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31873 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31874 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31875 };
31876 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31877 index 3a35ec6..5634510 100644
31878 --- a/drivers/ide/pdc202xx_old.c
31879 +++ b/drivers/ide/pdc202xx_old.c
31880 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31881 .max_sectors = sectors, \
31882 }
31883
31884 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31885 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31886 { /* 0: PDC20246 */
31887 .name = DRV_NAME,
31888 .init_chipset = init_chipset_pdc202xx,
31889 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31890 index 1892e81..fe0fd60 100644
31891 --- a/drivers/ide/piix.c
31892 +++ b/drivers/ide/piix.c
31893 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31894 .udma_mask = udma, \
31895 }
31896
31897 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31898 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31899 /* 0: MPIIX */
31900 { /*
31901 * MPIIX actually has only a single IDE channel mapped to
31902 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31903 index a6414a8..c04173e 100644
31904 --- a/drivers/ide/rz1000.c
31905 +++ b/drivers/ide/rz1000.c
31906 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31907 }
31908 }
31909
31910 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31911 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31912 .name = DRV_NAME,
31913 .host_flags = IDE_HFLAG_NO_DMA,
31914 };
31915 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31916 index 356b9b5..d4758eb 100644
31917 --- a/drivers/ide/sc1200.c
31918 +++ b/drivers/ide/sc1200.c
31919 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31920 .dma_sff_read_status = ide_dma_sff_read_status,
31921 };
31922
31923 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31924 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31925 .name = DRV_NAME,
31926 .port_ops = &sc1200_port_ops,
31927 .dma_ops = &sc1200_dma_ops,
31928 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31929 index b7f5b0c..9701038 100644
31930 --- a/drivers/ide/scc_pata.c
31931 +++ b/drivers/ide/scc_pata.c
31932 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31933 .dma_sff_read_status = scc_dma_sff_read_status,
31934 };
31935
31936 -static const struct ide_port_info scc_chipset __devinitdata = {
31937 +static const struct ide_port_info scc_chipset __devinitconst = {
31938 .name = "sccIDE",
31939 .init_iops = init_iops_scc,
31940 .init_dma = scc_init_dma,
31941 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31942 index 35fb8da..24d72ef 100644
31943 --- a/drivers/ide/serverworks.c
31944 +++ b/drivers/ide/serverworks.c
31945 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31946 .cable_detect = svwks_cable_detect,
31947 };
31948
31949 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31950 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31951 { /* 0: OSB4 */
31952 .name = DRV_NAME,
31953 .init_chipset = init_chipset_svwks,
31954 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31955 index ddeda44..46f7e30 100644
31956 --- a/drivers/ide/siimage.c
31957 +++ b/drivers/ide/siimage.c
31958 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31959 .udma_mask = ATA_UDMA6, \
31960 }
31961
31962 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31963 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31964 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31965 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31966 };
31967 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31968 index 4a00225..09e61b4 100644
31969 --- a/drivers/ide/sis5513.c
31970 +++ b/drivers/ide/sis5513.c
31971 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31972 .cable_detect = sis_cable_detect,
31973 };
31974
31975 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31976 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31977 .name = DRV_NAME,
31978 .init_chipset = init_chipset_sis5513,
31979 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31980 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31981 index f21dc2a..d051cd2 100644
31982 --- a/drivers/ide/sl82c105.c
31983 +++ b/drivers/ide/sl82c105.c
31984 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31985 .dma_sff_read_status = ide_dma_sff_read_status,
31986 };
31987
31988 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31989 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31990 .name = DRV_NAME,
31991 .init_chipset = init_chipset_sl82c105,
31992 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31993 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31994 index 864ffe0..863a5e9 100644
31995 --- a/drivers/ide/slc90e66.c
31996 +++ b/drivers/ide/slc90e66.c
31997 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31998 .cable_detect = slc90e66_cable_detect,
31999 };
32000
32001 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32002 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32003 .name = DRV_NAME,
32004 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32005 .port_ops = &slc90e66_port_ops,
32006 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32007 index 4799d5c..1794678 100644
32008 --- a/drivers/ide/tc86c001.c
32009 +++ b/drivers/ide/tc86c001.c
32010 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32011 .dma_sff_read_status = ide_dma_sff_read_status,
32012 };
32013
32014 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32015 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32016 .name = DRV_NAME,
32017 .init_hwif = init_hwif_tc86c001,
32018 .port_ops = &tc86c001_port_ops,
32019 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32020 index 281c914..55ce1b8 100644
32021 --- a/drivers/ide/triflex.c
32022 +++ b/drivers/ide/triflex.c
32023 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32024 .set_dma_mode = triflex_set_mode,
32025 };
32026
32027 -static const struct ide_port_info triflex_device __devinitdata = {
32028 +static const struct ide_port_info triflex_device __devinitconst = {
32029 .name = DRV_NAME,
32030 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32031 .port_ops = &triflex_port_ops,
32032 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32033 index 4b42ca0..e494a98 100644
32034 --- a/drivers/ide/trm290.c
32035 +++ b/drivers/ide/trm290.c
32036 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32037 .dma_check = trm290_dma_check,
32038 };
32039
32040 -static const struct ide_port_info trm290_chipset __devinitdata = {
32041 +static const struct ide_port_info trm290_chipset __devinitconst = {
32042 .name = DRV_NAME,
32043 .init_hwif = init_hwif_trm290,
32044 .tp_ops = &trm290_tp_ops,
32045 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32046 index f46f49c..eb77678 100644
32047 --- a/drivers/ide/via82cxxx.c
32048 +++ b/drivers/ide/via82cxxx.c
32049 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32050 .cable_detect = via82cxxx_cable_detect,
32051 };
32052
32053 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32054 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32055 .name = DRV_NAME,
32056 .init_chipset = init_chipset_via82cxxx,
32057 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32058 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32059 index 73d4531..c90cd2d 100644
32060 --- a/drivers/ieee802154/fakehard.c
32061 +++ b/drivers/ieee802154/fakehard.c
32062 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32063 phy->transmit_power = 0xbf;
32064
32065 dev->netdev_ops = &fake_ops;
32066 - dev->ml_priv = &fake_mlme;
32067 + dev->ml_priv = (void *)&fake_mlme;
32068
32069 priv = netdev_priv(dev);
32070 priv->phy = phy;
32071 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32072 index c889aae..6cf5aa7 100644
32073 --- a/drivers/infiniband/core/cm.c
32074 +++ b/drivers/infiniband/core/cm.c
32075 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32076
32077 struct cm_counter_group {
32078 struct kobject obj;
32079 - atomic_long_t counter[CM_ATTR_COUNT];
32080 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32081 };
32082
32083 struct cm_counter_attribute {
32084 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32085 struct ib_mad_send_buf *msg = NULL;
32086 int ret;
32087
32088 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32089 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32090 counter[CM_REQ_COUNTER]);
32091
32092 /* Quick state check to discard duplicate REQs. */
32093 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32094 if (!cm_id_priv)
32095 return;
32096
32097 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32098 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32099 counter[CM_REP_COUNTER]);
32100 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32101 if (ret)
32102 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32103 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32104 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32105 spin_unlock_irq(&cm_id_priv->lock);
32106 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32107 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32108 counter[CM_RTU_COUNTER]);
32109 goto out;
32110 }
32111 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32112 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32113 dreq_msg->local_comm_id);
32114 if (!cm_id_priv) {
32115 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32116 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32117 counter[CM_DREQ_COUNTER]);
32118 cm_issue_drep(work->port, work->mad_recv_wc);
32119 return -EINVAL;
32120 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32121 case IB_CM_MRA_REP_RCVD:
32122 break;
32123 case IB_CM_TIMEWAIT:
32124 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32125 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32126 counter[CM_DREQ_COUNTER]);
32127 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32128 goto unlock;
32129 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32130 cm_free_msg(msg);
32131 goto deref;
32132 case IB_CM_DREQ_RCVD:
32133 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32134 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32135 counter[CM_DREQ_COUNTER]);
32136 goto unlock;
32137 default:
32138 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32139 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32140 cm_id_priv->msg, timeout)) {
32141 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32142 - atomic_long_inc(&work->port->
32143 + atomic_long_inc_unchecked(&work->port->
32144 counter_group[CM_RECV_DUPLICATES].
32145 counter[CM_MRA_COUNTER]);
32146 goto out;
32147 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32148 break;
32149 case IB_CM_MRA_REQ_RCVD:
32150 case IB_CM_MRA_REP_RCVD:
32151 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32152 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32153 counter[CM_MRA_COUNTER]);
32154 /* fall through */
32155 default:
32156 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32157 case IB_CM_LAP_IDLE:
32158 break;
32159 case IB_CM_MRA_LAP_SENT:
32160 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32161 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32162 counter[CM_LAP_COUNTER]);
32163 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32164 goto unlock;
32165 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32166 cm_free_msg(msg);
32167 goto deref;
32168 case IB_CM_LAP_RCVD:
32169 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32170 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32171 counter[CM_LAP_COUNTER]);
32172 goto unlock;
32173 default:
32174 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32175 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32176 if (cur_cm_id_priv) {
32177 spin_unlock_irq(&cm.lock);
32178 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32179 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32180 counter[CM_SIDR_REQ_COUNTER]);
32181 goto out; /* Duplicate message. */
32182 }
32183 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32184 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32185 msg->retries = 1;
32186
32187 - atomic_long_add(1 + msg->retries,
32188 + atomic_long_add_unchecked(1 + msg->retries,
32189 &port->counter_group[CM_XMIT].counter[attr_index]);
32190 if (msg->retries)
32191 - atomic_long_add(msg->retries,
32192 + atomic_long_add_unchecked(msg->retries,
32193 &port->counter_group[CM_XMIT_RETRIES].
32194 counter[attr_index]);
32195
32196 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32197 }
32198
32199 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32200 - atomic_long_inc(&port->counter_group[CM_RECV].
32201 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32202 counter[attr_id - CM_ATTR_ID_OFFSET]);
32203
32204 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32205 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32206 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32207
32208 return sprintf(buf, "%ld\n",
32209 - atomic_long_read(&group->counter[cm_attr->index]));
32210 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32211 }
32212
32213 static const struct sysfs_ops cm_counter_ops = {
32214 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32215 index 176c8f9..2627b62 100644
32216 --- a/drivers/infiniband/core/fmr_pool.c
32217 +++ b/drivers/infiniband/core/fmr_pool.c
32218 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32219
32220 struct task_struct *thread;
32221
32222 - atomic_t req_ser;
32223 - atomic_t flush_ser;
32224 + atomic_unchecked_t req_ser;
32225 + atomic_unchecked_t flush_ser;
32226
32227 wait_queue_head_t force_wait;
32228 };
32229 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32230 struct ib_fmr_pool *pool = pool_ptr;
32231
32232 do {
32233 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32234 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32235 ib_fmr_batch_release(pool);
32236
32237 - atomic_inc(&pool->flush_ser);
32238 + atomic_inc_unchecked(&pool->flush_ser);
32239 wake_up_interruptible(&pool->force_wait);
32240
32241 if (pool->flush_function)
32242 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32243 }
32244
32245 set_current_state(TASK_INTERRUPTIBLE);
32246 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32247 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32248 !kthread_should_stop())
32249 schedule();
32250 __set_current_state(TASK_RUNNING);
32251 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32252 pool->dirty_watermark = params->dirty_watermark;
32253 pool->dirty_len = 0;
32254 spin_lock_init(&pool->pool_lock);
32255 - atomic_set(&pool->req_ser, 0);
32256 - atomic_set(&pool->flush_ser, 0);
32257 + atomic_set_unchecked(&pool->req_ser, 0);
32258 + atomic_set_unchecked(&pool->flush_ser, 0);
32259 init_waitqueue_head(&pool->force_wait);
32260
32261 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32262 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32263 }
32264 spin_unlock_irq(&pool->pool_lock);
32265
32266 - serial = atomic_inc_return(&pool->req_ser);
32267 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32268 wake_up_process(pool->thread);
32269
32270 if (wait_event_interruptible(pool->force_wait,
32271 - atomic_read(&pool->flush_ser) - serial >= 0))
32272 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32273 return -EINTR;
32274
32275 return 0;
32276 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32277 } else {
32278 list_add_tail(&fmr->list, &pool->dirty_list);
32279 if (++pool->dirty_len >= pool->dirty_watermark) {
32280 - atomic_inc(&pool->req_ser);
32281 + atomic_inc_unchecked(&pool->req_ser);
32282 wake_up_process(pool->thread);
32283 }
32284 }
32285 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32286 index 40c8353..946b0e4 100644
32287 --- a/drivers/infiniband/hw/cxgb4/mem.c
32288 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32289 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32290 int err;
32291 struct fw_ri_tpte tpt;
32292 u32 stag_idx;
32293 - static atomic_t key;
32294 + static atomic_unchecked_t key;
32295
32296 if (c4iw_fatal_error(rdev))
32297 return -EIO;
32298 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32299 &rdev->resource.tpt_fifo_lock);
32300 if (!stag_idx)
32301 return -ENOMEM;
32302 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32303 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32304 }
32305 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32306 __func__, stag_state, type, pdid, stag_idx);
32307 diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
32308 index a4de9d5..5fa20c3 100644
32309 --- a/drivers/infiniband/hw/ipath/ipath_fs.c
32310 +++ b/drivers/infiniband/hw/ipath/ipath_fs.c
32311 @@ -126,6 +126,8 @@ static const struct file_operations atomic_counters_ops = {
32312 };
32313
32314 static ssize_t flash_read(struct file *file, char __user *buf,
32315 + size_t count, loff_t *ppos) __size_overflow(3);
32316 +static ssize_t flash_read(struct file *file, char __user *buf,
32317 size_t count, loff_t *ppos)
32318 {
32319 struct ipath_devdata *dd;
32320 @@ -177,6 +179,8 @@ bail:
32321 }
32322
32323 static ssize_t flash_write(struct file *file, const char __user *buf,
32324 + size_t count, loff_t *ppos) __size_overflow(3);
32325 +static ssize_t flash_write(struct file *file, const char __user *buf,
32326 size_t count, loff_t *ppos)
32327 {
32328 struct ipath_devdata *dd;
32329 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32330 index 79b3dbc..96e5fcc 100644
32331 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32332 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32333 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32334 struct ib_atomic_eth *ateth;
32335 struct ipath_ack_entry *e;
32336 u64 vaddr;
32337 - atomic64_t *maddr;
32338 + atomic64_unchecked_t *maddr;
32339 u64 sdata;
32340 u32 rkey;
32341 u8 next;
32342 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32343 IB_ACCESS_REMOTE_ATOMIC)))
32344 goto nack_acc_unlck;
32345 /* Perform atomic OP and save result. */
32346 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32347 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32348 sdata = be64_to_cpu(ateth->swap_data);
32349 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32350 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32351 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32352 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32353 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32354 be64_to_cpu(ateth->compare_data),
32355 sdata);
32356 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32357 index 1f95bba..9530f87 100644
32358 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32359 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32360 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32361 unsigned long flags;
32362 struct ib_wc wc;
32363 u64 sdata;
32364 - atomic64_t *maddr;
32365 + atomic64_unchecked_t *maddr;
32366 enum ib_wc_status send_status;
32367
32368 /*
32369 @@ -382,11 +382,11 @@ again:
32370 IB_ACCESS_REMOTE_ATOMIC)))
32371 goto acc_err;
32372 /* Perform atomic OP and save result. */
32373 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32374 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32375 sdata = wqe->wr.wr.atomic.compare_add;
32376 *(u64 *) sqp->s_sge.sge.vaddr =
32377 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32378 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32379 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32380 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32381 sdata, wqe->wr.wr.atomic.swap);
32382 goto send_comp;
32383 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32384 index 7140199..da60063 100644
32385 --- a/drivers/infiniband/hw/nes/nes.c
32386 +++ b/drivers/infiniband/hw/nes/nes.c
32387 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32388 LIST_HEAD(nes_adapter_list);
32389 static LIST_HEAD(nes_dev_list);
32390
32391 -atomic_t qps_destroyed;
32392 +atomic_unchecked_t qps_destroyed;
32393
32394 static unsigned int ee_flsh_adapter;
32395 static unsigned int sysfs_nonidx_addr;
32396 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32397 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32398 struct nes_adapter *nesadapter = nesdev->nesadapter;
32399
32400 - atomic_inc(&qps_destroyed);
32401 + atomic_inc_unchecked(&qps_destroyed);
32402
32403 /* Free the control structures */
32404
32405 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32406 index c438e46..ca30356 100644
32407 --- a/drivers/infiniband/hw/nes/nes.h
32408 +++ b/drivers/infiniband/hw/nes/nes.h
32409 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32410 extern unsigned int wqm_quanta;
32411 extern struct list_head nes_adapter_list;
32412
32413 -extern atomic_t cm_connects;
32414 -extern atomic_t cm_accepts;
32415 -extern atomic_t cm_disconnects;
32416 -extern atomic_t cm_closes;
32417 -extern atomic_t cm_connecteds;
32418 -extern atomic_t cm_connect_reqs;
32419 -extern atomic_t cm_rejects;
32420 -extern atomic_t mod_qp_timouts;
32421 -extern atomic_t qps_created;
32422 -extern atomic_t qps_destroyed;
32423 -extern atomic_t sw_qps_destroyed;
32424 +extern atomic_unchecked_t cm_connects;
32425 +extern atomic_unchecked_t cm_accepts;
32426 +extern atomic_unchecked_t cm_disconnects;
32427 +extern atomic_unchecked_t cm_closes;
32428 +extern atomic_unchecked_t cm_connecteds;
32429 +extern atomic_unchecked_t cm_connect_reqs;
32430 +extern atomic_unchecked_t cm_rejects;
32431 +extern atomic_unchecked_t mod_qp_timouts;
32432 +extern atomic_unchecked_t qps_created;
32433 +extern atomic_unchecked_t qps_destroyed;
32434 +extern atomic_unchecked_t sw_qps_destroyed;
32435 extern u32 mh_detected;
32436 extern u32 mh_pauses_sent;
32437 extern u32 cm_packets_sent;
32438 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32439 extern u32 cm_packets_received;
32440 extern u32 cm_packets_dropped;
32441 extern u32 cm_packets_retrans;
32442 -extern atomic_t cm_listens_created;
32443 -extern atomic_t cm_listens_destroyed;
32444 +extern atomic_unchecked_t cm_listens_created;
32445 +extern atomic_unchecked_t cm_listens_destroyed;
32446 extern u32 cm_backlog_drops;
32447 -extern atomic_t cm_loopbacks;
32448 -extern atomic_t cm_nodes_created;
32449 -extern atomic_t cm_nodes_destroyed;
32450 -extern atomic_t cm_accel_dropped_pkts;
32451 -extern atomic_t cm_resets_recvd;
32452 -extern atomic_t pau_qps_created;
32453 -extern atomic_t pau_qps_destroyed;
32454 +extern atomic_unchecked_t cm_loopbacks;
32455 +extern atomic_unchecked_t cm_nodes_created;
32456 +extern atomic_unchecked_t cm_nodes_destroyed;
32457 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32458 +extern atomic_unchecked_t cm_resets_recvd;
32459 +extern atomic_unchecked_t pau_qps_created;
32460 +extern atomic_unchecked_t pau_qps_destroyed;
32461
32462 extern u32 int_mod_timer_init;
32463 extern u32 int_mod_cq_depth_256;
32464 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32465 index a4972ab..1bcfc31 100644
32466 --- a/drivers/infiniband/hw/nes/nes_cm.c
32467 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32468 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32469 u32 cm_packets_retrans;
32470 u32 cm_packets_created;
32471 u32 cm_packets_received;
32472 -atomic_t cm_listens_created;
32473 -atomic_t cm_listens_destroyed;
32474 +atomic_unchecked_t cm_listens_created;
32475 +atomic_unchecked_t cm_listens_destroyed;
32476 u32 cm_backlog_drops;
32477 -atomic_t cm_loopbacks;
32478 -atomic_t cm_nodes_created;
32479 -atomic_t cm_nodes_destroyed;
32480 -atomic_t cm_accel_dropped_pkts;
32481 -atomic_t cm_resets_recvd;
32482 +atomic_unchecked_t cm_loopbacks;
32483 +atomic_unchecked_t cm_nodes_created;
32484 +atomic_unchecked_t cm_nodes_destroyed;
32485 +atomic_unchecked_t cm_accel_dropped_pkts;
32486 +atomic_unchecked_t cm_resets_recvd;
32487
32488 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32489 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32490 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32491
32492 static struct nes_cm_core *g_cm_core;
32493
32494 -atomic_t cm_connects;
32495 -atomic_t cm_accepts;
32496 -atomic_t cm_disconnects;
32497 -atomic_t cm_closes;
32498 -atomic_t cm_connecteds;
32499 -atomic_t cm_connect_reqs;
32500 -atomic_t cm_rejects;
32501 +atomic_unchecked_t cm_connects;
32502 +atomic_unchecked_t cm_accepts;
32503 +atomic_unchecked_t cm_disconnects;
32504 +atomic_unchecked_t cm_closes;
32505 +atomic_unchecked_t cm_connecteds;
32506 +atomic_unchecked_t cm_connect_reqs;
32507 +atomic_unchecked_t cm_rejects;
32508
32509 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32510 {
32511 @@ -1274,7 +1274,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32512 kfree(listener);
32513 listener = NULL;
32514 ret = 0;
32515 - atomic_inc(&cm_listens_destroyed);
32516 + atomic_inc_unchecked(&cm_listens_destroyed);
32517 } else {
32518 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32519 }
32520 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32521 cm_node->rem_mac);
32522
32523 add_hte_node(cm_core, cm_node);
32524 - atomic_inc(&cm_nodes_created);
32525 + atomic_inc_unchecked(&cm_nodes_created);
32526
32527 return cm_node;
32528 }
32529 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32530 }
32531
32532 atomic_dec(&cm_core->node_cnt);
32533 - atomic_inc(&cm_nodes_destroyed);
32534 + atomic_inc_unchecked(&cm_nodes_destroyed);
32535 nesqp = cm_node->nesqp;
32536 if (nesqp) {
32537 nesqp->cm_node = NULL;
32538 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32539
32540 static void drop_packet(struct sk_buff *skb)
32541 {
32542 - atomic_inc(&cm_accel_dropped_pkts);
32543 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32544 dev_kfree_skb_any(skb);
32545 }
32546
32547 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32548 {
32549
32550 int reset = 0; /* whether to send reset in case of err.. */
32551 - atomic_inc(&cm_resets_recvd);
32552 + atomic_inc_unchecked(&cm_resets_recvd);
32553 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32554 " refcnt=%d\n", cm_node, cm_node->state,
32555 atomic_read(&cm_node->ref_count));
32556 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32557 rem_ref_cm_node(cm_node->cm_core, cm_node);
32558 return NULL;
32559 }
32560 - atomic_inc(&cm_loopbacks);
32561 + atomic_inc_unchecked(&cm_loopbacks);
32562 loopbackremotenode->loopbackpartner = cm_node;
32563 loopbackremotenode->tcp_cntxt.rcv_wscale =
32564 NES_CM_DEFAULT_RCV_WND_SCALE;
32565 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32566 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32567 else {
32568 rem_ref_cm_node(cm_core, cm_node);
32569 - atomic_inc(&cm_accel_dropped_pkts);
32570 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32571 dev_kfree_skb_any(skb);
32572 }
32573 break;
32574 @@ -2881,7 +2881,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32575
32576 if ((cm_id) && (cm_id->event_handler)) {
32577 if (issue_disconn) {
32578 - atomic_inc(&cm_disconnects);
32579 + atomic_inc_unchecked(&cm_disconnects);
32580 cm_event.event = IW_CM_EVENT_DISCONNECT;
32581 cm_event.status = disconn_status;
32582 cm_event.local_addr = cm_id->local_addr;
32583 @@ -2903,7 +2903,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32584 }
32585
32586 if (issue_close) {
32587 - atomic_inc(&cm_closes);
32588 + atomic_inc_unchecked(&cm_closes);
32589 nes_disconnect(nesqp, 1);
32590
32591 cm_id->provider_data = nesqp;
32592 @@ -3039,7 +3039,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32593
32594 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32595 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32596 - atomic_inc(&cm_accepts);
32597 + atomic_inc_unchecked(&cm_accepts);
32598
32599 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32600 netdev_refcnt_read(nesvnic->netdev));
32601 @@ -3241,7 +3241,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32602 struct nes_cm_core *cm_core;
32603 u8 *start_buff;
32604
32605 - atomic_inc(&cm_rejects);
32606 + atomic_inc_unchecked(&cm_rejects);
32607 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32608 loopback = cm_node->loopbackpartner;
32609 cm_core = cm_node->cm_core;
32610 @@ -3301,7 +3301,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32611 ntohl(cm_id->local_addr.sin_addr.s_addr),
32612 ntohs(cm_id->local_addr.sin_port));
32613
32614 - atomic_inc(&cm_connects);
32615 + atomic_inc_unchecked(&cm_connects);
32616 nesqp->active_conn = 1;
32617
32618 /* cache the cm_id in the qp */
32619 @@ -3407,7 +3407,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32620 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32621 return err;
32622 }
32623 - atomic_inc(&cm_listens_created);
32624 + atomic_inc_unchecked(&cm_listens_created);
32625 }
32626
32627 cm_id->add_ref(cm_id);
32628 @@ -3508,7 +3508,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32629
32630 if (nesqp->destroyed)
32631 return;
32632 - atomic_inc(&cm_connecteds);
32633 + atomic_inc_unchecked(&cm_connecteds);
32634 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32635 " local port 0x%04X. jiffies = %lu.\n",
32636 nesqp->hwqp.qp_id,
32637 @@ -3695,7 +3695,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32638
32639 cm_id->add_ref(cm_id);
32640 ret = cm_id->event_handler(cm_id, &cm_event);
32641 - atomic_inc(&cm_closes);
32642 + atomic_inc_unchecked(&cm_closes);
32643 cm_event.event = IW_CM_EVENT_CLOSE;
32644 cm_event.status = 0;
32645 cm_event.provider_data = cm_id->provider_data;
32646 @@ -3731,7 +3731,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32647 return;
32648 cm_id = cm_node->cm_id;
32649
32650 - atomic_inc(&cm_connect_reqs);
32651 + atomic_inc_unchecked(&cm_connect_reqs);
32652 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32653 cm_node, cm_id, jiffies);
32654
32655 @@ -3771,7 +3771,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32656 return;
32657 cm_id = cm_node->cm_id;
32658
32659 - atomic_inc(&cm_connect_reqs);
32660 + atomic_inc_unchecked(&cm_connect_reqs);
32661 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32662 cm_node, cm_id, jiffies);
32663
32664 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32665 index 3ba7be3..c81f6ff 100644
32666 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32667 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32668 @@ -40,8 +40,8 @@
32669 #include "nes.h"
32670 #include "nes_mgt.h"
32671
32672 -atomic_t pau_qps_created;
32673 -atomic_t pau_qps_destroyed;
32674 +atomic_unchecked_t pau_qps_created;
32675 +atomic_unchecked_t pau_qps_destroyed;
32676
32677 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32678 {
32679 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32680 {
32681 struct sk_buff *skb;
32682 unsigned long flags;
32683 - atomic_inc(&pau_qps_destroyed);
32684 + atomic_inc_unchecked(&pau_qps_destroyed);
32685
32686 /* Free packets that have not yet been forwarded */
32687 /* Lock is acquired by skb_dequeue when removing the skb */
32688 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32689 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32690 skb_queue_head_init(&nesqp->pau_list);
32691 spin_lock_init(&nesqp->pau_lock);
32692 - atomic_inc(&pau_qps_created);
32693 + atomic_inc_unchecked(&pau_qps_created);
32694 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32695 }
32696
32697 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32698 index f3a3ecf..57d311d 100644
32699 --- a/drivers/infiniband/hw/nes/nes_nic.c
32700 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32701 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32702 target_stat_values[++index] = mh_detected;
32703 target_stat_values[++index] = mh_pauses_sent;
32704 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32705 - target_stat_values[++index] = atomic_read(&cm_connects);
32706 - target_stat_values[++index] = atomic_read(&cm_accepts);
32707 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32708 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32709 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32710 - target_stat_values[++index] = atomic_read(&cm_rejects);
32711 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32712 - target_stat_values[++index] = atomic_read(&qps_created);
32713 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32714 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32715 - target_stat_values[++index] = atomic_read(&cm_closes);
32716 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32717 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32718 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32719 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32720 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32721 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32722 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32723 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32724 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32725 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32726 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32727 target_stat_values[++index] = cm_packets_sent;
32728 target_stat_values[++index] = cm_packets_bounced;
32729 target_stat_values[++index] = cm_packets_created;
32730 target_stat_values[++index] = cm_packets_received;
32731 target_stat_values[++index] = cm_packets_dropped;
32732 target_stat_values[++index] = cm_packets_retrans;
32733 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32734 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32735 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32736 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32737 target_stat_values[++index] = cm_backlog_drops;
32738 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32739 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32740 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32741 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32742 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32743 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32744 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32745 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32746 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32747 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32748 target_stat_values[++index] = nesadapter->free_4kpbl;
32749 target_stat_values[++index] = nesadapter->free_256pbl;
32750 target_stat_values[++index] = int_mod_timer_init;
32751 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32752 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32753 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32754 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32755 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32756 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32757 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32758 }
32759
32760 /**
32761 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32762 index 0927b5c..ed67986 100644
32763 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32764 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32765 @@ -46,9 +46,9 @@
32766
32767 #include <rdma/ib_umem.h>
32768
32769 -atomic_t mod_qp_timouts;
32770 -atomic_t qps_created;
32771 -atomic_t sw_qps_destroyed;
32772 +atomic_unchecked_t mod_qp_timouts;
32773 +atomic_unchecked_t qps_created;
32774 +atomic_unchecked_t sw_qps_destroyed;
32775
32776 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32777
32778 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32779 if (init_attr->create_flags)
32780 return ERR_PTR(-EINVAL);
32781
32782 - atomic_inc(&qps_created);
32783 + atomic_inc_unchecked(&qps_created);
32784 switch (init_attr->qp_type) {
32785 case IB_QPT_RC:
32786 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32787 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32788 struct iw_cm_event cm_event;
32789 int ret = 0;
32790
32791 - atomic_inc(&sw_qps_destroyed);
32792 + atomic_inc_unchecked(&sw_qps_destroyed);
32793 nesqp->destroyed = 1;
32794
32795 /* Blow away the connection if it exists. */
32796 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32797 index b881bdc..c2e360c 100644
32798 --- a/drivers/infiniband/hw/qib/qib.h
32799 +++ b/drivers/infiniband/hw/qib/qib.h
32800 @@ -51,6 +51,7 @@
32801 #include <linux/completion.h>
32802 #include <linux/kref.h>
32803 #include <linux/sched.h>
32804 +#include <linux/slab.h>
32805
32806 #include "qib_common.h"
32807 #include "qib_verbs.h"
32808 diff --git a/drivers/infiniband/hw/qib/qib_fs.c b/drivers/infiniband/hw/qib/qib_fs.c
32809 index 05e0f17..0275789 100644
32810 --- a/drivers/infiniband/hw/qib/qib_fs.c
32811 +++ b/drivers/infiniband/hw/qib/qib_fs.c
32812 @@ -267,6 +267,8 @@ static const struct file_operations qsfp_ops[] = {
32813 };
32814
32815 static ssize_t flash_read(struct file *file, char __user *buf,
32816 + size_t count, loff_t *ppos) __size_overflow(3);
32817 +static ssize_t flash_read(struct file *file, char __user *buf,
32818 size_t count, loff_t *ppos)
32819 {
32820 struct qib_devdata *dd;
32821 @@ -318,6 +320,8 @@ bail:
32822 }
32823
32824 static ssize_t flash_write(struct file *file, const char __user *buf,
32825 + size_t count, loff_t *ppos) __size_overflow(3);
32826 +static ssize_t flash_write(struct file *file, const char __user *buf,
32827 size_t count, loff_t *ppos)
32828 {
32829 struct qib_devdata *dd;
32830 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32831 index c351aa4..e6967c2 100644
32832 --- a/drivers/input/gameport/gameport.c
32833 +++ b/drivers/input/gameport/gameport.c
32834 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32835 */
32836 static void gameport_init_port(struct gameport *gameport)
32837 {
32838 - static atomic_t gameport_no = ATOMIC_INIT(0);
32839 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32840
32841 __module_get(THIS_MODULE);
32842
32843 mutex_init(&gameport->drv_mutex);
32844 device_initialize(&gameport->dev);
32845 dev_set_name(&gameport->dev, "gameport%lu",
32846 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32847 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32848 gameport->dev.bus = &gameport_bus;
32849 gameport->dev.release = gameport_release_port;
32850 if (gameport->parent)
32851 diff --git a/drivers/input/input.c b/drivers/input/input.c
32852 index 1f78c95..3cddc6c 100644
32853 --- a/drivers/input/input.c
32854 +++ b/drivers/input/input.c
32855 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32856 */
32857 int input_register_device(struct input_dev *dev)
32858 {
32859 - static atomic_t input_no = ATOMIC_INIT(0);
32860 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32861 struct input_handler *handler;
32862 const char *path;
32863 int error;
32864 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32865 dev->setkeycode = input_default_setkeycode;
32866
32867 dev_set_name(&dev->dev, "input%ld",
32868 - (unsigned long) atomic_inc_return(&input_no) - 1);
32869 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32870
32871 error = device_add(&dev->dev);
32872 if (error)
32873 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32874 index b8d8611..7a4a04b 100644
32875 --- a/drivers/input/joystick/sidewinder.c
32876 +++ b/drivers/input/joystick/sidewinder.c
32877 @@ -30,6 +30,7 @@
32878 #include <linux/kernel.h>
32879 #include <linux/module.h>
32880 #include <linux/slab.h>
32881 +#include <linux/sched.h>
32882 #include <linux/init.h>
32883 #include <linux/input.h>
32884 #include <linux/gameport.h>
32885 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32886 index fd7a0d5..a4af10c 100644
32887 --- a/drivers/input/joystick/xpad.c
32888 +++ b/drivers/input/joystick/xpad.c
32889 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32890
32891 static int xpad_led_probe(struct usb_xpad *xpad)
32892 {
32893 - static atomic_t led_seq = ATOMIC_INIT(0);
32894 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32895 long led_no;
32896 struct xpad_led *led;
32897 struct led_classdev *led_cdev;
32898 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32899 if (!led)
32900 return -ENOMEM;
32901
32902 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32903 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32904
32905 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32906 led->xpad = xpad;
32907 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32908 index 0110b5a..d3ad144 100644
32909 --- a/drivers/input/mousedev.c
32910 +++ b/drivers/input/mousedev.c
32911 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32912
32913 spin_unlock_irq(&client->packet_lock);
32914
32915 - if (copy_to_user(buffer, data, count))
32916 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32917 return -EFAULT;
32918
32919 return count;
32920 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32921 index ba70058..571d25d 100644
32922 --- a/drivers/input/serio/serio.c
32923 +++ b/drivers/input/serio/serio.c
32924 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
32925 */
32926 static void serio_init_port(struct serio *serio)
32927 {
32928 - static atomic_t serio_no = ATOMIC_INIT(0);
32929 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32930
32931 __module_get(THIS_MODULE);
32932
32933 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
32934 mutex_init(&serio->drv_mutex);
32935 device_initialize(&serio->dev);
32936 dev_set_name(&serio->dev, "serio%ld",
32937 - (long)atomic_inc_return(&serio_no) - 1);
32938 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32939 serio->dev.bus = &serio_bus;
32940 serio->dev.release = serio_release_port;
32941 serio->dev.groups = serio_device_attr_groups;
32942 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32943 index e44933d..9ba484a 100644
32944 --- a/drivers/isdn/capi/capi.c
32945 +++ b/drivers/isdn/capi/capi.c
32946 @@ -83,8 +83,8 @@ struct capiminor {
32947
32948 struct capi20_appl *ap;
32949 u32 ncci;
32950 - atomic_t datahandle;
32951 - atomic_t msgid;
32952 + atomic_unchecked_t datahandle;
32953 + atomic_unchecked_t msgid;
32954
32955 struct tty_port port;
32956 int ttyinstop;
32957 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32958 capimsg_setu16(s, 2, mp->ap->applid);
32959 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32960 capimsg_setu8 (s, 5, CAPI_RESP);
32961 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32962 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32963 capimsg_setu32(s, 8, mp->ncci);
32964 capimsg_setu16(s, 12, datahandle);
32965 }
32966 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32967 mp->outbytes -= len;
32968 spin_unlock_bh(&mp->outlock);
32969
32970 - datahandle = atomic_inc_return(&mp->datahandle);
32971 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32972 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32973 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32974 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32975 capimsg_setu16(skb->data, 2, mp->ap->applid);
32976 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32977 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32978 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32979 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32980 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32981 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32982 capimsg_setu16(skb->data, 16, len); /* Data length */
32983 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
32984 index db621db..825ea1a 100644
32985 --- a/drivers/isdn/gigaset/common.c
32986 +++ b/drivers/isdn/gigaset/common.c
32987 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
32988 cs->commands_pending = 0;
32989 cs->cur_at_seq = 0;
32990 cs->gotfwver = -1;
32991 - cs->open_count = 0;
32992 + local_set(&cs->open_count, 0);
32993 cs->dev = NULL;
32994 cs->tty = NULL;
32995 cs->tty_dev = NULL;
32996 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
32997 index 212efaf..f187c6b 100644
32998 --- a/drivers/isdn/gigaset/gigaset.h
32999 +++ b/drivers/isdn/gigaset/gigaset.h
33000 @@ -35,6 +35,7 @@
33001 #include <linux/tty_driver.h>
33002 #include <linux/list.h>
33003 #include <linux/atomic.h>
33004 +#include <asm/local.h>
33005
33006 #define GIG_VERSION {0, 5, 0, 0}
33007 #define GIG_COMPAT {0, 4, 0, 0}
33008 @@ -433,7 +434,7 @@ struct cardstate {
33009 spinlock_t cmdlock;
33010 unsigned curlen, cmdbytes;
33011
33012 - unsigned open_count;
33013 + local_t open_count;
33014 struct tty_struct *tty;
33015 struct tasklet_struct if_wake_tasklet;
33016 unsigned control_state;
33017 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33018 index ee0a549..a7c9798 100644
33019 --- a/drivers/isdn/gigaset/interface.c
33020 +++ b/drivers/isdn/gigaset/interface.c
33021 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33022 }
33023 tty->driver_data = cs;
33024
33025 - ++cs->open_count;
33026 -
33027 - if (cs->open_count == 1) {
33028 + if (local_inc_return(&cs->open_count) == 1) {
33029 spin_lock_irqsave(&cs->lock, flags);
33030 cs->tty = tty;
33031 spin_unlock_irqrestore(&cs->lock, flags);
33032 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33033
33034 if (!cs->connected)
33035 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33036 - else if (!cs->open_count)
33037 + else if (!local_read(&cs->open_count))
33038 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33039 else {
33040 - if (!--cs->open_count) {
33041 + if (!local_dec_return(&cs->open_count)) {
33042 spin_lock_irqsave(&cs->lock, flags);
33043 cs->tty = NULL;
33044 spin_unlock_irqrestore(&cs->lock, flags);
33045 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
33046 if (!cs->connected) {
33047 gig_dbg(DEBUG_IF, "not connected");
33048 retval = -ENODEV;
33049 - } else if (!cs->open_count)
33050 + } else if (!local_read(&cs->open_count))
33051 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33052 else {
33053 retval = 0;
33054 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
33055 retval = -ENODEV;
33056 goto done;
33057 }
33058 - if (!cs->open_count) {
33059 + if (!local_read(&cs->open_count)) {
33060 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33061 retval = -ENODEV;
33062 goto done;
33063 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
33064 if (!cs->connected) {
33065 gig_dbg(DEBUG_IF, "not connected");
33066 retval = -ENODEV;
33067 - } else if (!cs->open_count)
33068 + } else if (!local_read(&cs->open_count))
33069 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33070 else if (cs->mstate != MS_LOCKED) {
33071 dev_warn(cs->dev, "can't write to unlocked device\n");
33072 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
33073
33074 if (!cs->connected)
33075 gig_dbg(DEBUG_IF, "not connected");
33076 - else if (!cs->open_count)
33077 + else if (!local_read(&cs->open_count))
33078 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33079 else if (cs->mstate != MS_LOCKED)
33080 dev_warn(cs->dev, "can't write to unlocked device\n");
33081 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
33082
33083 if (!cs->connected)
33084 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33085 - else if (!cs->open_count)
33086 + else if (!local_read(&cs->open_count))
33087 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33088 else
33089 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
33090 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
33091
33092 if (!cs->connected)
33093 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33094 - else if (!cs->open_count)
33095 + else if (!local_read(&cs->open_count))
33096 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33097 else
33098 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
33099 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
33100 goto out;
33101 }
33102
33103 - if (!cs->open_count) {
33104 + if (!local_read(&cs->open_count)) {
33105 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33106 goto out;
33107 }
33108 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33109 index 2a57da59..e7a12ed 100644
33110 --- a/drivers/isdn/hardware/avm/b1.c
33111 +++ b/drivers/isdn/hardware/avm/b1.c
33112 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
33113 }
33114 if (left) {
33115 if (t4file->user) {
33116 - if (copy_from_user(buf, dp, left))
33117 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33118 return -EFAULT;
33119 } else {
33120 memcpy(buf, dp, left);
33121 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
33122 }
33123 if (left) {
33124 if (config->user) {
33125 - if (copy_from_user(buf, dp, left))
33126 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33127 return -EFAULT;
33128 } else {
33129 memcpy(buf, dp, left);
33130 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33131 index 85784a7..a19ca98 100644
33132 --- a/drivers/isdn/hardware/eicon/divasync.h
33133 +++ b/drivers/isdn/hardware/eicon/divasync.h
33134 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33135 } diva_didd_add_adapter_t;
33136 typedef struct _diva_didd_remove_adapter {
33137 IDI_CALL p_request;
33138 -} diva_didd_remove_adapter_t;
33139 +} __no_const diva_didd_remove_adapter_t;
33140 typedef struct _diva_didd_read_adapter_array {
33141 void * buffer;
33142 dword length;
33143 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33144 index a3bd163..8956575 100644
33145 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33146 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33147 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33148 typedef struct _diva_os_idi_adapter_interface {
33149 diva_init_card_proc_t cleanup_adapter_proc;
33150 diva_cmd_card_proc_t cmd_proc;
33151 -} diva_os_idi_adapter_interface_t;
33152 +} __no_const diva_os_idi_adapter_interface_t;
33153
33154 typedef struct _diva_os_xdi_adapter {
33155 struct list_head link;
33156 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33157 index 1f355bb..43f1fea 100644
33158 --- a/drivers/isdn/icn/icn.c
33159 +++ b/drivers/isdn/icn/icn.c
33160 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
33161 if (count > len)
33162 count = len;
33163 if (user) {
33164 - if (copy_from_user(msg, buf, count))
33165 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33166 return -EFAULT;
33167 } else
33168 memcpy(msg, buf, count);
33169 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33170 index b5fdcb7..5b6c59f 100644
33171 --- a/drivers/lguest/core.c
33172 +++ b/drivers/lguest/core.c
33173 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33174 * it's worked so far. The end address needs +1 because __get_vm_area
33175 * allocates an extra guard page, so we need space for that.
33176 */
33177 +
33178 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33179 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33180 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33181 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33182 +#else
33183 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33184 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33185 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33186 +#endif
33187 +
33188 if (!switcher_vma) {
33189 err = -ENOMEM;
33190 printk("lguest: could not map switcher pages high\n");
33191 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33192 * Now the Switcher is mapped at the right address, we can't fail!
33193 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33194 */
33195 - memcpy(switcher_vma->addr, start_switcher_text,
33196 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33197 end_switcher_text - start_switcher_text);
33198
33199 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33200 diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
33201 index ff4a0bc..f5fdd9c 100644
33202 --- a/drivers/lguest/lguest_user.c
33203 +++ b/drivers/lguest/lguest_user.c
33204 @@ -198,6 +198,7 @@ static int user_send_irq(struct lg_cpu *cpu, const unsigned long __user *input)
33205 * Once our Guest is initialized, the Launcher makes it run by reading
33206 * from /dev/lguest.
33207 */
33208 +static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o) __size_overflow(3);
33209 static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o)
33210 {
33211 struct lguest *lg = file->private_data;
33212 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33213 index 3980903..ce25c5e 100644
33214 --- a/drivers/lguest/x86/core.c
33215 +++ b/drivers/lguest/x86/core.c
33216 @@ -59,7 +59,7 @@ static struct {
33217 /* Offset from where switcher.S was compiled to where we've copied it */
33218 static unsigned long switcher_offset(void)
33219 {
33220 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33221 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33222 }
33223
33224 /* This cpu's struct lguest_pages. */
33225 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33226 * These copies are pretty cheap, so we do them unconditionally: */
33227 /* Save the current Host top-level page directory.
33228 */
33229 +
33230 +#ifdef CONFIG_PAX_PER_CPU_PGD
33231 + pages->state.host_cr3 = read_cr3();
33232 +#else
33233 pages->state.host_cr3 = __pa(current->mm->pgd);
33234 +#endif
33235 +
33236 /*
33237 * Set up the Guest's page tables to see this CPU's pages (and no
33238 * other CPU's pages).
33239 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33240 * compiled-in switcher code and the high-mapped copy we just made.
33241 */
33242 for (i = 0; i < IDT_ENTRIES; i++)
33243 - default_idt_entries[i] += switcher_offset();
33244 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33245
33246 /*
33247 * Set up the Switcher's per-cpu areas.
33248 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33249 * it will be undisturbed when we switch. To change %cs and jump we
33250 * need this structure to feed to Intel's "lcall" instruction.
33251 */
33252 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33253 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33254 lguest_entry.segment = LGUEST_CS;
33255
33256 /*
33257 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33258 index 40634b0..4f5855e 100644
33259 --- a/drivers/lguest/x86/switcher_32.S
33260 +++ b/drivers/lguest/x86/switcher_32.S
33261 @@ -87,6 +87,7 @@
33262 #include <asm/page.h>
33263 #include <asm/segment.h>
33264 #include <asm/lguest.h>
33265 +#include <asm/processor-flags.h>
33266
33267 // We mark the start of the code to copy
33268 // It's placed in .text tho it's never run here
33269 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33270 // Changes type when we load it: damn Intel!
33271 // For after we switch over our page tables
33272 // That entry will be read-only: we'd crash.
33273 +
33274 +#ifdef CONFIG_PAX_KERNEXEC
33275 + mov %cr0, %edx
33276 + xor $X86_CR0_WP, %edx
33277 + mov %edx, %cr0
33278 +#endif
33279 +
33280 movl $(GDT_ENTRY_TSS*8), %edx
33281 ltr %dx
33282
33283 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33284 // Let's clear it again for our return.
33285 // The GDT descriptor of the Host
33286 // Points to the table after two "size" bytes
33287 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33288 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33289 // Clear "used" from type field (byte 5, bit 2)
33290 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33291 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33292 +
33293 +#ifdef CONFIG_PAX_KERNEXEC
33294 + mov %cr0, %eax
33295 + xor $X86_CR0_WP, %eax
33296 + mov %eax, %cr0
33297 +#endif
33298
33299 // Once our page table's switched, the Guest is live!
33300 // The Host fades as we run this final step.
33301 @@ -295,13 +309,12 @@ deliver_to_host:
33302 // I consulted gcc, and it gave
33303 // These instructions, which I gladly credit:
33304 leal (%edx,%ebx,8), %eax
33305 - movzwl (%eax),%edx
33306 - movl 4(%eax), %eax
33307 - xorw %ax, %ax
33308 - orl %eax, %edx
33309 + movl 4(%eax), %edx
33310 + movw (%eax), %dx
33311 // Now the address of the handler's in %edx
33312 // We call it now: its "iret" drops us home.
33313 - jmp *%edx
33314 + ljmp $__KERNEL_CS, $1f
33315 +1: jmp *%edx
33316
33317 // Every interrupt can come to us here
33318 // But we must truly tell each apart.
33319 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33320 index 4daf9e5..b8d1d0f 100644
33321 --- a/drivers/macintosh/macio_asic.c
33322 +++ b/drivers/macintosh/macio_asic.c
33323 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33324 * MacIO is matched against any Apple ID, it's probe() function
33325 * will then decide wether it applies or not
33326 */
33327 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33328 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33329 .vendor = PCI_VENDOR_ID_APPLE,
33330 .device = PCI_ANY_ID,
33331 .subvendor = PCI_ANY_ID,
33332 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33333 index 1ce84ed..0fdd40a 100644
33334 --- a/drivers/md/dm-ioctl.c
33335 +++ b/drivers/md/dm-ioctl.c
33336 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33337 cmd == DM_LIST_VERSIONS_CMD)
33338 return 0;
33339
33340 - if ((cmd == DM_DEV_CREATE_CMD)) {
33341 + if (cmd == DM_DEV_CREATE_CMD) {
33342 if (!*param->name) {
33343 DMWARN("name not supplied when creating device");
33344 return -EINVAL;
33345 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33346 index 9bfd057..5373ff3 100644
33347 --- a/drivers/md/dm-raid1.c
33348 +++ b/drivers/md/dm-raid1.c
33349 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33350
33351 struct mirror {
33352 struct mirror_set *ms;
33353 - atomic_t error_count;
33354 + atomic_unchecked_t error_count;
33355 unsigned long error_type;
33356 struct dm_dev *dev;
33357 sector_t offset;
33358 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33359 struct mirror *m;
33360
33361 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33362 - if (!atomic_read(&m->error_count))
33363 + if (!atomic_read_unchecked(&m->error_count))
33364 return m;
33365
33366 return NULL;
33367 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33368 * simple way to tell if a device has encountered
33369 * errors.
33370 */
33371 - atomic_inc(&m->error_count);
33372 + atomic_inc_unchecked(&m->error_count);
33373
33374 if (test_and_set_bit(error_type, &m->error_type))
33375 return;
33376 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33377 struct mirror *m = get_default_mirror(ms);
33378
33379 do {
33380 - if (likely(!atomic_read(&m->error_count)))
33381 + if (likely(!atomic_read_unchecked(&m->error_count)))
33382 return m;
33383
33384 if (m-- == ms->mirror)
33385 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33386 {
33387 struct mirror *default_mirror = get_default_mirror(m->ms);
33388
33389 - return !atomic_read(&default_mirror->error_count);
33390 + return !atomic_read_unchecked(&default_mirror->error_count);
33391 }
33392
33393 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33394 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33395 */
33396 if (likely(region_in_sync(ms, region, 1)))
33397 m = choose_mirror(ms, bio->bi_sector);
33398 - else if (m && atomic_read(&m->error_count))
33399 + else if (m && atomic_read_unchecked(&m->error_count))
33400 m = NULL;
33401
33402 if (likely(m))
33403 @@ -848,6 +848,10 @@ static void do_mirror(struct work_struct *work)
33404 static struct mirror_set *alloc_context(unsigned int nr_mirrors,
33405 uint32_t region_size,
33406 struct dm_target *ti,
33407 + struct dm_dirty_log *dl) __size_overflow(1);
33408 +static struct mirror_set *alloc_context(unsigned int nr_mirrors,
33409 + uint32_t region_size,
33410 + struct dm_target *ti,
33411 struct dm_dirty_log *dl)
33412 {
33413 size_t len;
33414 @@ -937,7 +941,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33415 }
33416
33417 ms->mirror[mirror].ms = ms;
33418 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33419 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33420 ms->mirror[mirror].error_type = 0;
33421 ms->mirror[mirror].offset = offset;
33422
33423 @@ -1347,7 +1351,7 @@ static void mirror_resume(struct dm_target *ti)
33424 */
33425 static char device_status_char(struct mirror *m)
33426 {
33427 - if (!atomic_read(&(m->error_count)))
33428 + if (!atomic_read_unchecked(&(m->error_count)))
33429 return 'A';
33430
33431 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33432 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33433 index 3d80cf0..7d98e1a 100644
33434 --- a/drivers/md/dm-stripe.c
33435 +++ b/drivers/md/dm-stripe.c
33436 @@ -20,7 +20,7 @@ struct stripe {
33437 struct dm_dev *dev;
33438 sector_t physical_start;
33439
33440 - atomic_t error_count;
33441 + atomic_unchecked_t error_count;
33442 };
33443
33444 struct stripe_c {
33445 @@ -55,6 +55,7 @@ static void trigger_event(struct work_struct *work)
33446 dm_table_event(sc->ti->table);
33447 }
33448
33449 +static inline struct stripe_c *alloc_context(unsigned int stripes) __size_overflow(1);
33450 static inline struct stripe_c *alloc_context(unsigned int stripes)
33451 {
33452 size_t len;
33453 @@ -192,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33454 kfree(sc);
33455 return r;
33456 }
33457 - atomic_set(&(sc->stripe[i].error_count), 0);
33458 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33459 }
33460
33461 ti->private = sc;
33462 @@ -314,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33463 DMEMIT("%d ", sc->stripes);
33464 for (i = 0; i < sc->stripes; i++) {
33465 DMEMIT("%s ", sc->stripe[i].dev->name);
33466 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33467 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33468 'D' : 'A';
33469 }
33470 buffer[i] = '\0';
33471 @@ -361,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33472 */
33473 for (i = 0; i < sc->stripes; i++)
33474 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33475 - atomic_inc(&(sc->stripe[i].error_count));
33476 - if (atomic_read(&(sc->stripe[i].error_count)) <
33477 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33478 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33479 DM_IO_ERROR_THRESHOLD)
33480 schedule_work(&sc->trigger_event);
33481 }
33482 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33483 index 63cc542..8d45caf3 100644
33484 --- a/drivers/md/dm-table.c
33485 +++ b/drivers/md/dm-table.c
33486 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33487 if (!dev_size)
33488 return 0;
33489
33490 - if ((start >= dev_size) || (start + len > dev_size)) {
33491 + if ((start >= dev_size) || (len > dev_size - start)) {
33492 DMWARN("%s: %s too small for target: "
33493 "start=%llu, len=%llu, dev_size=%llu",
33494 dm_device_name(ti->table->md), bdevname(bdev, b),
33495 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33496 index 237571a..fb6d19b 100644
33497 --- a/drivers/md/dm-thin-metadata.c
33498 +++ b/drivers/md/dm-thin-metadata.c
33499 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33500
33501 pmd->info.tm = tm;
33502 pmd->info.levels = 2;
33503 - pmd->info.value_type.context = pmd->data_sm;
33504 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33505 pmd->info.value_type.size = sizeof(__le64);
33506 pmd->info.value_type.inc = data_block_inc;
33507 pmd->info.value_type.dec = data_block_dec;
33508 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33509
33510 pmd->bl_info.tm = tm;
33511 pmd->bl_info.levels = 1;
33512 - pmd->bl_info.value_type.context = pmd->data_sm;
33513 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33514 pmd->bl_info.value_type.size = sizeof(__le64);
33515 pmd->bl_info.value_type.inc = data_block_inc;
33516 pmd->bl_info.value_type.dec = data_block_dec;
33517 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33518 index b89c548..2af3ce4 100644
33519 --- a/drivers/md/dm.c
33520 +++ b/drivers/md/dm.c
33521 @@ -176,9 +176,9 @@ struct mapped_device {
33522 /*
33523 * Event handling.
33524 */
33525 - atomic_t event_nr;
33526 + atomic_unchecked_t event_nr;
33527 wait_queue_head_t eventq;
33528 - atomic_t uevent_seq;
33529 + atomic_unchecked_t uevent_seq;
33530 struct list_head uevent_list;
33531 spinlock_t uevent_lock; /* Protect access to uevent_list */
33532
33533 @@ -1844,8 +1844,8 @@ static struct mapped_device *alloc_dev(int minor)
33534 rwlock_init(&md->map_lock);
33535 atomic_set(&md->holders, 1);
33536 atomic_set(&md->open_count, 0);
33537 - atomic_set(&md->event_nr, 0);
33538 - atomic_set(&md->uevent_seq, 0);
33539 + atomic_set_unchecked(&md->event_nr, 0);
33540 + atomic_set_unchecked(&md->uevent_seq, 0);
33541 INIT_LIST_HEAD(&md->uevent_list);
33542 spin_lock_init(&md->uevent_lock);
33543
33544 @@ -1979,7 +1979,7 @@ static void event_callback(void *context)
33545
33546 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33547
33548 - atomic_inc(&md->event_nr);
33549 + atomic_inc_unchecked(&md->event_nr);
33550 wake_up(&md->eventq);
33551 }
33552
33553 @@ -2621,18 +2621,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33554
33555 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33556 {
33557 - return atomic_add_return(1, &md->uevent_seq);
33558 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33559 }
33560
33561 uint32_t dm_get_event_nr(struct mapped_device *md)
33562 {
33563 - return atomic_read(&md->event_nr);
33564 + return atomic_read_unchecked(&md->event_nr);
33565 }
33566
33567 int dm_wait_event(struct mapped_device *md, int event_nr)
33568 {
33569 return wait_event_interruptible(md->eventq,
33570 - (event_nr != atomic_read(&md->event_nr)));
33571 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33572 }
33573
33574 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33575 diff --git a/drivers/md/md.c b/drivers/md/md.c
33576 index 58027d8..d9cddcd 100644
33577 --- a/drivers/md/md.c
33578 +++ b/drivers/md/md.c
33579 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33580 * start build, activate spare
33581 */
33582 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33583 -static atomic_t md_event_count;
33584 +static atomic_unchecked_t md_event_count;
33585 void md_new_event(struct mddev *mddev)
33586 {
33587 - atomic_inc(&md_event_count);
33588 + atomic_inc_unchecked(&md_event_count);
33589 wake_up(&md_event_waiters);
33590 }
33591 EXPORT_SYMBOL_GPL(md_new_event);
33592 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33593 */
33594 static void md_new_event_inintr(struct mddev *mddev)
33595 {
33596 - atomic_inc(&md_event_count);
33597 + atomic_inc_unchecked(&md_event_count);
33598 wake_up(&md_event_waiters);
33599 }
33600
33601 @@ -1524,7 +1524,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33602
33603 rdev->preferred_minor = 0xffff;
33604 rdev->data_offset = le64_to_cpu(sb->data_offset);
33605 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33606 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33607
33608 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33609 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33610 @@ -1743,7 +1743,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33611 else
33612 sb->resync_offset = cpu_to_le64(0);
33613
33614 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33615 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33616
33617 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33618 sb->size = cpu_to_le64(mddev->dev_sectors);
33619 @@ -2689,7 +2689,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33620 static ssize_t
33621 errors_show(struct md_rdev *rdev, char *page)
33622 {
33623 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33624 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33625 }
33626
33627 static ssize_t
33628 @@ -2698,7 +2698,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33629 char *e;
33630 unsigned long n = simple_strtoul(buf, &e, 10);
33631 if (*buf && (*e == 0 || *e == '\n')) {
33632 - atomic_set(&rdev->corrected_errors, n);
33633 + atomic_set_unchecked(&rdev->corrected_errors, n);
33634 return len;
33635 }
33636 return -EINVAL;
33637 @@ -3084,8 +3084,8 @@ int md_rdev_init(struct md_rdev *rdev)
33638 rdev->sb_loaded = 0;
33639 rdev->bb_page = NULL;
33640 atomic_set(&rdev->nr_pending, 0);
33641 - atomic_set(&rdev->read_errors, 0);
33642 - atomic_set(&rdev->corrected_errors, 0);
33643 + atomic_set_unchecked(&rdev->read_errors, 0);
33644 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33645
33646 INIT_LIST_HEAD(&rdev->same_set);
33647 init_waitqueue_head(&rdev->blocked_wait);
33648 @@ -6736,7 +6736,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33649
33650 spin_unlock(&pers_lock);
33651 seq_printf(seq, "\n");
33652 - seq->poll_event = atomic_read(&md_event_count);
33653 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33654 return 0;
33655 }
33656 if (v == (void*)2) {
33657 @@ -6828,7 +6828,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33658 chunk_kb ? "KB" : "B");
33659 if (bitmap->file) {
33660 seq_printf(seq, ", file: ");
33661 - seq_path(seq, &bitmap->file->f_path, " \t\n");
33662 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33663 }
33664
33665 seq_printf(seq, "\n");
33666 @@ -6859,7 +6859,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33667 return error;
33668
33669 seq = file->private_data;
33670 - seq->poll_event = atomic_read(&md_event_count);
33671 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33672 return error;
33673 }
33674
33675 @@ -6873,7 +6873,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33676 /* always allow read */
33677 mask = POLLIN | POLLRDNORM;
33678
33679 - if (seq->poll_event != atomic_read(&md_event_count))
33680 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33681 mask |= POLLERR | POLLPRI;
33682 return mask;
33683 }
33684 @@ -6917,7 +6917,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33685 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33686 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33687 (int)part_stat_read(&disk->part0, sectors[1]) -
33688 - atomic_read(&disk->sync_io);
33689 + atomic_read_unchecked(&disk->sync_io);
33690 /* sync IO will cause sync_io to increase before the disk_stats
33691 * as sync_io is counted when a request starts, and
33692 * disk_stats is counted when it completes.
33693 diff --git a/drivers/md/md.h b/drivers/md/md.h
33694 index 44c63df..b795d1a 100644
33695 --- a/drivers/md/md.h
33696 +++ b/drivers/md/md.h
33697 @@ -93,13 +93,13 @@ struct md_rdev {
33698 * only maintained for arrays that
33699 * support hot removal
33700 */
33701 - atomic_t read_errors; /* number of consecutive read errors that
33702 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33703 * we have tried to ignore.
33704 */
33705 struct timespec last_read_error; /* monotonic time since our
33706 * last read error
33707 */
33708 - atomic_t corrected_errors; /* number of corrected read errors,
33709 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33710 * for reporting to userspace and storing
33711 * in superblock.
33712 */
33713 @@ -421,7 +421,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33714
33715 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33716 {
33717 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33718 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33719 }
33720
33721 struct md_personality
33722 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33723 index 50ed53b..4f29d7d 100644
33724 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33725 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33726 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
33727 /*----------------------------------------------------------------*/
33728
33729 struct sm_checker {
33730 - struct dm_space_map sm;
33731 + dm_space_map_no_const sm;
33732
33733 struct count_array old_counts;
33734 struct count_array counts;
33735 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33736 index fc469ba..2d91555 100644
33737 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33738 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33739 @@ -23,7 +23,7 @@
33740 * Space map interface.
33741 */
33742 struct sm_disk {
33743 - struct dm_space_map sm;
33744 + dm_space_map_no_const sm;
33745
33746 struct ll_disk ll;
33747 struct ll_disk old_ll;
33748 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33749 index e89ae5e..062e4c2 100644
33750 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33751 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33752 @@ -43,7 +43,7 @@ struct block_op {
33753 };
33754
33755 struct sm_metadata {
33756 - struct dm_space_map sm;
33757 + dm_space_map_no_const sm;
33758
33759 struct ll_disk ll;
33760 struct ll_disk old_ll;
33761 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33762 index 1cbfc6b..56e1dbb 100644
33763 --- a/drivers/md/persistent-data/dm-space-map.h
33764 +++ b/drivers/md/persistent-data/dm-space-map.h
33765 @@ -60,6 +60,7 @@ struct dm_space_map {
33766 int (*root_size)(struct dm_space_map *sm, size_t *result);
33767 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33768 };
33769 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33770
33771 /*----------------------------------------------------------------*/
33772
33773 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33774 index edc735a..e9b97f1 100644
33775 --- a/drivers/md/raid1.c
33776 +++ b/drivers/md/raid1.c
33777 @@ -1645,7 +1645,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33778 if (r1_sync_page_io(rdev, sect, s,
33779 bio->bi_io_vec[idx].bv_page,
33780 READ) != 0)
33781 - atomic_add(s, &rdev->corrected_errors);
33782 + atomic_add_unchecked(s, &rdev->corrected_errors);
33783 }
33784 sectors -= s;
33785 sect += s;
33786 @@ -1859,7 +1859,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33787 test_bit(In_sync, &rdev->flags)) {
33788 if (r1_sync_page_io(rdev, sect, s,
33789 conf->tmppage, READ)) {
33790 - atomic_add(s, &rdev->corrected_errors);
33791 + atomic_add_unchecked(s, &rdev->corrected_errors);
33792 printk(KERN_INFO
33793 "md/raid1:%s: read error corrected "
33794 "(%d sectors at %llu on %s)\n",
33795 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33796 index 1898389..a3aa617 100644
33797 --- a/drivers/md/raid10.c
33798 +++ b/drivers/md/raid10.c
33799 @@ -1636,7 +1636,7 @@ static void end_sync_read(struct bio *bio, int error)
33800 /* The write handler will notice the lack of
33801 * R10BIO_Uptodate and record any errors etc
33802 */
33803 - atomic_add(r10_bio->sectors,
33804 + atomic_add_unchecked(r10_bio->sectors,
33805 &conf->mirrors[d].rdev->corrected_errors);
33806
33807 /* for reconstruct, we always reschedule after a read.
33808 @@ -1987,7 +1987,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33809 {
33810 struct timespec cur_time_mon;
33811 unsigned long hours_since_last;
33812 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33813 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33814
33815 ktime_get_ts(&cur_time_mon);
33816
33817 @@ -2009,9 +2009,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33818 * overflowing the shift of read_errors by hours_since_last.
33819 */
33820 if (hours_since_last >= 8 * sizeof(read_errors))
33821 - atomic_set(&rdev->read_errors, 0);
33822 + atomic_set_unchecked(&rdev->read_errors, 0);
33823 else
33824 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33825 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33826 }
33827
33828 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33829 @@ -2065,8 +2065,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33830 return;
33831
33832 check_decay_read_errors(mddev, rdev);
33833 - atomic_inc(&rdev->read_errors);
33834 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33835 + atomic_inc_unchecked(&rdev->read_errors);
33836 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33837 char b[BDEVNAME_SIZE];
33838 bdevname(rdev->bdev, b);
33839
33840 @@ -2074,7 +2074,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33841 "md/raid10:%s: %s: Raid device exceeded "
33842 "read_error threshold [cur %d:max %d]\n",
33843 mdname(mddev), b,
33844 - atomic_read(&rdev->read_errors), max_read_errors);
33845 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33846 printk(KERN_NOTICE
33847 "md/raid10:%s: %s: Failing raid device\n",
33848 mdname(mddev), b);
33849 @@ -2223,7 +2223,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33850 (unsigned long long)(
33851 sect + rdev->data_offset),
33852 bdevname(rdev->bdev, b));
33853 - atomic_add(s, &rdev->corrected_errors);
33854 + atomic_add_unchecked(s, &rdev->corrected_errors);
33855 }
33856
33857 rdev_dec_pending(rdev, mddev);
33858 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33859 index d1162e5..c7cd902 100644
33860 --- a/drivers/md/raid5.c
33861 +++ b/drivers/md/raid5.c
33862 @@ -1687,18 +1687,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33863 (unsigned long long)(sh->sector
33864 + rdev->data_offset),
33865 bdevname(rdev->bdev, b));
33866 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33867 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33868 clear_bit(R5_ReadError, &sh->dev[i].flags);
33869 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33870 }
33871 - if (atomic_read(&rdev->read_errors))
33872 - atomic_set(&rdev->read_errors, 0);
33873 + if (atomic_read_unchecked(&rdev->read_errors))
33874 + atomic_set_unchecked(&rdev->read_errors, 0);
33875 } else {
33876 const char *bdn = bdevname(rdev->bdev, b);
33877 int retry = 0;
33878
33879 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33880 - atomic_inc(&rdev->read_errors);
33881 + atomic_inc_unchecked(&rdev->read_errors);
33882 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33883 printk_ratelimited(
33884 KERN_WARNING
33885 @@ -1727,7 +1727,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33886 (unsigned long long)(sh->sector
33887 + rdev->data_offset),
33888 bdn);
33889 - else if (atomic_read(&rdev->read_errors)
33890 + else if (atomic_read_unchecked(&rdev->read_errors)
33891 > conf->max_nr_stripes)
33892 printk(KERN_WARNING
33893 "md/raid:%s: Too many read errors, failing device %s.\n",
33894 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33895 index ce4f858..7bcfb46 100644
33896 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33897 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33898 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33899 .subvendor = _subvend, .subdevice = _subdev, \
33900 .driver_data = (unsigned long)&_driverdata }
33901
33902 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33903 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33904 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33905 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33906 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33907 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33908 index a7d876f..8c21b61 100644
33909 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33910 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33911 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33912 union {
33913 dmx_ts_cb ts;
33914 dmx_section_cb sec;
33915 - } cb;
33916 + } __no_const cb;
33917
33918 struct dvb_demux *demux;
33919 void *priv;
33920 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33921 index 00a6732..70a682e 100644
33922 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33923 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33924 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33925 const struct dvb_device *template, void *priv, int type)
33926 {
33927 struct dvb_device *dvbdev;
33928 - struct file_operations *dvbdevfops;
33929 + file_operations_no_const *dvbdevfops;
33930 struct device *clsdev;
33931 int minor;
33932 int id;
33933 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33934 index 3940bb0..fb3952a 100644
33935 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33936 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33937 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33938
33939 struct dib0700_adapter_state {
33940 int (*set_param_save) (struct dvb_frontend *);
33941 -};
33942 +} __no_const;
33943
33944 static int dib7070_set_param_override(struct dvb_frontend *fe)
33945 {
33946 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33947 index 451c5a7..649f711 100644
33948 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33949 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33950 @@ -95,7 +95,7 @@ struct su3000_state {
33951
33952 struct s6x0_state {
33953 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33954 -};
33955 +} __no_const;
33956
33957 /* debug */
33958 static int dvb_usb_dw2102_debug;
33959 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33960 index 404f63a..4796533 100644
33961 --- a/drivers/media/dvb/frontends/dib3000.h
33962 +++ b/drivers/media/dvb/frontends/dib3000.h
33963 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33964 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33965 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33966 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33967 -};
33968 +} __no_const;
33969
33970 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33971 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33972 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33973 index 8418c02..8555013 100644
33974 --- a/drivers/media/dvb/ngene/ngene-cards.c
33975 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33976 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
33977
33978 /****************************************************************************/
33979
33980 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33981 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33982 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33983 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33984 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33985 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33986 index 16a089f..ab1667d 100644
33987 --- a/drivers/media/radio/radio-cadet.c
33988 +++ b/drivers/media/radio/radio-cadet.c
33989 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33990 unsigned char readbuf[RDS_BUFFER];
33991 int i = 0;
33992
33993 + if (count > RDS_BUFFER)
33994 + return -EFAULT;
33995 mutex_lock(&dev->lock);
33996 if (dev->rdsstat == 0) {
33997 dev->rdsstat = 1;
33998 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33999 index 9cde353..8c6a1c3 100644
34000 --- a/drivers/media/video/au0828/au0828.h
34001 +++ b/drivers/media/video/au0828/au0828.h
34002 @@ -191,7 +191,7 @@ struct au0828_dev {
34003
34004 /* I2C */
34005 struct i2c_adapter i2c_adap;
34006 - struct i2c_algorithm i2c_algo;
34007 + i2c_algorithm_no_const i2c_algo;
34008 struct i2c_client i2c_client;
34009 u32 i2c_rc;
34010
34011 diff --git a/drivers/media/video/cpia2/cpia2_core.c b/drivers/media/video/cpia2/cpia2_core.c
34012 index ee91e295..04ad048 100644
34013 --- a/drivers/media/video/cpia2/cpia2_core.c
34014 +++ b/drivers/media/video/cpia2/cpia2_core.c
34015 @@ -86,6 +86,7 @@ static inline unsigned long kvirt_to_pa(unsigned long adr)
34016 return ret;
34017 }
34018
34019 +static void *rvmalloc(unsigned long size) __size_overflow(1);
34020 static void *rvmalloc(unsigned long size)
34021 {
34022 void *mem;
34023 diff --git a/drivers/media/video/cx18/cx18-alsa-pcm.c b/drivers/media/video/cx18/cx18-alsa-pcm.c
34024 index 82d195b..181103c 100644
34025 --- a/drivers/media/video/cx18/cx18-alsa-pcm.c
34026 +++ b/drivers/media/video/cx18/cx18-alsa-pcm.c
34027 @@ -229,6 +229,8 @@ static int snd_cx18_pcm_ioctl(struct snd_pcm_substream *substream,
34028
34029
34030 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
34031 + size_t size) __size_overflow(2);
34032 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
34033 size_t size)
34034 {
34035 struct snd_pcm_runtime *runtime = subs->runtime;
34036 diff --git a/drivers/media/video/cx231xx/cx231xx-audio.c b/drivers/media/video/cx231xx/cx231xx-audio.c
34037 index a2c2b7d..8f1bec7 100644
34038 --- a/drivers/media/video/cx231xx/cx231xx-audio.c
34039 +++ b/drivers/media/video/cx231xx/cx231xx-audio.c
34040 @@ -389,6 +389,8 @@ static int cx231xx_init_audio_bulk(struct cx231xx *dev)
34041 }
34042
34043 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
34044 + size_t size) __size_overflow(2);
34045 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
34046 size_t size)
34047 {
34048 struct snd_pcm_runtime *runtime = subs->runtime;
34049 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34050 index 04bf662..e0ac026 100644
34051 --- a/drivers/media/video/cx88/cx88-alsa.c
34052 +++ b/drivers/media/video/cx88/cx88-alsa.c
34053 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34054 * Only boards with eeprom and byte 1 at eeprom=1 have it
34055 */
34056
34057 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34058 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34059 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34060 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34061 {0, }
34062 diff --git a/drivers/media/video/em28xx/em28xx-audio.c b/drivers/media/video/em28xx/em28xx-audio.c
34063 index e2a7b77..753d0ee 100644
34064 --- a/drivers/media/video/em28xx/em28xx-audio.c
34065 +++ b/drivers/media/video/em28xx/em28xx-audio.c
34066 @@ -225,6 +225,8 @@ static int em28xx_init_audio_isoc(struct em28xx *dev)
34067 }
34068
34069 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
34070 + size_t size) __size_overflow(2);
34071 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
34072 size_t size)
34073 {
34074 struct snd_pcm_runtime *runtime = subs->runtime;
34075 diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
34076 index b09a3c8..6dcba0a 100644
34077 --- a/drivers/media/video/meye.c
34078 +++ b/drivers/media/video/meye.c
34079 @@ -72,6 +72,7 @@ static struct meye meye;
34080 /****************************************************************************/
34081 /* Memory allocation routines (stolen from bttv-driver.c) */
34082 /****************************************************************************/
34083 +static void *rvmalloc(unsigned long size) __size_overflow(1);
34084 static void *rvmalloc(unsigned long size)
34085 {
34086 void *mem;
34087 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34088 index 1fb7d5b..3901e77 100644
34089 --- a/drivers/media/video/omap/omap_vout.c
34090 +++ b/drivers/media/video/omap/omap_vout.c
34091 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34092 OMAP_VIDEO2,
34093 };
34094
34095 -static struct videobuf_queue_ops video_vbq_ops;
34096 /* Variables configurable through module params*/
34097 static u32 video1_numbuffers = 3;
34098 static u32 video2_numbuffers = 3;
34099 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34100 {
34101 struct videobuf_queue *q;
34102 struct omap_vout_device *vout = NULL;
34103 + static struct videobuf_queue_ops video_vbq_ops = {
34104 + .buf_setup = omap_vout_buffer_setup,
34105 + .buf_prepare = omap_vout_buffer_prepare,
34106 + .buf_release = omap_vout_buffer_release,
34107 + .buf_queue = omap_vout_buffer_queue,
34108 + };
34109
34110 vout = video_drvdata(file);
34111 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34112 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34113 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34114
34115 q = &vout->vbq;
34116 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34117 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34118 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34119 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34120 spin_lock_init(&vout->vbq_lock);
34121
34122 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34123 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34124 index 305e6aa..0143317 100644
34125 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34126 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34127 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34128
34129 /* I2C stuff */
34130 struct i2c_adapter i2c_adap;
34131 - struct i2c_algorithm i2c_algo;
34132 + i2c_algorithm_no_const i2c_algo;
34133 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34134 int i2c_cx25840_hack_state;
34135 int i2c_linked;
34136 diff --git a/drivers/media/video/saa7164/saa7164-encoder.c b/drivers/media/video/saa7164/saa7164-encoder.c
34137 index 2fd38a0..ddec3c4 100644
34138 --- a/drivers/media/video/saa7164/saa7164-encoder.c
34139 +++ b/drivers/media/video/saa7164/saa7164-encoder.c
34140 @@ -1136,6 +1136,8 @@ struct saa7164_user_buffer *saa7164_enc_next_buf(struct saa7164_port *port)
34141 }
34142
34143 static ssize_t fops_read(struct file *file, char __user *buffer,
34144 + size_t count, loff_t *pos) __size_overflow(3);
34145 +static ssize_t fops_read(struct file *file, char __user *buffer,
34146 size_t count, loff_t *pos)
34147 {
34148 struct saa7164_encoder_fh *fh = file->private_data;
34149 diff --git a/drivers/media/video/saa7164/saa7164-vbi.c b/drivers/media/video/saa7164/saa7164-vbi.c
34150 index e2e0341..b80056c 100644
34151 --- a/drivers/media/video/saa7164/saa7164-vbi.c
34152 +++ b/drivers/media/video/saa7164/saa7164-vbi.c
34153 @@ -1081,6 +1081,8 @@ struct saa7164_user_buffer *saa7164_vbi_next_buf(struct saa7164_port *port)
34154 }
34155
34156 static ssize_t fops_read(struct file *file, char __user *buffer,
34157 + size_t count, loff_t *pos) __size_overflow(3);
34158 +static ssize_t fops_read(struct file *file, char __user *buffer,
34159 size_t count, loff_t *pos)
34160 {
34161 struct saa7164_vbi_fh *fh = file->private_data;
34162 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34163 index 4ed1c7c2..8f15e13 100644
34164 --- a/drivers/media/video/timblogiw.c
34165 +++ b/drivers/media/video/timblogiw.c
34166 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34167
34168 /* Platform device functions */
34169
34170 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34171 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34172 .vidioc_querycap = timblogiw_querycap,
34173 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34174 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34175 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34176 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34177 };
34178
34179 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34180 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34181 .owner = THIS_MODULE,
34182 .open = timblogiw_open,
34183 .release = timblogiw_close,
34184 diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c
34185 index c969111..a7910f4 100644
34186 --- a/drivers/media/video/videobuf-dma-contig.c
34187 +++ b/drivers/media/video/videobuf-dma-contig.c
34188 @@ -184,6 +184,7 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem,
34189 return ret;
34190 }
34191
34192 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
34193 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
34194 {
34195 struct videobuf_dma_contig_memory *mem;
34196 diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
34197 index f300dea..5fc9c4a 100644
34198 --- a/drivers/media/video/videobuf-dma-sg.c
34199 +++ b/drivers/media/video/videobuf-dma-sg.c
34200 @@ -419,6 +419,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
34201 struct videobuf_dma_sg_memory
34202 */
34203
34204 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
34205 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
34206 {
34207 struct videobuf_dma_sg_memory *mem;
34208 diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
34209 index df14258..12cc7a3 100644
34210 --- a/drivers/media/video/videobuf-vmalloc.c
34211 +++ b/drivers/media/video/videobuf-vmalloc.c
34212 @@ -135,6 +135,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
34213 struct videobuf_dma_sg_memory
34214 */
34215
34216 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
34217 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
34218 {
34219 struct videobuf_vmalloc_memory *mem;
34220 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34221 index a7dc467..a55c423 100644
34222 --- a/drivers/message/fusion/mptbase.c
34223 +++ b/drivers/message/fusion/mptbase.c
34224 @@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34225 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34226 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34227
34228 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34229 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34230 +#else
34231 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34232 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34233 +#endif
34234 +
34235 /*
34236 * Rounding UP to nearest 4-kB boundary here...
34237 */
34238 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34239 index 551262e..7551198 100644
34240 --- a/drivers/message/fusion/mptsas.c
34241 +++ b/drivers/message/fusion/mptsas.c
34242 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34243 return 0;
34244 }
34245
34246 +static inline void
34247 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34248 +{
34249 + if (phy_info->port_details) {
34250 + phy_info->port_details->rphy = rphy;
34251 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34252 + ioc->name, rphy));
34253 + }
34254 +
34255 + if (rphy) {
34256 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34257 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34258 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34259 + ioc->name, rphy, rphy->dev.release));
34260 + }
34261 +}
34262 +
34263 /* no mutex */
34264 static void
34265 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34266 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34267 return NULL;
34268 }
34269
34270 -static inline void
34271 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34272 -{
34273 - if (phy_info->port_details) {
34274 - phy_info->port_details->rphy = rphy;
34275 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34276 - ioc->name, rphy));
34277 - }
34278 -
34279 - if (rphy) {
34280 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34281 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34282 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34283 - ioc->name, rphy, rphy->dev.release));
34284 - }
34285 -}
34286 -
34287 static inline struct sas_port *
34288 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34289 {
34290 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34291 index 0c3ced7..1fe34ec 100644
34292 --- a/drivers/message/fusion/mptscsih.c
34293 +++ b/drivers/message/fusion/mptscsih.c
34294 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34295
34296 h = shost_priv(SChost);
34297
34298 - if (h) {
34299 - if (h->info_kbuf == NULL)
34300 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34301 - return h->info_kbuf;
34302 - h->info_kbuf[0] = '\0';
34303 + if (!h)
34304 + return NULL;
34305
34306 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34307 - h->info_kbuf[size-1] = '\0';
34308 - }
34309 + if (h->info_kbuf == NULL)
34310 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34311 + return h->info_kbuf;
34312 + h->info_kbuf[0] = '\0';
34313 +
34314 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34315 + h->info_kbuf[size-1] = '\0';
34316
34317 return h->info_kbuf;
34318 }
34319 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34320 index 6d115c7..58ff7fd 100644
34321 --- a/drivers/message/i2o/i2o_proc.c
34322 +++ b/drivers/message/i2o/i2o_proc.c
34323 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34324 "Array Controller Device"
34325 };
34326
34327 -static char *chtostr(u8 * chars, int n)
34328 -{
34329 - char tmp[256];
34330 - tmp[0] = 0;
34331 - return strncat(tmp, (char *)chars, n);
34332 -}
34333 -
34334 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34335 char *group)
34336 {
34337 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34338
34339 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34340 seq_printf(seq, "%-#8x", ddm_table.module_id);
34341 - seq_printf(seq, "%-29s",
34342 - chtostr(ddm_table.module_name_version, 28));
34343 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34344 seq_printf(seq, "%9d ", ddm_table.data_size);
34345 seq_printf(seq, "%8d", ddm_table.code_size);
34346
34347 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34348
34349 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34350 seq_printf(seq, "%-#8x", dst->module_id);
34351 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34352 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34353 + seq_printf(seq, "%-.28s", dst->module_name_version);
34354 + seq_printf(seq, "%-.8s", dst->date);
34355 seq_printf(seq, "%8d ", dst->module_size);
34356 seq_printf(seq, "%8d ", dst->mpb_size);
34357 seq_printf(seq, "0x%04x", dst->module_flags);
34358 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34359 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34360 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34361 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34362 - seq_printf(seq, "Vendor info : %s\n",
34363 - chtostr((u8 *) (work32 + 2), 16));
34364 - seq_printf(seq, "Product info : %s\n",
34365 - chtostr((u8 *) (work32 + 6), 16));
34366 - seq_printf(seq, "Description : %s\n",
34367 - chtostr((u8 *) (work32 + 10), 16));
34368 - seq_printf(seq, "Product rev. : %s\n",
34369 - chtostr((u8 *) (work32 + 14), 8));
34370 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34371 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34372 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34373 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34374
34375 seq_printf(seq, "Serial number : ");
34376 print_serial_number(seq, (u8 *) (work32 + 16),
34377 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34378 }
34379
34380 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34381 - seq_printf(seq, "Module name : %s\n",
34382 - chtostr(result.module_name, 24));
34383 - seq_printf(seq, "Module revision : %s\n",
34384 - chtostr(result.module_rev, 8));
34385 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34386 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34387
34388 seq_printf(seq, "Serial number : ");
34389 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34390 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34391 return 0;
34392 }
34393
34394 - seq_printf(seq, "Device name : %s\n",
34395 - chtostr(result.device_name, 64));
34396 - seq_printf(seq, "Service name : %s\n",
34397 - chtostr(result.service_name, 64));
34398 - seq_printf(seq, "Physical name : %s\n",
34399 - chtostr(result.physical_location, 64));
34400 - seq_printf(seq, "Instance number : %s\n",
34401 - chtostr(result.instance_number, 4));
34402 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34403 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34404 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34405 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34406
34407 return 0;
34408 }
34409 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34410 index a8c08f3..155fe3d 100644
34411 --- a/drivers/message/i2o/iop.c
34412 +++ b/drivers/message/i2o/iop.c
34413 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34414
34415 spin_lock_irqsave(&c->context_list_lock, flags);
34416
34417 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34418 - atomic_inc(&c->context_list_counter);
34419 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34420 + atomic_inc_unchecked(&c->context_list_counter);
34421
34422 - entry->context = atomic_read(&c->context_list_counter);
34423 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34424
34425 list_add(&entry->list, &c->context_list);
34426
34427 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34428
34429 #if BITS_PER_LONG == 64
34430 spin_lock_init(&c->context_list_lock);
34431 - atomic_set(&c->context_list_counter, 0);
34432 + atomic_set_unchecked(&c->context_list_counter, 0);
34433 INIT_LIST_HEAD(&c->context_list);
34434 #endif
34435
34436 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34437 index 7ce65f4..e66e9bc 100644
34438 --- a/drivers/mfd/abx500-core.c
34439 +++ b/drivers/mfd/abx500-core.c
34440 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34441
34442 struct abx500_device_entry {
34443 struct list_head list;
34444 - struct abx500_ops ops;
34445 + abx500_ops_no_const ops;
34446 struct device *dev;
34447 };
34448
34449 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34450 index a9223ed..4127b13 100644
34451 --- a/drivers/mfd/janz-cmodio.c
34452 +++ b/drivers/mfd/janz-cmodio.c
34453 @@ -13,6 +13,7 @@
34454
34455 #include <linux/kernel.h>
34456 #include <linux/module.h>
34457 +#include <linux/slab.h>
34458 #include <linux/init.h>
34459 #include <linux/pci.h>
34460 #include <linux/interrupt.h>
34461 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34462 index a981e2a..5ca0c8b 100644
34463 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34464 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34465 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34466 * the lid is closed. This leads to interrupts as soon as a little move
34467 * is done.
34468 */
34469 - atomic_inc(&lis3->count);
34470 + atomic_inc_unchecked(&lis3->count);
34471
34472 wake_up_interruptible(&lis3->misc_wait);
34473 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34474 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34475 if (lis3->pm_dev)
34476 pm_runtime_get_sync(lis3->pm_dev);
34477
34478 - atomic_set(&lis3->count, 0);
34479 + atomic_set_unchecked(&lis3->count, 0);
34480 return 0;
34481 }
34482
34483 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34484 add_wait_queue(&lis3->misc_wait, &wait);
34485 while (true) {
34486 set_current_state(TASK_INTERRUPTIBLE);
34487 - data = atomic_xchg(&lis3->count, 0);
34488 + data = atomic_xchg_unchecked(&lis3->count, 0);
34489 if (data)
34490 break;
34491
34492 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34493 struct lis3lv02d, miscdev);
34494
34495 poll_wait(file, &lis3->misc_wait, wait);
34496 - if (atomic_read(&lis3->count))
34497 + if (atomic_read_unchecked(&lis3->count))
34498 return POLLIN | POLLRDNORM;
34499 return 0;
34500 }
34501 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34502 index 2b1482a..5d33616 100644
34503 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34504 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34505 @@ -266,7 +266,7 @@ struct lis3lv02d {
34506 struct input_polled_dev *idev; /* input device */
34507 struct platform_device *pdev; /* platform device */
34508 struct regulator_bulk_data regulators[2];
34509 - atomic_t count; /* interrupt count after last read */
34510 + atomic_unchecked_t count; /* interrupt count after last read */
34511 union axis_conversion ac; /* hw -> logical axis */
34512 int mapped_btns[3];
34513
34514 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34515 index 2f30bad..c4c13d0 100644
34516 --- a/drivers/misc/sgi-gru/gruhandles.c
34517 +++ b/drivers/misc/sgi-gru/gruhandles.c
34518 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34519 unsigned long nsec;
34520
34521 nsec = CLKS2NSEC(clks);
34522 - atomic_long_inc(&mcs_op_statistics[op].count);
34523 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34524 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34525 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34526 if (mcs_op_statistics[op].max < nsec)
34527 mcs_op_statistics[op].max = nsec;
34528 }
34529 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34530 index 950dbe9..eeef0f8 100644
34531 --- a/drivers/misc/sgi-gru/gruprocfs.c
34532 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34533 @@ -32,9 +32,9 @@
34534
34535 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34536
34537 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34538 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34539 {
34540 - unsigned long val = atomic_long_read(v);
34541 + unsigned long val = atomic_long_read_unchecked(v);
34542
34543 seq_printf(s, "%16lu %s\n", val, id);
34544 }
34545 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34546
34547 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34548 for (op = 0; op < mcsop_last; op++) {
34549 - count = atomic_long_read(&mcs_op_statistics[op].count);
34550 - total = atomic_long_read(&mcs_op_statistics[op].total);
34551 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34552 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34553 max = mcs_op_statistics[op].max;
34554 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34555 count ? total / count : 0, max);
34556 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34557 index 5c3ce24..4915ccb 100644
34558 --- a/drivers/misc/sgi-gru/grutables.h
34559 +++ b/drivers/misc/sgi-gru/grutables.h
34560 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34561 * GRU statistics.
34562 */
34563 struct gru_stats_s {
34564 - atomic_long_t vdata_alloc;
34565 - atomic_long_t vdata_free;
34566 - atomic_long_t gts_alloc;
34567 - atomic_long_t gts_free;
34568 - atomic_long_t gms_alloc;
34569 - atomic_long_t gms_free;
34570 - atomic_long_t gts_double_allocate;
34571 - atomic_long_t assign_context;
34572 - atomic_long_t assign_context_failed;
34573 - atomic_long_t free_context;
34574 - atomic_long_t load_user_context;
34575 - atomic_long_t load_kernel_context;
34576 - atomic_long_t lock_kernel_context;
34577 - atomic_long_t unlock_kernel_context;
34578 - atomic_long_t steal_user_context;
34579 - atomic_long_t steal_kernel_context;
34580 - atomic_long_t steal_context_failed;
34581 - atomic_long_t nopfn;
34582 - atomic_long_t asid_new;
34583 - atomic_long_t asid_next;
34584 - atomic_long_t asid_wrap;
34585 - atomic_long_t asid_reuse;
34586 - atomic_long_t intr;
34587 - atomic_long_t intr_cbr;
34588 - atomic_long_t intr_tfh;
34589 - atomic_long_t intr_spurious;
34590 - atomic_long_t intr_mm_lock_failed;
34591 - atomic_long_t call_os;
34592 - atomic_long_t call_os_wait_queue;
34593 - atomic_long_t user_flush_tlb;
34594 - atomic_long_t user_unload_context;
34595 - atomic_long_t user_exception;
34596 - atomic_long_t set_context_option;
34597 - atomic_long_t check_context_retarget_intr;
34598 - atomic_long_t check_context_unload;
34599 - atomic_long_t tlb_dropin;
34600 - atomic_long_t tlb_preload_page;
34601 - atomic_long_t tlb_dropin_fail_no_asid;
34602 - atomic_long_t tlb_dropin_fail_upm;
34603 - atomic_long_t tlb_dropin_fail_invalid;
34604 - atomic_long_t tlb_dropin_fail_range_active;
34605 - atomic_long_t tlb_dropin_fail_idle;
34606 - atomic_long_t tlb_dropin_fail_fmm;
34607 - atomic_long_t tlb_dropin_fail_no_exception;
34608 - atomic_long_t tfh_stale_on_fault;
34609 - atomic_long_t mmu_invalidate_range;
34610 - atomic_long_t mmu_invalidate_page;
34611 - atomic_long_t flush_tlb;
34612 - atomic_long_t flush_tlb_gru;
34613 - atomic_long_t flush_tlb_gru_tgh;
34614 - atomic_long_t flush_tlb_gru_zero_asid;
34615 + atomic_long_unchecked_t vdata_alloc;
34616 + atomic_long_unchecked_t vdata_free;
34617 + atomic_long_unchecked_t gts_alloc;
34618 + atomic_long_unchecked_t gts_free;
34619 + atomic_long_unchecked_t gms_alloc;
34620 + atomic_long_unchecked_t gms_free;
34621 + atomic_long_unchecked_t gts_double_allocate;
34622 + atomic_long_unchecked_t assign_context;
34623 + atomic_long_unchecked_t assign_context_failed;
34624 + atomic_long_unchecked_t free_context;
34625 + atomic_long_unchecked_t load_user_context;
34626 + atomic_long_unchecked_t load_kernel_context;
34627 + atomic_long_unchecked_t lock_kernel_context;
34628 + atomic_long_unchecked_t unlock_kernel_context;
34629 + atomic_long_unchecked_t steal_user_context;
34630 + atomic_long_unchecked_t steal_kernel_context;
34631 + atomic_long_unchecked_t steal_context_failed;
34632 + atomic_long_unchecked_t nopfn;
34633 + atomic_long_unchecked_t asid_new;
34634 + atomic_long_unchecked_t asid_next;
34635 + atomic_long_unchecked_t asid_wrap;
34636 + atomic_long_unchecked_t asid_reuse;
34637 + atomic_long_unchecked_t intr;
34638 + atomic_long_unchecked_t intr_cbr;
34639 + atomic_long_unchecked_t intr_tfh;
34640 + atomic_long_unchecked_t intr_spurious;
34641 + atomic_long_unchecked_t intr_mm_lock_failed;
34642 + atomic_long_unchecked_t call_os;
34643 + atomic_long_unchecked_t call_os_wait_queue;
34644 + atomic_long_unchecked_t user_flush_tlb;
34645 + atomic_long_unchecked_t user_unload_context;
34646 + atomic_long_unchecked_t user_exception;
34647 + atomic_long_unchecked_t set_context_option;
34648 + atomic_long_unchecked_t check_context_retarget_intr;
34649 + atomic_long_unchecked_t check_context_unload;
34650 + atomic_long_unchecked_t tlb_dropin;
34651 + atomic_long_unchecked_t tlb_preload_page;
34652 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34653 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34654 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34655 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34656 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34657 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34658 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34659 + atomic_long_unchecked_t tfh_stale_on_fault;
34660 + atomic_long_unchecked_t mmu_invalidate_range;
34661 + atomic_long_unchecked_t mmu_invalidate_page;
34662 + atomic_long_unchecked_t flush_tlb;
34663 + atomic_long_unchecked_t flush_tlb_gru;
34664 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34665 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34666
34667 - atomic_long_t copy_gpa;
34668 - atomic_long_t read_gpa;
34669 + atomic_long_unchecked_t copy_gpa;
34670 + atomic_long_unchecked_t read_gpa;
34671
34672 - atomic_long_t mesq_receive;
34673 - atomic_long_t mesq_receive_none;
34674 - atomic_long_t mesq_send;
34675 - atomic_long_t mesq_send_failed;
34676 - atomic_long_t mesq_noop;
34677 - atomic_long_t mesq_send_unexpected_error;
34678 - atomic_long_t mesq_send_lb_overflow;
34679 - atomic_long_t mesq_send_qlimit_reached;
34680 - atomic_long_t mesq_send_amo_nacked;
34681 - atomic_long_t mesq_send_put_nacked;
34682 - atomic_long_t mesq_page_overflow;
34683 - atomic_long_t mesq_qf_locked;
34684 - atomic_long_t mesq_qf_noop_not_full;
34685 - atomic_long_t mesq_qf_switch_head_failed;
34686 - atomic_long_t mesq_qf_unexpected_error;
34687 - atomic_long_t mesq_noop_unexpected_error;
34688 - atomic_long_t mesq_noop_lb_overflow;
34689 - atomic_long_t mesq_noop_qlimit_reached;
34690 - atomic_long_t mesq_noop_amo_nacked;
34691 - atomic_long_t mesq_noop_put_nacked;
34692 - atomic_long_t mesq_noop_page_overflow;
34693 + atomic_long_unchecked_t mesq_receive;
34694 + atomic_long_unchecked_t mesq_receive_none;
34695 + atomic_long_unchecked_t mesq_send;
34696 + atomic_long_unchecked_t mesq_send_failed;
34697 + atomic_long_unchecked_t mesq_noop;
34698 + atomic_long_unchecked_t mesq_send_unexpected_error;
34699 + atomic_long_unchecked_t mesq_send_lb_overflow;
34700 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34701 + atomic_long_unchecked_t mesq_send_amo_nacked;
34702 + atomic_long_unchecked_t mesq_send_put_nacked;
34703 + atomic_long_unchecked_t mesq_page_overflow;
34704 + atomic_long_unchecked_t mesq_qf_locked;
34705 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34706 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34707 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34708 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34709 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34710 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34711 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34712 + atomic_long_unchecked_t mesq_noop_put_nacked;
34713 + atomic_long_unchecked_t mesq_noop_page_overflow;
34714
34715 };
34716
34717 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34718 tghop_invalidate, mcsop_last};
34719
34720 struct mcs_op_statistic {
34721 - atomic_long_t count;
34722 - atomic_long_t total;
34723 + atomic_long_unchecked_t count;
34724 + atomic_long_unchecked_t total;
34725 unsigned long max;
34726 };
34727
34728 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34729
34730 #define STAT(id) do { \
34731 if (gru_options & OPT_STATS) \
34732 - atomic_long_inc(&gru_stats.id); \
34733 + atomic_long_inc_unchecked(&gru_stats.id); \
34734 } while (0)
34735
34736 #ifdef CONFIG_SGI_GRU_DEBUG
34737 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34738 index 851b2f2..a4ec097 100644
34739 --- a/drivers/misc/sgi-xp/xp.h
34740 +++ b/drivers/misc/sgi-xp/xp.h
34741 @@ -289,7 +289,7 @@ struct xpc_interface {
34742 xpc_notify_func, void *);
34743 void (*received) (short, int, void *);
34744 enum xp_retval (*partid_to_nasids) (short, void *);
34745 -};
34746 +} __no_const;
34747
34748 extern struct xpc_interface xpc_interface;
34749
34750 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34751 index b94d5f7..7f494c5 100644
34752 --- a/drivers/misc/sgi-xp/xpc.h
34753 +++ b/drivers/misc/sgi-xp/xpc.h
34754 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34755 void (*received_payload) (struct xpc_channel *, void *);
34756 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34757 };
34758 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34759
34760 /* struct xpc_partition act_state values (for XPC HB) */
34761
34762 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34763 /* found in xpc_main.c */
34764 extern struct device *xpc_part;
34765 extern struct device *xpc_chan;
34766 -extern struct xpc_arch_operations xpc_arch_ops;
34767 +extern xpc_arch_operations_no_const xpc_arch_ops;
34768 extern int xpc_disengage_timelimit;
34769 extern int xpc_disengage_timedout;
34770 extern int xpc_activate_IRQ_rcvd;
34771 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34772 index 8d082b4..aa749ae 100644
34773 --- a/drivers/misc/sgi-xp/xpc_main.c
34774 +++ b/drivers/misc/sgi-xp/xpc_main.c
34775 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34776 .notifier_call = xpc_system_die,
34777 };
34778
34779 -struct xpc_arch_operations xpc_arch_ops;
34780 +xpc_arch_operations_no_const xpc_arch_ops;
34781
34782 /*
34783 * Timer function to enforce the timelimit on the partition disengage.
34784 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34785 index 6ebdc40..9edf5d8 100644
34786 --- a/drivers/mmc/host/sdhci-pci.c
34787 +++ b/drivers/mmc/host/sdhci-pci.c
34788 @@ -631,7 +631,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34789 .probe = via_probe,
34790 };
34791
34792 -static const struct pci_device_id pci_ids[] __devinitdata = {
34793 +static const struct pci_device_id pci_ids[] __devinitconst = {
34794 {
34795 .vendor = PCI_VENDOR_ID_RICOH,
34796 .device = PCI_DEVICE_ID_RICOH_R5C822,
34797 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34798 index 87a431c..4959b43 100644
34799 --- a/drivers/mtd/devices/doc2000.c
34800 +++ b/drivers/mtd/devices/doc2000.c
34801 @@ -764,7 +764,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34802
34803 /* The ECC will not be calculated correctly if less than 512 is written */
34804 /* DBB-
34805 - if (len != 0x200 && eccbuf)
34806 + if (len != 0x200)
34807 printk(KERN_WARNING
34808 "ECC needs a full sector write (adr: %lx size %lx)\n",
34809 (long) to, (long) len);
34810 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
34811 index 9eacf67..4534b5b 100644
34812 --- a/drivers/mtd/devices/doc2001.c
34813 +++ b/drivers/mtd/devices/doc2001.c
34814 @@ -384,7 +384,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
34815 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34816
34817 /* Don't allow read past end of device */
34818 - if (from >= this->totlen)
34819 + if (from >= this->totlen || !len)
34820 return -EINVAL;
34821
34822 /* Don't allow a single read to cross a 512-byte block boundary */
34823 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34824 index 3984d48..28aa897 100644
34825 --- a/drivers/mtd/nand/denali.c
34826 +++ b/drivers/mtd/nand/denali.c
34827 @@ -26,6 +26,7 @@
34828 #include <linux/pci.h>
34829 #include <linux/mtd/mtd.h>
34830 #include <linux/module.h>
34831 +#include <linux/slab.h>
34832
34833 #include "denali.h"
34834
34835 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34836 index 51b9d6a..52af9a7 100644
34837 --- a/drivers/mtd/nftlmount.c
34838 +++ b/drivers/mtd/nftlmount.c
34839 @@ -24,6 +24,7 @@
34840 #include <asm/errno.h>
34841 #include <linux/delay.h>
34842 #include <linux/slab.h>
34843 +#include <linux/sched.h>
34844 #include <linux/mtd/mtd.h>
34845 #include <linux/mtd/nand.h>
34846 #include <linux/mtd/nftl.h>
34847 diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
34848 index e2cdebf..d48183a 100644
34849 --- a/drivers/mtd/ubi/debug.c
34850 +++ b/drivers/mtd/ubi/debug.c
34851 @@ -338,6 +338,8 @@ out:
34852
34853 /* Write an UBI debugfs file */
34854 static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
34855 + size_t count, loff_t *ppos) __size_overflow(3);
34856 +static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
34857 size_t count, loff_t *ppos)
34858 {
34859 unsigned long ubi_num = (unsigned long)file->private_data;
34860 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34861 index 071f4c8..440862e 100644
34862 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34863 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34864 @@ -2862,7 +2862,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34865 */
34866
34867 #define ATL2_PARAM(X, desc) \
34868 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34869 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34870 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34871 MODULE_PARM_DESC(X, desc);
34872 #else
34873 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34874 index 66da39f..5dc436d 100644
34875 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34876 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34877 @@ -473,7 +473,7 @@ struct bnx2x_rx_mode_obj {
34878
34879 int (*wait_comp)(struct bnx2x *bp,
34880 struct bnx2x_rx_mode_ramrod_params *p);
34881 -};
34882 +} __no_const;
34883
34884 /********************** Set multicast group ***********************************/
34885
34886 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34887 index aea8f72..fcebf75 100644
34888 --- a/drivers/net/ethernet/broadcom/tg3.h
34889 +++ b/drivers/net/ethernet/broadcom/tg3.h
34890 @@ -140,6 +140,7 @@
34891 #define CHIPREV_ID_5750_A0 0x4000
34892 #define CHIPREV_ID_5750_A1 0x4001
34893 #define CHIPREV_ID_5750_A3 0x4003
34894 +#define CHIPREV_ID_5750_C1 0x4201
34895 #define CHIPREV_ID_5750_C2 0x4202
34896 #define CHIPREV_ID_5752_A0_HW 0x5000
34897 #define CHIPREV_ID_5752_A0 0x6000
34898 diff --git a/drivers/net/ethernet/chelsio/cxgb/sge.c b/drivers/net/ethernet/chelsio/cxgb/sge.c
34899 index 47a8435..248e4b3 100644
34900 --- a/drivers/net/ethernet/chelsio/cxgb/sge.c
34901 +++ b/drivers/net/ethernet/chelsio/cxgb/sge.c
34902 @@ -1052,6 +1052,8 @@ MODULE_PARM_DESC(copybreak, "Receive copy threshold");
34903 * be copied but there is no memory for the copy.
34904 */
34905 static inline struct sk_buff *get_packet(struct pci_dev *pdev,
34906 + struct freelQ *fl, unsigned int len) __size_overflow(3);
34907 +static inline struct sk_buff *get_packet(struct pci_dev *pdev,
34908 struct freelQ *fl, unsigned int len)
34909 {
34910 struct sk_buff *skb;
34911 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34912 index c4e8643..0979484 100644
34913 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34914 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34915 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34916 */
34917 struct l2t_skb_cb {
34918 arp_failure_handler_func arp_failure_handler;
34919 -};
34920 +} __no_const;
34921
34922 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34923
34924 diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
34925 index cfb60e1..94af340 100644
34926 --- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
34927 +++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
34928 @@ -611,6 +611,8 @@ static void recycle_rx_buf(struct adapter *adap, struct sge_fl *q,
34929 * of the SW ring.
34930 */
34931 static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
34932 + size_t sw_size, dma_addr_t * phys, void *metadata) __size_overflow(2,4);
34933 +static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
34934 size_t sw_size, dma_addr_t * phys, void *metadata)
34935 {
34936 size_t len = nelem * elem_size;
34937 @@ -777,6 +779,8 @@ static inline unsigned int flits_to_desc(unsigned int n)
34938 * be copied but there is no memory for the copy.
34939 */
34940 static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
34941 + unsigned int len, unsigned int drop_thres) __size_overflow(3);
34942 +static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
34943 unsigned int len, unsigned int drop_thres)
34944 {
34945 struct sk_buff *skb = NULL;
34946 diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
34947 index 2dae795..73037d2 100644
34948 --- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
34949 +++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
34950 @@ -593,6 +593,9 @@ static inline void __refill_fl(struct adapter *adap, struct sge_fl *fl)
34951 */
34952 static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
34953 size_t sw_size, dma_addr_t *phys, void *metadata,
34954 + size_t stat_size, int node) __size_overflow(2,4);
34955 +static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
34956 + size_t sw_size, dma_addr_t *phys, void *metadata,
34957 size_t stat_size, int node)
34958 {
34959 size_t len = nelem * elem_size + stat_size;
34960 diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34961 index 0bd585b..d954ca5 100644
34962 --- a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34963 +++ b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34964 @@ -729,6 +729,9 @@ static inline void __refill_fl(struct adapter *adapter, struct sge_fl *fl)
34965 */
34966 static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
34967 size_t swsize, dma_addr_t *busaddrp, void *swringp,
34968 + size_t stat_size) __size_overflow(2,4);
34969 +static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
34970 + size_t swsize, dma_addr_t *busaddrp, void *swringp,
34971 size_t stat_size)
34972 {
34973 /*
34974 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34975 index 4d71f5a..8004440 100644
34976 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34977 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34978 @@ -5392,7 +5392,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34979 for (i=0; i<ETH_ALEN; i++) {
34980 tmp.addr[i] = dev->dev_addr[i];
34981 }
34982 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34983 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34984 break;
34985
34986 case DE4X5_SET_HWADDR: /* Set the hardware address */
34987 @@ -5432,7 +5432,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34988 spin_lock_irqsave(&lp->lock, flags);
34989 memcpy(&statbuf, &lp->pktStats, ioc->len);
34990 spin_unlock_irqrestore(&lp->lock, flags);
34991 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34992 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34993 return -EFAULT;
34994 break;
34995 }
34996 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34997 index 14d5b61..1398636 100644
34998 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34999 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
35000 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
35001 {NULL}};
35002
35003
35004 -static const char *block_name[] __devinitdata = {
35005 +static const char *block_name[] __devinitconst = {
35006 "21140 non-MII",
35007 "21140 MII PHY",
35008 "21142 Serial PHY",
35009 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
35010 index 52da7b2..4ddfe1c 100644
35011 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
35012 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
35013 @@ -236,7 +236,7 @@ struct pci_id_info {
35014 int drv_flags; /* Driver use, intended as capability flags. */
35015 };
35016
35017 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35018 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35019 { /* Sometime a Level-One switch card. */
35020 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
35021 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
35022 diff --git a/drivers/net/ethernet/dlink/dl2k.c b/drivers/net/ethernet/dlink/dl2k.c
35023 index b2dc2c8..2e09edb 100644
35024 --- a/drivers/net/ethernet/dlink/dl2k.c
35025 +++ b/drivers/net/ethernet/dlink/dl2k.c
35026 @@ -1259,55 +1259,21 @@ rio_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
35027 {
35028 int phy_addr;
35029 struct netdev_private *np = netdev_priv(dev);
35030 - struct mii_data *miidata = (struct mii_data *) &rq->ifr_ifru;
35031 -
35032 - struct netdev_desc *desc;
35033 - int i;
35034 + struct mii_ioctl_data *miidata = if_mii(rq);
35035
35036 phy_addr = np->phy_addr;
35037 switch (cmd) {
35038 - case SIOCDEVPRIVATE:
35039 + case SIOCGMIIPHY:
35040 + miidata->phy_id = phy_addr;
35041 break;
35042 -
35043 - case SIOCDEVPRIVATE + 1:
35044 - miidata->out_value = mii_read (dev, phy_addr, miidata->reg_num);
35045 + case SIOCGMIIREG:
35046 + miidata->val_out = mii_read (dev, phy_addr, miidata->reg_num);
35047 break;
35048 - case SIOCDEVPRIVATE + 2:
35049 - mii_write (dev, phy_addr, miidata->reg_num, miidata->in_value);
35050 + case SIOCSMIIREG:
35051 + if (!capable(CAP_NET_ADMIN))
35052 + return -EPERM;
35053 + mii_write (dev, phy_addr, miidata->reg_num, miidata->val_in);
35054 break;
35055 - case SIOCDEVPRIVATE + 3:
35056 - break;
35057 - case SIOCDEVPRIVATE + 4:
35058 - break;
35059 - case SIOCDEVPRIVATE + 5:
35060 - netif_stop_queue (dev);
35061 - break;
35062 - case SIOCDEVPRIVATE + 6:
35063 - netif_wake_queue (dev);
35064 - break;
35065 - case SIOCDEVPRIVATE + 7:
35066 - printk
35067 - ("tx_full=%x cur_tx=%lx old_tx=%lx cur_rx=%lx old_rx=%lx\n",
35068 - netif_queue_stopped(dev), np->cur_tx, np->old_tx, np->cur_rx,
35069 - np->old_rx);
35070 - break;
35071 - case SIOCDEVPRIVATE + 8:
35072 - printk("TX ring:\n");
35073 - for (i = 0; i < TX_RING_SIZE; i++) {
35074 - desc = &np->tx_ring[i];
35075 - printk
35076 - ("%02x:cur:%08x next:%08x status:%08x frag1:%08x frag0:%08x",
35077 - i,
35078 - (u32) (np->tx_ring_dma + i * sizeof (*desc)),
35079 - (u32)le64_to_cpu(desc->next_desc),
35080 - (u32)le64_to_cpu(desc->status),
35081 - (u32)(le64_to_cpu(desc->fraginfo) >> 32),
35082 - (u32)le64_to_cpu(desc->fraginfo));
35083 - printk ("\n");
35084 - }
35085 - printk ("\n");
35086 - break;
35087 -
35088 default:
35089 return -EOPNOTSUPP;
35090 }
35091 diff --git a/drivers/net/ethernet/dlink/dl2k.h b/drivers/net/ethernet/dlink/dl2k.h
35092 index ba0adca..30c2da3 100644
35093 --- a/drivers/net/ethernet/dlink/dl2k.h
35094 +++ b/drivers/net/ethernet/dlink/dl2k.h
35095 @@ -365,13 +365,6 @@ struct ioctl_data {
35096 char *data;
35097 };
35098
35099 -struct mii_data {
35100 - __u16 reserved;
35101 - __u16 reg_num;
35102 - __u16 in_value;
35103 - __u16 out_value;
35104 -};
35105 -
35106 /* The Rx and Tx buffer descriptors. */
35107 struct netdev_desc {
35108 __le64 next_desc;
35109 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
35110 index 28a3a9b..d96cb63 100644
35111 --- a/drivers/net/ethernet/dlink/sundance.c
35112 +++ b/drivers/net/ethernet/dlink/sundance.c
35113 @@ -218,7 +218,7 @@ enum {
35114 struct pci_id_info {
35115 const char *name;
35116 };
35117 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35118 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35119 {"D-Link DFE-550TX FAST Ethernet Adapter"},
35120 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
35121 {"D-Link DFE-580TX 4 port Server Adapter"},
35122 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
35123 index e703d64..d62ecf9 100644
35124 --- a/drivers/net/ethernet/emulex/benet/be_main.c
35125 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
35126 @@ -402,7 +402,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
35127
35128 if (wrapped)
35129 newacc += 65536;
35130 - ACCESS_ONCE(*acc) = newacc;
35131 + ACCESS_ONCE_RW(*acc) = newacc;
35132 }
35133
35134 void be_parse_stats(struct be_adapter *adapter)
35135 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
35136 index 47f85c3..82ab6c4 100644
35137 --- a/drivers/net/ethernet/faraday/ftgmac100.c
35138 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
35139 @@ -31,6 +31,8 @@
35140 #include <linux/netdevice.h>
35141 #include <linux/phy.h>
35142 #include <linux/platform_device.h>
35143 +#include <linux/interrupt.h>
35144 +#include <linux/irqreturn.h>
35145 #include <net/ip.h>
35146
35147 #include "ftgmac100.h"
35148 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
35149 index bb336a0..4b472da 100644
35150 --- a/drivers/net/ethernet/faraday/ftmac100.c
35151 +++ b/drivers/net/ethernet/faraday/ftmac100.c
35152 @@ -31,6 +31,8 @@
35153 #include <linux/module.h>
35154 #include <linux/netdevice.h>
35155 #include <linux/platform_device.h>
35156 +#include <linux/interrupt.h>
35157 +#include <linux/irqreturn.h>
35158
35159 #include "ftmac100.h"
35160
35161 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
35162 index c82d444..0007fb4 100644
35163 --- a/drivers/net/ethernet/fealnx.c
35164 +++ b/drivers/net/ethernet/fealnx.c
35165 @@ -150,7 +150,7 @@ struct chip_info {
35166 int flags;
35167 };
35168
35169 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35170 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35171 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35172 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35173 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35174 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
35175 index e1159e5..e18684d 100644
35176 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
35177 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
35178 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
35179 {
35180 struct e1000_hw *hw = &adapter->hw;
35181 struct e1000_mac_info *mac = &hw->mac;
35182 - struct e1000_mac_operations *func = &mac->ops;
35183 + e1000_mac_operations_no_const *func = &mac->ops;
35184
35185 /* Set media type */
35186 switch (adapter->pdev->device) {
35187 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
35188 index a3e65fd..f451444 100644
35189 --- a/drivers/net/ethernet/intel/e1000e/82571.c
35190 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
35191 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
35192 {
35193 struct e1000_hw *hw = &adapter->hw;
35194 struct e1000_mac_info *mac = &hw->mac;
35195 - struct e1000_mac_operations *func = &mac->ops;
35196 + e1000_mac_operations_no_const *func = &mac->ops;
35197 u32 swsm = 0;
35198 u32 swsm2 = 0;
35199 bool force_clear_smbi = false;
35200 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35201 index 2967039..ca8c40c 100644
35202 --- a/drivers/net/ethernet/intel/e1000e/hw.h
35203 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
35204 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
35205 void (*write_vfta)(struct e1000_hw *, u32, u32);
35206 s32 (*read_mac_addr)(struct e1000_hw *);
35207 };
35208 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35209
35210 /*
35211 * When to use various PHY register access functions:
35212 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
35213 void (*power_up)(struct e1000_hw *);
35214 void (*power_down)(struct e1000_hw *);
35215 };
35216 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35217
35218 /* Function pointers for the NVM. */
35219 struct e1000_nvm_operations {
35220 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
35221 s32 (*validate)(struct e1000_hw *);
35222 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35223 };
35224 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35225
35226 struct e1000_mac_info {
35227 - struct e1000_mac_operations ops;
35228 + e1000_mac_operations_no_const ops;
35229 u8 addr[ETH_ALEN];
35230 u8 perm_addr[ETH_ALEN];
35231
35232 @@ -872,7 +875,7 @@ struct e1000_mac_info {
35233 };
35234
35235 struct e1000_phy_info {
35236 - struct e1000_phy_operations ops;
35237 + e1000_phy_operations_no_const ops;
35238
35239 enum e1000_phy_type type;
35240
35241 @@ -906,7 +909,7 @@ struct e1000_phy_info {
35242 };
35243
35244 struct e1000_nvm_info {
35245 - struct e1000_nvm_operations ops;
35246 + e1000_nvm_operations_no_const ops;
35247
35248 enum e1000_nvm_type type;
35249 enum e1000_nvm_override override;
35250 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35251 index f67cbd3..cef9e3d 100644
35252 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35253 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35254 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
35255 s32 (*read_mac_addr)(struct e1000_hw *);
35256 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
35257 };
35258 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35259
35260 struct e1000_phy_operations {
35261 s32 (*acquire)(struct e1000_hw *);
35262 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
35263 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35264 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35265 };
35266 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35267
35268 struct e1000_nvm_operations {
35269 s32 (*acquire)(struct e1000_hw *);
35270 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
35271 s32 (*update)(struct e1000_hw *);
35272 s32 (*validate)(struct e1000_hw *);
35273 };
35274 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35275
35276 struct e1000_info {
35277 s32 (*get_invariants)(struct e1000_hw *);
35278 @@ -350,7 +353,7 @@ struct e1000_info {
35279 extern const struct e1000_info e1000_82575_info;
35280
35281 struct e1000_mac_info {
35282 - struct e1000_mac_operations ops;
35283 + e1000_mac_operations_no_const ops;
35284
35285 u8 addr[6];
35286 u8 perm_addr[6];
35287 @@ -388,7 +391,7 @@ struct e1000_mac_info {
35288 };
35289
35290 struct e1000_phy_info {
35291 - struct e1000_phy_operations ops;
35292 + e1000_phy_operations_no_const ops;
35293
35294 enum e1000_phy_type type;
35295
35296 @@ -423,7 +426,7 @@ struct e1000_phy_info {
35297 };
35298
35299 struct e1000_nvm_info {
35300 - struct e1000_nvm_operations ops;
35301 + e1000_nvm_operations_no_const ops;
35302 enum e1000_nvm_type type;
35303 enum e1000_nvm_override override;
35304
35305 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
35306 s32 (*check_for_ack)(struct e1000_hw *, u16);
35307 s32 (*check_for_rst)(struct e1000_hw *, u16);
35308 };
35309 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35310
35311 struct e1000_mbx_stats {
35312 u32 msgs_tx;
35313 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
35314 };
35315
35316 struct e1000_mbx_info {
35317 - struct e1000_mbx_operations ops;
35318 + e1000_mbx_operations_no_const ops;
35319 struct e1000_mbx_stats stats;
35320 u32 timeout;
35321 u32 usec_delay;
35322 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35323 index 57db3c6..aa825fc 100644
35324 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35325 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35326 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35327 s32 (*read_mac_addr)(struct e1000_hw *);
35328 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35329 };
35330 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35331
35332 struct e1000_mac_info {
35333 - struct e1000_mac_operations ops;
35334 + e1000_mac_operations_no_const ops;
35335 u8 addr[6];
35336 u8 perm_addr[6];
35337
35338 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35339 s32 (*check_for_ack)(struct e1000_hw *);
35340 s32 (*check_for_rst)(struct e1000_hw *);
35341 };
35342 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35343
35344 struct e1000_mbx_stats {
35345 u32 msgs_tx;
35346 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35347 };
35348
35349 struct e1000_mbx_info {
35350 - struct e1000_mbx_operations ops;
35351 + e1000_mbx_operations_no_const ops;
35352 struct e1000_mbx_stats stats;
35353 u32 timeout;
35354 u32 usec_delay;
35355 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35356 index 9b95bef..7e254ee 100644
35357 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35358 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35359 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
35360 s32 (*update_checksum)(struct ixgbe_hw *);
35361 u16 (*calc_checksum)(struct ixgbe_hw *);
35362 };
35363 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35364
35365 struct ixgbe_mac_operations {
35366 s32 (*init_hw)(struct ixgbe_hw *);
35367 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
35368 /* Manageability interface */
35369 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
35370 };
35371 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35372
35373 struct ixgbe_phy_operations {
35374 s32 (*identify)(struct ixgbe_hw *);
35375 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
35376 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35377 s32 (*check_overtemp)(struct ixgbe_hw *);
35378 };
35379 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35380
35381 struct ixgbe_eeprom_info {
35382 - struct ixgbe_eeprom_operations ops;
35383 + ixgbe_eeprom_operations_no_const ops;
35384 enum ixgbe_eeprom_type type;
35385 u32 semaphore_delay;
35386 u16 word_size;
35387 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
35388
35389 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35390 struct ixgbe_mac_info {
35391 - struct ixgbe_mac_operations ops;
35392 + ixgbe_mac_operations_no_const ops;
35393 enum ixgbe_mac_type type;
35394 u8 addr[ETH_ALEN];
35395 u8 perm_addr[ETH_ALEN];
35396 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
35397 };
35398
35399 struct ixgbe_phy_info {
35400 - struct ixgbe_phy_operations ops;
35401 + ixgbe_phy_operations_no_const ops;
35402 struct mdio_if_info mdio;
35403 enum ixgbe_phy_type type;
35404 u32 id;
35405 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
35406 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35407 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35408 };
35409 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35410
35411 struct ixgbe_mbx_stats {
35412 u32 msgs_tx;
35413 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
35414 };
35415
35416 struct ixgbe_mbx_info {
35417 - struct ixgbe_mbx_operations ops;
35418 + ixgbe_mbx_operations_no_const ops;
35419 struct ixgbe_mbx_stats stats;
35420 u32 timeout;
35421 u32 usec_delay;
35422 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35423 index 25c951d..cc7cf33 100644
35424 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35425 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35426 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35427 s32 (*clear_vfta)(struct ixgbe_hw *);
35428 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35429 };
35430 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35431
35432 enum ixgbe_mac_type {
35433 ixgbe_mac_unknown = 0,
35434 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35435 };
35436
35437 struct ixgbe_mac_info {
35438 - struct ixgbe_mac_operations ops;
35439 + ixgbe_mac_operations_no_const ops;
35440 u8 addr[6];
35441 u8 perm_addr[6];
35442
35443 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35444 s32 (*check_for_ack)(struct ixgbe_hw *);
35445 s32 (*check_for_rst)(struct ixgbe_hw *);
35446 };
35447 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35448
35449 struct ixgbe_mbx_stats {
35450 u32 msgs_tx;
35451 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35452 };
35453
35454 struct ixgbe_mbx_info {
35455 - struct ixgbe_mbx_operations ops;
35456 + ixgbe_mbx_operations_no_const ops;
35457 struct ixgbe_mbx_stats stats;
35458 u32 timeout;
35459 u32 udelay;
35460 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35461 index 8bf22b6..7f5baaa 100644
35462 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
35463 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35464 @@ -41,6 +41,7 @@
35465 #include <linux/slab.h>
35466 #include <linux/io-mapping.h>
35467 #include <linux/delay.h>
35468 +#include <linux/sched.h>
35469
35470 #include <linux/mlx4/device.h>
35471 #include <linux/mlx4/doorbell.h>
35472 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35473 index 5046a64..71ca936 100644
35474 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35475 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35476 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35477 void (*link_down)(struct __vxge_hw_device *devh);
35478 void (*crit_err)(struct __vxge_hw_device *devh,
35479 enum vxge_hw_event type, u64 ext_data);
35480 -};
35481 +} __no_const;
35482
35483 /*
35484 * struct __vxge_hw_blockpool_entry - Block private data structure
35485 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35486 index 4a518a3..936b334 100644
35487 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35488 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35489 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35490 struct vxge_hw_mempool_dma *dma_object,
35491 u32 index,
35492 u32 is_last);
35493 -};
35494 +} __no_const;
35495
35496 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35497 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35498 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35499 index bbacb37..d60887d 100644
35500 --- a/drivers/net/ethernet/realtek/r8169.c
35501 +++ b/drivers/net/ethernet/realtek/r8169.c
35502 @@ -695,17 +695,17 @@ struct rtl8169_private {
35503 struct mdio_ops {
35504 void (*write)(void __iomem *, int, int);
35505 int (*read)(void __iomem *, int);
35506 - } mdio_ops;
35507 + } __no_const mdio_ops;
35508
35509 struct pll_power_ops {
35510 void (*down)(struct rtl8169_private *);
35511 void (*up)(struct rtl8169_private *);
35512 - } pll_power_ops;
35513 + } __no_const pll_power_ops;
35514
35515 struct jumbo_ops {
35516 void (*enable)(struct rtl8169_private *);
35517 void (*disable)(struct rtl8169_private *);
35518 - } jumbo_ops;
35519 + } __no_const jumbo_ops;
35520
35521 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35522 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35523 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35524 index 5b118cd..858b523 100644
35525 --- a/drivers/net/ethernet/sis/sis190.c
35526 +++ b/drivers/net/ethernet/sis/sis190.c
35527 @@ -1622,7 +1622,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35528 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35529 struct net_device *dev)
35530 {
35531 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35532 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35533 struct sis190_private *tp = netdev_priv(dev);
35534 struct pci_dev *isa_bridge;
35535 u8 reg, tmp8;
35536 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35537 index c07cfe9..81cbf7e 100644
35538 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35539 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35540 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35541
35542 writel(value, ioaddr + MMC_CNTRL);
35543
35544 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35545 - MMC_CNTRL, value);
35546 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35547 +// MMC_CNTRL, value);
35548 }
35549
35550 /* To mask all all interrupts.*/
35551 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35552 index dec5836..6d4db7d 100644
35553 --- a/drivers/net/hyperv/hyperv_net.h
35554 +++ b/drivers/net/hyperv/hyperv_net.h
35555 @@ -97,7 +97,7 @@ struct rndis_device {
35556
35557 enum rndis_device_state state;
35558 bool link_state;
35559 - atomic_t new_req_id;
35560 + atomic_unchecked_t new_req_id;
35561
35562 spinlock_t request_lock;
35563 struct list_head req_list;
35564 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35565 index 133b7fb..d58c559 100644
35566 --- a/drivers/net/hyperv/rndis_filter.c
35567 +++ b/drivers/net/hyperv/rndis_filter.c
35568 @@ -96,7 +96,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35569 * template
35570 */
35571 set = &rndis_msg->msg.set_req;
35572 - set->req_id = atomic_inc_return(&dev->new_req_id);
35573 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35574
35575 /* Add to the request list */
35576 spin_lock_irqsave(&dev->request_lock, flags);
35577 @@ -627,7 +627,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35578
35579 /* Setup the rndis set */
35580 halt = &request->request_msg.msg.halt_req;
35581 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35582 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35583
35584 /* Ignore return since this msg is optional. */
35585 rndis_filter_send_request(dev, request);
35586 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
35587 index 58dc117..f140c77 100644
35588 --- a/drivers/net/macvtap.c
35589 +++ b/drivers/net/macvtap.c
35590 @@ -526,6 +526,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
35591 }
35592 base = (unsigned long)from->iov_base + offset1;
35593 size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
35594 + if (i + size >= MAX_SKB_FRAGS)
35595 + return -EFAULT;
35596 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
35597 if ((num_pages != size) ||
35598 (num_pages > MAX_SKB_FRAGS - skb_shinfo(skb)->nr_frags))
35599 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35600 index 3ed983c..a1bb418 100644
35601 --- a/drivers/net/ppp/ppp_generic.c
35602 +++ b/drivers/net/ppp/ppp_generic.c
35603 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35604 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35605 struct ppp_stats stats;
35606 struct ppp_comp_stats cstats;
35607 - char *vers;
35608
35609 switch (cmd) {
35610 case SIOCGPPPSTATS:
35611 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35612 break;
35613
35614 case SIOCGPPPVER:
35615 - vers = PPP_VERSION;
35616 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35617 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35618 break;
35619 err = 0;
35620 break;
35621 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35622 index 515f122..41dd273 100644
35623 --- a/drivers/net/tokenring/abyss.c
35624 +++ b/drivers/net/tokenring/abyss.c
35625 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
35626
35627 static int __init abyss_init (void)
35628 {
35629 - abyss_netdev_ops = tms380tr_netdev_ops;
35630 + pax_open_kernel();
35631 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35632
35633 - abyss_netdev_ops.ndo_open = abyss_open;
35634 - abyss_netdev_ops.ndo_stop = abyss_close;
35635 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35636 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35637 + pax_close_kernel();
35638
35639 return pci_register_driver(&abyss_driver);
35640 }
35641 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35642 index 6153cfd..cf69c1c 100644
35643 --- a/drivers/net/tokenring/madgemc.c
35644 +++ b/drivers/net/tokenring/madgemc.c
35645 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
35646
35647 static int __init madgemc_init (void)
35648 {
35649 - madgemc_netdev_ops = tms380tr_netdev_ops;
35650 - madgemc_netdev_ops.ndo_open = madgemc_open;
35651 - madgemc_netdev_ops.ndo_stop = madgemc_close;
35652 + pax_open_kernel();
35653 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35654 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35655 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35656 + pax_close_kernel();
35657
35658 return mca_register_driver (&madgemc_driver);
35659 }
35660 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35661 index 8d362e6..f91cc52 100644
35662 --- a/drivers/net/tokenring/proteon.c
35663 +++ b/drivers/net/tokenring/proteon.c
35664 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
35665 struct platform_device *pdev;
35666 int i, num = 0, err = 0;
35667
35668 - proteon_netdev_ops = tms380tr_netdev_ops;
35669 - proteon_netdev_ops.ndo_open = proteon_open;
35670 - proteon_netdev_ops.ndo_stop = tms380tr_close;
35671 + pax_open_kernel();
35672 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35673 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35674 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35675 + pax_close_kernel();
35676
35677 err = platform_driver_register(&proteon_driver);
35678 if (err)
35679 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35680 index 46db5c5..37c1536 100644
35681 --- a/drivers/net/tokenring/skisa.c
35682 +++ b/drivers/net/tokenring/skisa.c
35683 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
35684 struct platform_device *pdev;
35685 int i, num = 0, err = 0;
35686
35687 - sk_isa_netdev_ops = tms380tr_netdev_ops;
35688 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
35689 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35690 + pax_open_kernel();
35691 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35692 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35693 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35694 + pax_close_kernel();
35695
35696 err = platform_driver_register(&sk_isa_driver);
35697 if (err)
35698 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35699 index e1324b4..e1b0041 100644
35700 --- a/drivers/net/usb/hso.c
35701 +++ b/drivers/net/usb/hso.c
35702 @@ -71,7 +71,7 @@
35703 #include <asm/byteorder.h>
35704 #include <linux/serial_core.h>
35705 #include <linux/serial.h>
35706 -
35707 +#include <asm/local.h>
35708
35709 #define MOD_AUTHOR "Option Wireless"
35710 #define MOD_DESCRIPTION "USB High Speed Option driver"
35711 @@ -257,7 +257,7 @@ struct hso_serial {
35712
35713 /* from usb_serial_port */
35714 struct tty_struct *tty;
35715 - int open_count;
35716 + local_t open_count;
35717 spinlock_t serial_lock;
35718
35719 int (*write_data) (struct hso_serial *serial);
35720 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35721 struct urb *urb;
35722
35723 urb = serial->rx_urb[0];
35724 - if (serial->open_count > 0) {
35725 + if (local_read(&serial->open_count) > 0) {
35726 count = put_rxbuf_data(urb, serial);
35727 if (count == -1)
35728 return;
35729 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35730 DUMP1(urb->transfer_buffer, urb->actual_length);
35731
35732 /* Anyone listening? */
35733 - if (serial->open_count == 0)
35734 + if (local_read(&serial->open_count) == 0)
35735 return;
35736
35737 if (status == 0) {
35738 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35739 spin_unlock_irq(&serial->serial_lock);
35740
35741 /* check for port already opened, if not set the termios */
35742 - serial->open_count++;
35743 - if (serial->open_count == 1) {
35744 + if (local_inc_return(&serial->open_count) == 1) {
35745 serial->rx_state = RX_IDLE;
35746 /* Force default termio settings */
35747 _hso_serial_set_termios(tty, NULL);
35748 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35749 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35750 if (result) {
35751 hso_stop_serial_device(serial->parent);
35752 - serial->open_count--;
35753 + local_dec(&serial->open_count);
35754 kref_put(&serial->parent->ref, hso_serial_ref_free);
35755 }
35756 } else {
35757 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35758
35759 /* reset the rts and dtr */
35760 /* do the actual close */
35761 - serial->open_count--;
35762 + local_dec(&serial->open_count);
35763
35764 - if (serial->open_count <= 0) {
35765 - serial->open_count = 0;
35766 + if (local_read(&serial->open_count) <= 0) {
35767 + local_set(&serial->open_count, 0);
35768 spin_lock_irq(&serial->serial_lock);
35769 if (serial->tty == tty) {
35770 serial->tty->driver_data = NULL;
35771 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35772
35773 /* the actual setup */
35774 spin_lock_irqsave(&serial->serial_lock, flags);
35775 - if (serial->open_count)
35776 + if (local_read(&serial->open_count))
35777 _hso_serial_set_termios(tty, old);
35778 else
35779 tty->termios = old;
35780 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35781 D1("Pending read interrupt on port %d\n", i);
35782 spin_lock(&serial->serial_lock);
35783 if (serial->rx_state == RX_IDLE &&
35784 - serial->open_count > 0) {
35785 + local_read(&serial->open_count) > 0) {
35786 /* Setup and send a ctrl req read on
35787 * port i */
35788 if (!serial->rx_urb_filled[0]) {
35789 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35790 /* Start all serial ports */
35791 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35792 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35793 - if (dev2ser(serial_table[i])->open_count) {
35794 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
35795 result =
35796 hso_start_serial_device(serial_table[i], GFP_NOIO);
35797 hso_kick_transmit(dev2ser(serial_table[i]));
35798 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35799 index efc0111..79c8f5b 100644
35800 --- a/drivers/net/wireless/ath/ath.h
35801 +++ b/drivers/net/wireless/ath/ath.h
35802 @@ -119,6 +119,7 @@ struct ath_ops {
35803 void (*write_flush) (void *);
35804 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35805 };
35806 +typedef struct ath_ops __no_const ath_ops_no_const;
35807
35808 struct ath_common;
35809 struct ath_bus_ops;
35810 diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
35811 index 8c5ce8b..abf101b 100644
35812 --- a/drivers/net/wireless/ath/ath5k/debug.c
35813 +++ b/drivers/net/wireless/ath/ath5k/debug.c
35814 @@ -343,6 +343,9 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35815
35816 static ssize_t write_file_debug(struct file *file,
35817 const char __user *userbuf,
35818 + size_t count, loff_t *ppos) __size_overflow(3);
35819 +static ssize_t write_file_debug(struct file *file,
35820 + const char __user *userbuf,
35821 size_t count, loff_t *ppos)
35822 {
35823 struct ath5k_hw *ah = file->private_data;
35824 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35825 index 7b6417b..ab5db98 100644
35826 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35827 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35828 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35829 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35830 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35831
35832 - ACCESS_ONCE(ads->ds_link) = i->link;
35833 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35834 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35835 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35836
35837 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35838 ctl6 = SM(i->keytype, AR_EncrType);
35839 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35840
35841 if ((i->is_first || i->is_last) &&
35842 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35843 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35844 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35845 | set11nTries(i->rates, 1)
35846 | set11nTries(i->rates, 2)
35847 | set11nTries(i->rates, 3)
35848 | (i->dur_update ? AR_DurUpdateEna : 0)
35849 | SM(0, AR_BurstDur);
35850
35851 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35852 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35853 | set11nRate(i->rates, 1)
35854 | set11nRate(i->rates, 2)
35855 | set11nRate(i->rates, 3);
35856 } else {
35857 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35858 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35859 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35860 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35861 }
35862
35863 if (!i->is_first) {
35864 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35865 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35866 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35867 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35868 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35869 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35870 return;
35871 }
35872
35873 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35874 break;
35875 }
35876
35877 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35878 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35879 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35880 | SM(i->txpower, AR_XmitPower)
35881 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35882 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35883 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35884 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35885
35886 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35887 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35888 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35889 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35890
35891 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35892 return;
35893
35894 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35895 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35896 | set11nPktDurRTSCTS(i->rates, 1);
35897
35898 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35899 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35900 | set11nPktDurRTSCTS(i->rates, 3);
35901
35902 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35903 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35904 | set11nRateFlags(i->rates, 1)
35905 | set11nRateFlags(i->rates, 2)
35906 | set11nRateFlags(i->rates, 3)
35907 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35908 index 09b8c9d..905339e 100644
35909 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35910 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35911 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35912 (i->qcu << AR_TxQcuNum_S) | 0x17;
35913
35914 checksum += val;
35915 - ACCESS_ONCE(ads->info) = val;
35916 + ACCESS_ONCE_RW(ads->info) = val;
35917
35918 checksum += i->link;
35919 - ACCESS_ONCE(ads->link) = i->link;
35920 + ACCESS_ONCE_RW(ads->link) = i->link;
35921
35922 checksum += i->buf_addr[0];
35923 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35924 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35925 checksum += i->buf_addr[1];
35926 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35927 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35928 checksum += i->buf_addr[2];
35929 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35930 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35931 checksum += i->buf_addr[3];
35932 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35933 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35934
35935 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35936 - ACCESS_ONCE(ads->ctl3) = val;
35937 + ACCESS_ONCE_RW(ads->ctl3) = val;
35938 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35939 - ACCESS_ONCE(ads->ctl5) = val;
35940 + ACCESS_ONCE_RW(ads->ctl5) = val;
35941 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35942 - ACCESS_ONCE(ads->ctl7) = val;
35943 + ACCESS_ONCE_RW(ads->ctl7) = val;
35944 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35945 - ACCESS_ONCE(ads->ctl9) = val;
35946 + ACCESS_ONCE_RW(ads->ctl9) = val;
35947
35948 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35949 - ACCESS_ONCE(ads->ctl10) = checksum;
35950 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35951
35952 if (i->is_first || i->is_last) {
35953 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35954 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35955 | set11nTries(i->rates, 1)
35956 | set11nTries(i->rates, 2)
35957 | set11nTries(i->rates, 3)
35958 | (i->dur_update ? AR_DurUpdateEna : 0)
35959 | SM(0, AR_BurstDur);
35960
35961 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35962 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35963 | set11nRate(i->rates, 1)
35964 | set11nRate(i->rates, 2)
35965 | set11nRate(i->rates, 3);
35966 } else {
35967 - ACCESS_ONCE(ads->ctl13) = 0;
35968 - ACCESS_ONCE(ads->ctl14) = 0;
35969 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35970 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35971 }
35972
35973 ads->ctl20 = 0;
35974 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35975
35976 ctl17 = SM(i->keytype, AR_EncrType);
35977 if (!i->is_first) {
35978 - ACCESS_ONCE(ads->ctl11) = 0;
35979 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35980 - ACCESS_ONCE(ads->ctl15) = 0;
35981 - ACCESS_ONCE(ads->ctl16) = 0;
35982 - ACCESS_ONCE(ads->ctl17) = ctl17;
35983 - ACCESS_ONCE(ads->ctl18) = 0;
35984 - ACCESS_ONCE(ads->ctl19) = 0;
35985 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35986 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35987 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35988 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35989 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35990 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35991 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35992 return;
35993 }
35994
35995 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35996 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35997 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35998 | SM(i->txpower, AR_XmitPower)
35999 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36000 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36001 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
36002 ctl12 |= SM(val, AR_PAPRDChainMask);
36003
36004 - ACCESS_ONCE(ads->ctl12) = ctl12;
36005 - ACCESS_ONCE(ads->ctl17) = ctl17;
36006 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
36007 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36008
36009 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36010 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36011 | set11nPktDurRTSCTS(i->rates, 1);
36012
36013 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36014 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36015 | set11nPktDurRTSCTS(i->rates, 3);
36016
36017 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
36018 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
36019 | set11nRateFlags(i->rates, 1)
36020 | set11nRateFlags(i->rates, 2)
36021 | set11nRateFlags(i->rates, 3)
36022 | SM(i->rtscts_rate, AR_RTSCTSRate);
36023
36024 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
36025 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
36026 }
36027
36028 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
36029 diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
36030 index 68d972b..1d9205b 100644
36031 --- a/drivers/net/wireless/ath/ath9k/debug.c
36032 +++ b/drivers/net/wireless/ath/ath9k/debug.c
36033 @@ -60,6 +60,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
36034 }
36035
36036 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
36037 + size_t count, loff_t *ppos) __size_overflow(3);
36038 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
36039 size_t count, loff_t *ppos)
36040 {
36041 struct ath_softc *sc = file->private_data;
36042 diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
36043 index d3ff33c..c98bcda 100644
36044 --- a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
36045 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
36046 @@ -464,6 +464,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
36047 }
36048
36049 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
36050 + size_t count, loff_t *ppos) __size_overflow(3);
36051 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
36052 size_t count, loff_t *ppos)
36053 {
36054 struct ath9k_htc_priv *priv = file->private_data;
36055 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
36056 index c8261d4..8d88929 100644
36057 --- a/drivers/net/wireless/ath/ath9k/hw.h
36058 +++ b/drivers/net/wireless/ath/ath9k/hw.h
36059 @@ -773,7 +773,7 @@ struct ath_hw_private_ops {
36060
36061 /* ANI */
36062 void (*ani_cache_ini_regs)(struct ath_hw *ah);
36063 -};
36064 +} __no_const;
36065
36066 /**
36067 * struct ath_hw_ops - callbacks used by hardware code and driver code
36068 @@ -803,7 +803,7 @@ struct ath_hw_ops {
36069 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
36070 struct ath_hw_antcomb_conf *antconf);
36071
36072 -};
36073 +} __no_const;
36074
36075 struct ath_nf_limits {
36076 s16 max;
36077 @@ -823,7 +823,7 @@ enum ath_cal_list {
36078 #define AH_FASTCC 0x4
36079
36080 struct ath_hw {
36081 - struct ath_ops reg_ops;
36082 + ath_ops_no_const reg_ops;
36083
36084 struct ieee80211_hw *hw;
36085 struct ath_common common;
36086 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36087 index af00e2c..ab04d34 100644
36088 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36089 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36090 @@ -545,7 +545,7 @@ struct phy_func_ptr {
36091 void (*carrsuppr)(struct brcms_phy *);
36092 s32 (*rxsigpwr)(struct brcms_phy *, s32);
36093 void (*detach)(struct brcms_phy *);
36094 -};
36095 +} __no_const;
36096
36097 struct brcms_phy {
36098 struct brcms_phy_pub pubpi_ro;
36099 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
36100 index a2ec369..36fdf14 100644
36101 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
36102 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
36103 @@ -3646,7 +3646,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
36104 */
36105 if (il3945_mod_params.disable_hw_scan) {
36106 D_INFO("Disabling hw_scan\n");
36107 - il3945_hw_ops.hw_scan = NULL;
36108 + pax_open_kernel();
36109 + *(void **)&il3945_hw_ops.hw_scan = NULL;
36110 + pax_close_kernel();
36111 }
36112
36113 D_INFO("*** LOAD DRIVER ***\n");
36114 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
36115 index f8fc239..8cade22 100644
36116 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
36117 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
36118 @@ -86,8 +86,8 @@ do { \
36119 } while (0)
36120
36121 #else
36122 -#define IWL_DEBUG(m, level, fmt, args...)
36123 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
36124 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
36125 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
36126 #define iwl_print_hex_dump(m, level, p, len)
36127 #define IWL_DEBUG_QUIET_RFKILL(p, fmt, args...) \
36128 do { \
36129 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36130 index 4b9e730..7603659 100644
36131 --- a/drivers/net/wireless/mac80211_hwsim.c
36132 +++ b/drivers/net/wireless/mac80211_hwsim.c
36133 @@ -1677,9 +1677,11 @@ static int __init init_mac80211_hwsim(void)
36134 return -EINVAL;
36135
36136 if (fake_hw_scan) {
36137 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36138 - mac80211_hwsim_ops.sw_scan_start = NULL;
36139 - mac80211_hwsim_ops.sw_scan_complete = NULL;
36140 + pax_open_kernel();
36141 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36142 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36143 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36144 + pax_close_kernel();
36145 }
36146
36147 spin_lock_init(&hwsim_radio_lock);
36148 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36149 index 3186aa4..b35b09f 100644
36150 --- a/drivers/net/wireless/mwifiex/main.h
36151 +++ b/drivers/net/wireless/mwifiex/main.h
36152 @@ -536,7 +536,7 @@ struct mwifiex_if_ops {
36153 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
36154 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
36155 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36156 -};
36157 +} __no_const;
36158
36159 struct mwifiex_adapter {
36160 u8 iface_type;
36161 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36162 index a330c69..a81540f 100644
36163 --- a/drivers/net/wireless/rndis_wlan.c
36164 +++ b/drivers/net/wireless/rndis_wlan.c
36165 @@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36166
36167 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36168
36169 - if (rts_threshold < 0 || rts_threshold > 2347)
36170 + if (rts_threshold > 2347)
36171 rts_threshold = 2347;
36172
36173 tmp = cpu_to_le32(rts_threshold);
36174 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
36175 index a77f1bb..c608b2b 100644
36176 --- a/drivers/net/wireless/wl1251/wl1251.h
36177 +++ b/drivers/net/wireless/wl1251/wl1251.h
36178 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
36179 void (*reset)(struct wl1251 *wl);
36180 void (*enable_irq)(struct wl1251 *wl);
36181 void (*disable_irq)(struct wl1251 *wl);
36182 -};
36183 +} __no_const;
36184
36185 struct wl1251 {
36186 struct ieee80211_hw *hw;
36187 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36188 index f34b5b2..b5abb9f 100644
36189 --- a/drivers/oprofile/buffer_sync.c
36190 +++ b/drivers/oprofile/buffer_sync.c
36191 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36192 if (cookie == NO_COOKIE)
36193 offset = pc;
36194 if (cookie == INVALID_COOKIE) {
36195 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36196 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36197 offset = pc;
36198 }
36199 if (cookie != last_cookie) {
36200 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36201 /* add userspace sample */
36202
36203 if (!mm) {
36204 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36205 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36206 return 0;
36207 }
36208
36209 cookie = lookup_dcookie(mm, s->eip, &offset);
36210
36211 if (cookie == INVALID_COOKIE) {
36212 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36213 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36214 return 0;
36215 }
36216
36217 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36218 /* ignore backtraces if failed to add a sample */
36219 if (state == sb_bt_start) {
36220 state = sb_bt_ignore;
36221 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36222 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36223 }
36224 }
36225 release_mm(mm);
36226 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36227 index c0cc4e7..44d4e54 100644
36228 --- a/drivers/oprofile/event_buffer.c
36229 +++ b/drivers/oprofile/event_buffer.c
36230 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36231 }
36232
36233 if (buffer_pos == buffer_size) {
36234 - atomic_inc(&oprofile_stats.event_lost_overflow);
36235 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36236 return;
36237 }
36238
36239 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36240 index ed2c3ec..deda85a 100644
36241 --- a/drivers/oprofile/oprof.c
36242 +++ b/drivers/oprofile/oprof.c
36243 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36244 if (oprofile_ops.switch_events())
36245 return;
36246
36247 - atomic_inc(&oprofile_stats.multiplex_counter);
36248 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36249 start_switch_worker();
36250 }
36251
36252 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
36253 index 84a208d..f07d177 100644
36254 --- a/drivers/oprofile/oprofile_files.c
36255 +++ b/drivers/oprofile/oprofile_files.c
36256 @@ -36,6 +36,8 @@ static ssize_t timeout_read(struct file *file, char __user *buf,
36257
36258
36259 static ssize_t timeout_write(struct file *file, char const __user *buf,
36260 + size_t count, loff_t *offset) __size_overflow(3);
36261 +static ssize_t timeout_write(struct file *file, char const __user *buf,
36262 size_t count, loff_t *offset)
36263 {
36264 unsigned long val;
36265 @@ -72,6 +74,7 @@ static ssize_t depth_read(struct file *file, char __user *buf, size_t count, lof
36266 }
36267
36268
36269 +static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
36270 static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
36271 {
36272 unsigned long val;
36273 @@ -126,12 +129,14 @@ static const struct file_operations cpu_type_fops = {
36274 };
36275
36276
36277 +static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset) __size_overflow(3);
36278 static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
36279 {
36280 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
36281 }
36282
36283
36284 +static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
36285 static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
36286 {
36287 unsigned long val;
36288 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36289 index 917d28e..d62d981 100644
36290 --- a/drivers/oprofile/oprofile_stats.c
36291 +++ b/drivers/oprofile/oprofile_stats.c
36292 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36293 cpu_buf->sample_invalid_eip = 0;
36294 }
36295
36296 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36297 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36298 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36299 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36300 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36301 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36302 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36303 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36304 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36305 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36306 }
36307
36308
36309 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36310 index 38b6fc0..b5cbfce 100644
36311 --- a/drivers/oprofile/oprofile_stats.h
36312 +++ b/drivers/oprofile/oprofile_stats.h
36313 @@ -13,11 +13,11 @@
36314 #include <linux/atomic.h>
36315
36316 struct oprofile_stat_struct {
36317 - atomic_t sample_lost_no_mm;
36318 - atomic_t sample_lost_no_mapping;
36319 - atomic_t bt_lost_no_mapping;
36320 - atomic_t event_lost_overflow;
36321 - atomic_t multiplex_counter;
36322 + atomic_unchecked_t sample_lost_no_mm;
36323 + atomic_unchecked_t sample_lost_no_mapping;
36324 + atomic_unchecked_t bt_lost_no_mapping;
36325 + atomic_unchecked_t event_lost_overflow;
36326 + atomic_unchecked_t multiplex_counter;
36327 };
36328
36329 extern struct oprofile_stat_struct oprofile_stats;
36330 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36331 index 2f0aa0f..d5246c3 100644
36332 --- a/drivers/oprofile/oprofilefs.c
36333 +++ b/drivers/oprofile/oprofilefs.c
36334 @@ -97,6 +97,7 @@ static ssize_t ulong_read_file(struct file *file, char __user *buf, size_t count
36335 }
36336
36337
36338 +static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
36339 static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset)
36340 {
36341 unsigned long value;
36342 @@ -193,7 +194,7 @@ static const struct file_operations atomic_ro_fops = {
36343
36344
36345 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36346 - char const *name, atomic_t *val)
36347 + char const *name, atomic_unchecked_t *val)
36348 {
36349 return __oprofilefs_create_file(sb, root, name,
36350 &atomic_ro_fops, 0444, val);
36351 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36352 index 3f56bc0..707d642 100644
36353 --- a/drivers/parport/procfs.c
36354 +++ b/drivers/parport/procfs.c
36355 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36356
36357 *ppos += len;
36358
36359 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36360 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36361 }
36362
36363 #ifdef CONFIG_PARPORT_1284
36364 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36365
36366 *ppos += len;
36367
36368 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36369 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36370 }
36371 #endif /* IEEE1284.3 support. */
36372
36373 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36374 index 9fff878..ad0ad53 100644
36375 --- a/drivers/pci/hotplug/cpci_hotplug.h
36376 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36377 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36378 int (*hardware_test) (struct slot* slot, u32 value);
36379 u8 (*get_power) (struct slot* slot);
36380 int (*set_power) (struct slot* slot, int value);
36381 -};
36382 +} __no_const;
36383
36384 struct cpci_hp_controller {
36385 unsigned int irq;
36386 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36387 index 76ba8a1..20ca857 100644
36388 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36389 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36390 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36391
36392 void compaq_nvram_init (void __iomem *rom_start)
36393 {
36394 +
36395 +#ifndef CONFIG_PAX_KERNEXEC
36396 if (rom_start) {
36397 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36398 }
36399 +#endif
36400 +
36401 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36402
36403 /* initialize our int15 lock */
36404 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36405 index 2275162..95f1a92 100644
36406 --- a/drivers/pci/pcie/aspm.c
36407 +++ b/drivers/pci/pcie/aspm.c
36408 @@ -27,9 +27,9 @@
36409 #define MODULE_PARAM_PREFIX "pcie_aspm."
36410
36411 /* Note: those are not register definitions */
36412 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36413 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36414 -#define ASPM_STATE_L1 (4) /* L1 state */
36415 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36416 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36417 +#define ASPM_STATE_L1 (4U) /* L1 state */
36418 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36419 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36420
36421 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36422 index 71eac9c..2de27ef 100644
36423 --- a/drivers/pci/probe.c
36424 +++ b/drivers/pci/probe.c
36425 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36426 u32 l, sz, mask;
36427 u16 orig_cmd;
36428
36429 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36430 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36431
36432 if (!dev->mmio_always_on) {
36433 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36434 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36435 index 27911b5..5b6db88 100644
36436 --- a/drivers/pci/proc.c
36437 +++ b/drivers/pci/proc.c
36438 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36439 static int __init pci_proc_init(void)
36440 {
36441 struct pci_dev *dev = NULL;
36442 +
36443 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36444 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36445 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36446 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36447 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36448 +#endif
36449 +#else
36450 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36451 +#endif
36452 proc_create("devices", 0, proc_bus_pci_dir,
36453 &proc_bus_pci_dev_operations);
36454 proc_initialized = 1;
36455 diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
36456 index 6f966d6..68e18ed 100644
36457 --- a/drivers/platform/x86/asus_acpi.c
36458 +++ b/drivers/platform/x86/asus_acpi.c
36459 @@ -887,6 +887,8 @@ static int lcd_proc_open(struct inode *inode, struct file *file)
36460 }
36461
36462 static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
36463 + size_t count, loff_t *pos) __size_overflow(3);
36464 +static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
36465 size_t count, loff_t *pos)
36466 {
36467 int rv, value;
36468 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36469 index ea0c607..58c4628 100644
36470 --- a/drivers/platform/x86/thinkpad_acpi.c
36471 +++ b/drivers/platform/x86/thinkpad_acpi.c
36472 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
36473 return 0;
36474 }
36475
36476 -void static hotkey_mask_warn_incomplete_mask(void)
36477 +static void hotkey_mask_warn_incomplete_mask(void)
36478 {
36479 /* log only what the user can fix... */
36480 const u32 wantedmask = hotkey_driver_mask &
36481 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36482 }
36483 }
36484
36485 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36486 - struct tp_nvram_state *newn,
36487 - const u32 event_mask)
36488 -{
36489 -
36490 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36491 do { \
36492 if ((event_mask & (1 << __scancode)) && \
36493 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36494 tpacpi_hotkey_send_key(__scancode); \
36495 } while (0)
36496
36497 - void issue_volchange(const unsigned int oldvol,
36498 - const unsigned int newvol)
36499 - {
36500 - unsigned int i = oldvol;
36501 +static void issue_volchange(const unsigned int oldvol,
36502 + const unsigned int newvol,
36503 + const u32 event_mask)
36504 +{
36505 + unsigned int i = oldvol;
36506
36507 - while (i > newvol) {
36508 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36509 - i--;
36510 - }
36511 - while (i < newvol) {
36512 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36513 - i++;
36514 - }
36515 + while (i > newvol) {
36516 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36517 + i--;
36518 }
36519 + while (i < newvol) {
36520 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36521 + i++;
36522 + }
36523 +}
36524
36525 - void issue_brightnesschange(const unsigned int oldbrt,
36526 - const unsigned int newbrt)
36527 - {
36528 - unsigned int i = oldbrt;
36529 +static void issue_brightnesschange(const unsigned int oldbrt,
36530 + const unsigned int newbrt,
36531 + const u32 event_mask)
36532 +{
36533 + unsigned int i = oldbrt;
36534
36535 - while (i > newbrt) {
36536 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36537 - i--;
36538 - }
36539 - while (i < newbrt) {
36540 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36541 - i++;
36542 - }
36543 + while (i > newbrt) {
36544 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36545 + i--;
36546 + }
36547 + while (i < newbrt) {
36548 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36549 + i++;
36550 }
36551 +}
36552
36553 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36554 + struct tp_nvram_state *newn,
36555 + const u32 event_mask)
36556 +{
36557 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36558 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36559 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36560 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36561 oldn->volume_level != newn->volume_level) {
36562 /* recently muted, or repeated mute keypress, or
36563 * multiple presses ending in mute */
36564 - issue_volchange(oldn->volume_level, newn->volume_level);
36565 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36566 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36567 }
36568 } else {
36569 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36570 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36571 }
36572 if (oldn->volume_level != newn->volume_level) {
36573 - issue_volchange(oldn->volume_level, newn->volume_level);
36574 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36575 } else if (oldn->volume_toggle != newn->volume_toggle) {
36576 /* repeated vol up/down keypress at end of scale ? */
36577 if (newn->volume_level == 0)
36578 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36579 /* handle brightness */
36580 if (oldn->brightness_level != newn->brightness_level) {
36581 issue_brightnesschange(oldn->brightness_level,
36582 - newn->brightness_level);
36583 + newn->brightness_level,
36584 + event_mask);
36585 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36586 /* repeated key presses that didn't change state */
36587 if (newn->brightness_level == 0)
36588 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36589 && !tp_features.bright_unkfw)
36590 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36591 }
36592 +}
36593
36594 #undef TPACPI_COMPARE_KEY
36595 #undef TPACPI_MAY_SEND_KEY
36596 -}
36597
36598 /*
36599 * Polling driver
36600 diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
36601 index dcdc1f4..85cee16 100644
36602 --- a/drivers/platform/x86/toshiba_acpi.c
36603 +++ b/drivers/platform/x86/toshiba_acpi.c
36604 @@ -517,6 +517,8 @@ static int set_lcd_status(struct backlight_device *bd)
36605 }
36606
36607 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
36608 + size_t count, loff_t *pos) __size_overflow(3);
36609 +static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
36610 size_t count, loff_t *pos)
36611 {
36612 struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
36613 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36614 index b859d16..5cc6b1a 100644
36615 --- a/drivers/pnp/pnpbios/bioscalls.c
36616 +++ b/drivers/pnp/pnpbios/bioscalls.c
36617 @@ -59,7 +59,7 @@ do { \
36618 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36619 } while(0)
36620
36621 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36622 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36623 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36624
36625 /*
36626 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36627
36628 cpu = get_cpu();
36629 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36630 +
36631 + pax_open_kernel();
36632 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36633 + pax_close_kernel();
36634
36635 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36636 spin_lock_irqsave(&pnp_bios_lock, flags);
36637 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36638 :"memory");
36639 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36640
36641 + pax_open_kernel();
36642 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36643 + pax_close_kernel();
36644 +
36645 put_cpu();
36646
36647 /* If we get here and this is set then the PnP BIOS faulted on us. */
36648 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36649 return status;
36650 }
36651
36652 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36653 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36654 {
36655 int i;
36656
36657 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36658 pnp_bios_callpoint.offset = header->fields.pm16offset;
36659 pnp_bios_callpoint.segment = PNP_CS16;
36660
36661 + pax_open_kernel();
36662 +
36663 for_each_possible_cpu(i) {
36664 struct desc_struct *gdt = get_cpu_gdt_table(i);
36665 if (!gdt)
36666 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36667 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36668 (unsigned long)__va(header->fields.pm16dseg));
36669 }
36670 +
36671 + pax_close_kernel();
36672 }
36673 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36674 index b0ecacb..7c9da2e 100644
36675 --- a/drivers/pnp/resource.c
36676 +++ b/drivers/pnp/resource.c
36677 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36678 return 1;
36679
36680 /* check if the resource is valid */
36681 - if (*irq < 0 || *irq > 15)
36682 + if (*irq > 15)
36683 return 0;
36684
36685 /* check if the resource is reserved */
36686 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36687 return 1;
36688
36689 /* check if the resource is valid */
36690 - if (*dma < 0 || *dma == 4 || *dma > 7)
36691 + if (*dma == 4 || *dma > 7)
36692 return 0;
36693
36694 /* check if the resource is reserved */
36695 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36696 index 1ed6ea0..77c0bd2 100644
36697 --- a/drivers/power/bq27x00_battery.c
36698 +++ b/drivers/power/bq27x00_battery.c
36699 @@ -72,7 +72,7 @@
36700 struct bq27x00_device_info;
36701 struct bq27x00_access_methods {
36702 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36703 -};
36704 +} __no_const;
36705
36706 enum bq27x00_chip { BQ27000, BQ27500 };
36707
36708 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36709 index a838e66..a9e1665 100644
36710 --- a/drivers/regulator/max8660.c
36711 +++ b/drivers/regulator/max8660.c
36712 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36713 max8660->shadow_regs[MAX8660_OVER1] = 5;
36714 } else {
36715 /* Otherwise devices can be toggled via software */
36716 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36717 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36718 + pax_open_kernel();
36719 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36720 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36721 + pax_close_kernel();
36722 }
36723
36724 /*
36725 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36726 index e8cfc99..072aee2 100644
36727 --- a/drivers/regulator/mc13892-regulator.c
36728 +++ b/drivers/regulator/mc13892-regulator.c
36729 @@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36730 }
36731 mc13xxx_unlock(mc13892);
36732
36733 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36734 + pax_open_kernel();
36735 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36736 = mc13892_vcam_set_mode;
36737 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36738 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36739 = mc13892_vcam_get_mode;
36740 + pax_close_kernel();
36741
36742 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36743 ARRAY_SIZE(mc13892_regulators));
36744 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36745 index cace6d3..f623fda 100644
36746 --- a/drivers/rtc/rtc-dev.c
36747 +++ b/drivers/rtc/rtc-dev.c
36748 @@ -14,6 +14,7 @@
36749 #include <linux/module.h>
36750 #include <linux/rtc.h>
36751 #include <linux/sched.h>
36752 +#include <linux/grsecurity.h>
36753 #include "rtc-core.h"
36754
36755 static dev_t rtc_devt;
36756 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36757 if (copy_from_user(&tm, uarg, sizeof(tm)))
36758 return -EFAULT;
36759
36760 + gr_log_timechange();
36761 +
36762 return rtc_set_time(rtc, &tm);
36763
36764 case RTC_PIE_ON:
36765 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36766 index ffb5878..e6d785c 100644
36767 --- a/drivers/scsi/aacraid/aacraid.h
36768 +++ b/drivers/scsi/aacraid/aacraid.h
36769 @@ -492,7 +492,7 @@ struct adapter_ops
36770 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36771 /* Administrative operations */
36772 int (*adapter_comm)(struct aac_dev * dev, int comm);
36773 -};
36774 +} __no_const;
36775
36776 /*
36777 * Define which interrupt handler needs to be installed
36778 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36779 index 705e13e..91c873c 100644
36780 --- a/drivers/scsi/aacraid/linit.c
36781 +++ b/drivers/scsi/aacraid/linit.c
36782 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36783 #elif defined(__devinitconst)
36784 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36785 #else
36786 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36787 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36788 #endif
36789 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36790 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36791 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36792 index d5ff142..49c0ebb 100644
36793 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36794 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36795 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36796 .lldd_control_phy = asd_control_phy,
36797 };
36798
36799 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36800 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36801 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36802 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36803 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36804 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36805 index a796de9..1ef20e1 100644
36806 --- a/drivers/scsi/bfa/bfa.h
36807 +++ b/drivers/scsi/bfa/bfa.h
36808 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36809 u32 *end);
36810 int cpe_vec_q0;
36811 int rme_vec_q0;
36812 -};
36813 +} __no_const;
36814 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36815
36816 struct bfa_faa_cbfn_s {
36817 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36818 index f0f80e2..8ec946b 100644
36819 --- a/drivers/scsi/bfa/bfa_fcpim.c
36820 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36821 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36822
36823 bfa_iotag_attach(fcp);
36824
36825 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36826 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36827 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36828 (fcp->num_itns * sizeof(struct bfa_itn_s));
36829 memset(fcp->itn_arr, 0,
36830 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36831 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36832 {
36833 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36834 - struct bfa_itn_s *itn;
36835 + bfa_itn_s_no_const *itn;
36836
36837 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36838 itn->isr = isr;
36839 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36840 index 36f26da..38a34a8 100644
36841 --- a/drivers/scsi/bfa/bfa_fcpim.h
36842 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36843 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36844 struct bfa_itn_s {
36845 bfa_isr_func_t isr;
36846 };
36847 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36848
36849 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36850 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36851 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36852 struct list_head iotag_tio_free_q; /* free IO resources */
36853 struct list_head iotag_unused_q; /* unused IO resources*/
36854 struct bfa_iotag_s *iotag_arr;
36855 - struct bfa_itn_s *itn_arr;
36856 + bfa_itn_s_no_const *itn_arr;
36857 int num_ioim_reqs;
36858 int num_fwtio_reqs;
36859 int num_itns;
36860 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36861 index 546d46b..642fa5b 100644
36862 --- a/drivers/scsi/bfa/bfa_ioc.h
36863 +++ b/drivers/scsi/bfa/bfa_ioc.h
36864 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36865 bfa_ioc_disable_cbfn_t disable_cbfn;
36866 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36867 bfa_ioc_reset_cbfn_t reset_cbfn;
36868 -};
36869 +} __no_const;
36870
36871 /*
36872 * IOC event notification mechanism.
36873 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36874 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36875 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36876 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36877 -};
36878 +} __no_const;
36879
36880 /*
36881 * Queue element to wait for room in request queue. FIFO order is
36882 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36883 index 351dc0b..951dc32 100644
36884 --- a/drivers/scsi/hosts.c
36885 +++ b/drivers/scsi/hosts.c
36886 @@ -42,7 +42,7 @@
36887 #include "scsi_logging.h"
36888
36889
36890 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36891 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36892
36893
36894 static void scsi_host_cls_release(struct device *dev)
36895 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36896 * subtract one because we increment first then return, but we need to
36897 * know what the next host number was before increment
36898 */
36899 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36900 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36901 shost->dma_channel = 0xff;
36902
36903 /* These three are default values which can be overridden */
36904 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36905 index b96962c..0c82ec2 100644
36906 --- a/drivers/scsi/hpsa.c
36907 +++ b/drivers/scsi/hpsa.c
36908 @@ -507,7 +507,7 @@ static inline u32 next_command(struct ctlr_info *h)
36909 u32 a;
36910
36911 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36912 - return h->access.command_completed(h);
36913 + return h->access->command_completed(h);
36914
36915 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36916 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36917 @@ -2991,7 +2991,7 @@ static void start_io(struct ctlr_info *h)
36918 while (!list_empty(&h->reqQ)) {
36919 c = list_entry(h->reqQ.next, struct CommandList, list);
36920 /* can't do anything if fifo is full */
36921 - if ((h->access.fifo_full(h))) {
36922 + if ((h->access->fifo_full(h))) {
36923 dev_warn(&h->pdev->dev, "fifo full\n");
36924 break;
36925 }
36926 @@ -3001,7 +3001,7 @@ static void start_io(struct ctlr_info *h)
36927 h->Qdepth--;
36928
36929 /* Tell the controller execute command */
36930 - h->access.submit_command(h, c);
36931 + h->access->submit_command(h, c);
36932
36933 /* Put job onto the completed Q */
36934 addQ(&h->cmpQ, c);
36935 @@ -3010,17 +3010,17 @@ static void start_io(struct ctlr_info *h)
36936
36937 static inline unsigned long get_next_completion(struct ctlr_info *h)
36938 {
36939 - return h->access.command_completed(h);
36940 + return h->access->command_completed(h);
36941 }
36942
36943 static inline bool interrupt_pending(struct ctlr_info *h)
36944 {
36945 - return h->access.intr_pending(h);
36946 + return h->access->intr_pending(h);
36947 }
36948
36949 static inline long interrupt_not_for_us(struct ctlr_info *h)
36950 {
36951 - return (h->access.intr_pending(h) == 0) ||
36952 + return (h->access->intr_pending(h) == 0) ||
36953 (h->interrupts_enabled == 0);
36954 }
36955
36956 @@ -3919,7 +3919,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36957 if (prod_index < 0)
36958 return -ENODEV;
36959 h->product_name = products[prod_index].product_name;
36960 - h->access = *(products[prod_index].access);
36961 + h->access = products[prod_index].access;
36962
36963 if (hpsa_board_disabled(h->pdev)) {
36964 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36965 @@ -4164,7 +4164,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36966
36967 assert_spin_locked(&lockup_detector_lock);
36968 remove_ctlr_from_lockup_detector_list(h);
36969 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36970 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36971 spin_lock_irqsave(&h->lock, flags);
36972 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36973 spin_unlock_irqrestore(&h->lock, flags);
36974 @@ -4344,7 +4344,7 @@ reinit_after_soft_reset:
36975 }
36976
36977 /* make sure the board interrupts are off */
36978 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36979 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36980
36981 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36982 goto clean2;
36983 @@ -4378,7 +4378,7 @@ reinit_after_soft_reset:
36984 * fake ones to scoop up any residual completions.
36985 */
36986 spin_lock_irqsave(&h->lock, flags);
36987 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36988 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36989 spin_unlock_irqrestore(&h->lock, flags);
36990 free_irq(h->intr[h->intr_mode], h);
36991 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36992 @@ -4397,9 +4397,9 @@ reinit_after_soft_reset:
36993 dev_info(&h->pdev->dev, "Board READY.\n");
36994 dev_info(&h->pdev->dev,
36995 "Waiting for stale completions to drain.\n");
36996 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36997 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36998 msleep(10000);
36999 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37000 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37001
37002 rc = controller_reset_failed(h->cfgtable);
37003 if (rc)
37004 @@ -4420,7 +4420,7 @@ reinit_after_soft_reset:
37005 }
37006
37007 /* Turn the interrupts on so we can service requests */
37008 - h->access.set_intr_mask(h, HPSA_INTR_ON);
37009 + h->access->set_intr_mask(h, HPSA_INTR_ON);
37010
37011 hpsa_hba_inquiry(h);
37012 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
37013 @@ -4472,7 +4472,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
37014 * To write all data in the battery backed cache to disks
37015 */
37016 hpsa_flush_cache(h);
37017 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37018 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37019 free_irq(h->intr[h->intr_mode], h);
37020 #ifdef CONFIG_PCI_MSI
37021 if (h->msix_vector)
37022 @@ -4636,7 +4636,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
37023 return;
37024 }
37025 /* Change the access methods to the performant access methods */
37026 - h->access = SA5_performant_access;
37027 + h->access = &SA5_performant_access;
37028 h->transMethod = CFGTBL_Trans_Performant;
37029 }
37030
37031 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
37032 index 91edafb..a9b88ec 100644
37033 --- a/drivers/scsi/hpsa.h
37034 +++ b/drivers/scsi/hpsa.h
37035 @@ -73,7 +73,7 @@ struct ctlr_info {
37036 unsigned int msix_vector;
37037 unsigned int msi_vector;
37038 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
37039 - struct access_method access;
37040 + struct access_method *access;
37041
37042 /* queue and queue Info */
37043 struct list_head reqQ;
37044 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
37045 index f2df059..a3a9930 100644
37046 --- a/drivers/scsi/ips.h
37047 +++ b/drivers/scsi/ips.h
37048 @@ -1027,7 +1027,7 @@ typedef struct {
37049 int (*intr)(struct ips_ha *);
37050 void (*enableint)(struct ips_ha *);
37051 uint32_t (*statupd)(struct ips_ha *);
37052 -} ips_hw_func_t;
37053 +} __no_const ips_hw_func_t;
37054
37055 typedef struct ips_ha {
37056 uint8_t ha_id[IPS_MAX_CHANNELS+1];
37057 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
37058 index 4d70d96..84d0573 100644
37059 --- a/drivers/scsi/libfc/fc_exch.c
37060 +++ b/drivers/scsi/libfc/fc_exch.c
37061 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
37062 * all together if not used XXX
37063 */
37064 struct {
37065 - atomic_t no_free_exch;
37066 - atomic_t no_free_exch_xid;
37067 - atomic_t xid_not_found;
37068 - atomic_t xid_busy;
37069 - atomic_t seq_not_found;
37070 - atomic_t non_bls_resp;
37071 + atomic_unchecked_t no_free_exch;
37072 + atomic_unchecked_t no_free_exch_xid;
37073 + atomic_unchecked_t xid_not_found;
37074 + atomic_unchecked_t xid_busy;
37075 + atomic_unchecked_t seq_not_found;
37076 + atomic_unchecked_t non_bls_resp;
37077 } stats;
37078 };
37079
37080 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
37081 /* allocate memory for exchange */
37082 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
37083 if (!ep) {
37084 - atomic_inc(&mp->stats.no_free_exch);
37085 + atomic_inc_unchecked(&mp->stats.no_free_exch);
37086 goto out;
37087 }
37088 memset(ep, 0, sizeof(*ep));
37089 @@ -780,7 +780,7 @@ out:
37090 return ep;
37091 err:
37092 spin_unlock_bh(&pool->lock);
37093 - atomic_inc(&mp->stats.no_free_exch_xid);
37094 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
37095 mempool_free(ep, mp->ep_pool);
37096 return NULL;
37097 }
37098 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37099 xid = ntohs(fh->fh_ox_id); /* we originated exch */
37100 ep = fc_exch_find(mp, xid);
37101 if (!ep) {
37102 - atomic_inc(&mp->stats.xid_not_found);
37103 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37104 reject = FC_RJT_OX_ID;
37105 goto out;
37106 }
37107 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37108 ep = fc_exch_find(mp, xid);
37109 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37110 if (ep) {
37111 - atomic_inc(&mp->stats.xid_busy);
37112 + atomic_inc_unchecked(&mp->stats.xid_busy);
37113 reject = FC_RJT_RX_ID;
37114 goto rel;
37115 }
37116 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37117 }
37118 xid = ep->xid; /* get our XID */
37119 } else if (!ep) {
37120 - atomic_inc(&mp->stats.xid_not_found);
37121 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37122 reject = FC_RJT_RX_ID; /* XID not found */
37123 goto out;
37124 }
37125 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37126 } else {
37127 sp = &ep->seq;
37128 if (sp->id != fh->fh_seq_id) {
37129 - atomic_inc(&mp->stats.seq_not_found);
37130 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37131 if (f_ctl & FC_FC_END_SEQ) {
37132 /*
37133 * Update sequence_id based on incoming last
37134 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37135
37136 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37137 if (!ep) {
37138 - atomic_inc(&mp->stats.xid_not_found);
37139 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37140 goto out;
37141 }
37142 if (ep->esb_stat & ESB_ST_COMPLETE) {
37143 - atomic_inc(&mp->stats.xid_not_found);
37144 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37145 goto rel;
37146 }
37147 if (ep->rxid == FC_XID_UNKNOWN)
37148 ep->rxid = ntohs(fh->fh_rx_id);
37149 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37150 - atomic_inc(&mp->stats.xid_not_found);
37151 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37152 goto rel;
37153 }
37154 if (ep->did != ntoh24(fh->fh_s_id) &&
37155 ep->did != FC_FID_FLOGI) {
37156 - atomic_inc(&mp->stats.xid_not_found);
37157 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37158 goto rel;
37159 }
37160 sof = fr_sof(fp);
37161 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37162 sp->ssb_stat |= SSB_ST_RESP;
37163 sp->id = fh->fh_seq_id;
37164 } else if (sp->id != fh->fh_seq_id) {
37165 - atomic_inc(&mp->stats.seq_not_found);
37166 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37167 goto rel;
37168 }
37169
37170 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37171 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37172
37173 if (!sp)
37174 - atomic_inc(&mp->stats.xid_not_found);
37175 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37176 else
37177 - atomic_inc(&mp->stats.non_bls_resp);
37178 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
37179
37180 fc_frame_free(fp);
37181 }
37182 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37183 index db9238f..4378ed2 100644
37184 --- a/drivers/scsi/libsas/sas_ata.c
37185 +++ b/drivers/scsi/libsas/sas_ata.c
37186 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
37187 .postreset = ata_std_postreset,
37188 .error_handler = ata_std_error_handler,
37189 .post_internal_cmd = sas_ata_post_internal,
37190 - .qc_defer = ata_std_qc_defer,
37191 + .qc_defer = ata_std_qc_defer,
37192 .qc_prep = ata_noop_qc_prep,
37193 .qc_issue = sas_ata_qc_issue,
37194 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37195 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37196 index 825f930..ce42672 100644
37197 --- a/drivers/scsi/lpfc/lpfc.h
37198 +++ b/drivers/scsi/lpfc/lpfc.h
37199 @@ -413,7 +413,7 @@ struct lpfc_vport {
37200 struct dentry *debug_nodelist;
37201 struct dentry *vport_debugfs_root;
37202 struct lpfc_debugfs_trc *disc_trc;
37203 - atomic_t disc_trc_cnt;
37204 + atomic_unchecked_t disc_trc_cnt;
37205 #endif
37206 uint8_t stat_data_enabled;
37207 uint8_t stat_data_blocked;
37208 @@ -821,8 +821,8 @@ struct lpfc_hba {
37209 struct timer_list fabric_block_timer;
37210 unsigned long bit_flags;
37211 #define FABRIC_COMANDS_BLOCKED 0
37212 - atomic_t num_rsrc_err;
37213 - atomic_t num_cmd_success;
37214 + atomic_unchecked_t num_rsrc_err;
37215 + atomic_unchecked_t num_cmd_success;
37216 unsigned long last_rsrc_error_time;
37217 unsigned long last_ramp_down_time;
37218 unsigned long last_ramp_up_time;
37219 @@ -852,7 +852,7 @@ struct lpfc_hba {
37220
37221 struct dentry *debug_slow_ring_trc;
37222 struct lpfc_debugfs_trc *slow_ring_trc;
37223 - atomic_t slow_ring_trc_cnt;
37224 + atomic_unchecked_t slow_ring_trc_cnt;
37225 /* iDiag debugfs sub-directory */
37226 struct dentry *idiag_root;
37227 struct dentry *idiag_pci_cfg;
37228 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37229 index 3587a3f..d45b81b 100644
37230 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37231 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37232 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37233
37234 #include <linux/debugfs.h>
37235
37236 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37237 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37238 static unsigned long lpfc_debugfs_start_time = 0L;
37239
37240 /* iDiag */
37241 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37242 lpfc_debugfs_enable = 0;
37243
37244 len = 0;
37245 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37246 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37247 (lpfc_debugfs_max_disc_trc - 1);
37248 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37249 dtp = vport->disc_trc + i;
37250 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37251 lpfc_debugfs_enable = 0;
37252
37253 len = 0;
37254 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37255 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37256 (lpfc_debugfs_max_slow_ring_trc - 1);
37257 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37258 dtp = phba->slow_ring_trc + i;
37259 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37260 !vport || !vport->disc_trc)
37261 return;
37262
37263 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37264 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37265 (lpfc_debugfs_max_disc_trc - 1);
37266 dtp = vport->disc_trc + index;
37267 dtp->fmt = fmt;
37268 dtp->data1 = data1;
37269 dtp->data2 = data2;
37270 dtp->data3 = data3;
37271 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37272 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37273 dtp->jif = jiffies;
37274 #endif
37275 return;
37276 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37277 !phba || !phba->slow_ring_trc)
37278 return;
37279
37280 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37281 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37282 (lpfc_debugfs_max_slow_ring_trc - 1);
37283 dtp = phba->slow_ring_trc + index;
37284 dtp->fmt = fmt;
37285 dtp->data1 = data1;
37286 dtp->data2 = data2;
37287 dtp->data3 = data3;
37288 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37289 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37290 dtp->jif = jiffies;
37291 #endif
37292 return;
37293 @@ -4040,7 +4040,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37294 "slow_ring buffer\n");
37295 goto debug_failed;
37296 }
37297 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37298 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37299 memset(phba->slow_ring_trc, 0,
37300 (sizeof(struct lpfc_debugfs_trc) *
37301 lpfc_debugfs_max_slow_ring_trc));
37302 @@ -4086,7 +4086,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37303 "buffer\n");
37304 goto debug_failed;
37305 }
37306 - atomic_set(&vport->disc_trc_cnt, 0);
37307 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37308
37309 snprintf(name, sizeof(name), "discovery_trace");
37310 vport->debug_disc_trc =
37311 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37312 index dfea2da..8e17227 100644
37313 --- a/drivers/scsi/lpfc/lpfc_init.c
37314 +++ b/drivers/scsi/lpfc/lpfc_init.c
37315 @@ -10145,8 +10145,10 @@ lpfc_init(void)
37316 printk(LPFC_COPYRIGHT "\n");
37317
37318 if (lpfc_enable_npiv) {
37319 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37320 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37321 + pax_open_kernel();
37322 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37323 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37324 + pax_close_kernel();
37325 }
37326 lpfc_transport_template =
37327 fc_attach_transport(&lpfc_transport_functions);
37328 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37329 index c60f5d0..751535c 100644
37330 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37331 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37332 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37333 uint32_t evt_posted;
37334
37335 spin_lock_irqsave(&phba->hbalock, flags);
37336 - atomic_inc(&phba->num_rsrc_err);
37337 + atomic_inc_unchecked(&phba->num_rsrc_err);
37338 phba->last_rsrc_error_time = jiffies;
37339
37340 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37341 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37342 unsigned long flags;
37343 struct lpfc_hba *phba = vport->phba;
37344 uint32_t evt_posted;
37345 - atomic_inc(&phba->num_cmd_success);
37346 + atomic_inc_unchecked(&phba->num_cmd_success);
37347
37348 if (vport->cfg_lun_queue_depth <= queue_depth)
37349 return;
37350 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37351 unsigned long num_rsrc_err, num_cmd_success;
37352 int i;
37353
37354 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37355 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37356 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37357 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37358
37359 vports = lpfc_create_vport_work_array(phba);
37360 if (vports != NULL)
37361 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37362 }
37363 }
37364 lpfc_destroy_vport_work_array(phba, vports);
37365 - atomic_set(&phba->num_rsrc_err, 0);
37366 - atomic_set(&phba->num_cmd_success, 0);
37367 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37368 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37369 }
37370
37371 /**
37372 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37373 }
37374 }
37375 lpfc_destroy_vport_work_array(phba, vports);
37376 - atomic_set(&phba->num_rsrc_err, 0);
37377 - atomic_set(&phba->num_cmd_success, 0);
37378 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37379 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37380 }
37381
37382 /**
37383 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37384 index ea8a0b4..812a124 100644
37385 --- a/drivers/scsi/pmcraid.c
37386 +++ b/drivers/scsi/pmcraid.c
37387 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37388 res->scsi_dev = scsi_dev;
37389 scsi_dev->hostdata = res;
37390 res->change_detected = 0;
37391 - atomic_set(&res->read_failures, 0);
37392 - atomic_set(&res->write_failures, 0);
37393 + atomic_set_unchecked(&res->read_failures, 0);
37394 + atomic_set_unchecked(&res->write_failures, 0);
37395 rc = 0;
37396 }
37397 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37398 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37399
37400 /* If this was a SCSI read/write command keep count of errors */
37401 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37402 - atomic_inc(&res->read_failures);
37403 + atomic_inc_unchecked(&res->read_failures);
37404 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37405 - atomic_inc(&res->write_failures);
37406 + atomic_inc_unchecked(&res->write_failures);
37407
37408 if (!RES_IS_GSCSI(res->cfg_entry) &&
37409 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37410 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37411 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37412 * hrrq_id assigned here in queuecommand
37413 */
37414 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37415 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37416 pinstance->num_hrrq;
37417 cmd->cmd_done = pmcraid_io_done;
37418
37419 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37420 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37421 * hrrq_id assigned here in queuecommand
37422 */
37423 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37424 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37425 pinstance->num_hrrq;
37426
37427 if (request_size) {
37428 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37429
37430 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37431 /* add resources only after host is added into system */
37432 - if (!atomic_read(&pinstance->expose_resources))
37433 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37434 return;
37435
37436 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37437 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37438 init_waitqueue_head(&pinstance->reset_wait_q);
37439
37440 atomic_set(&pinstance->outstanding_cmds, 0);
37441 - atomic_set(&pinstance->last_message_id, 0);
37442 - atomic_set(&pinstance->expose_resources, 0);
37443 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37444 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37445
37446 INIT_LIST_HEAD(&pinstance->free_res_q);
37447 INIT_LIST_HEAD(&pinstance->used_res_q);
37448 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37449 /* Schedule worker thread to handle CCN and take care of adding and
37450 * removing devices to OS
37451 */
37452 - atomic_set(&pinstance->expose_resources, 1);
37453 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37454 schedule_work(&pinstance->worker_q);
37455 return rc;
37456
37457 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37458 index ca496c7..9c791d5 100644
37459 --- a/drivers/scsi/pmcraid.h
37460 +++ b/drivers/scsi/pmcraid.h
37461 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37462 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37463
37464 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37465 - atomic_t last_message_id;
37466 + atomic_unchecked_t last_message_id;
37467
37468 /* configuration table */
37469 struct pmcraid_config_table *cfg_table;
37470 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37471 atomic_t outstanding_cmds;
37472
37473 /* should add/delete resources to mid-layer now ?*/
37474 - atomic_t expose_resources;
37475 + atomic_unchecked_t expose_resources;
37476
37477
37478
37479 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37480 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37481 };
37482 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37483 - atomic_t read_failures; /* count of failed READ commands */
37484 - atomic_t write_failures; /* count of failed WRITE commands */
37485 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37486 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37487
37488 /* To indicate add/delete/modify during CCN */
37489 u8 change_detected;
37490 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37491 index af1003f..be55a75 100644
37492 --- a/drivers/scsi/qla2xxx/qla_def.h
37493 +++ b/drivers/scsi/qla2xxx/qla_def.h
37494 @@ -2247,7 +2247,7 @@ struct isp_operations {
37495 int (*start_scsi) (srb_t *);
37496 int (*abort_isp) (struct scsi_qla_host *);
37497 int (*iospace_config)(struct qla_hw_data*);
37498 -};
37499 +} __no_const;
37500
37501 /* MSI-X Support *************************************************************/
37502
37503 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37504 index bfe6854..ceac088 100644
37505 --- a/drivers/scsi/qla4xxx/ql4_def.h
37506 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37507 @@ -261,7 +261,7 @@ struct ddb_entry {
37508 * (4000 only) */
37509 atomic_t relogin_timer; /* Max Time to wait for
37510 * relogin to complete */
37511 - atomic_t relogin_retry_count; /* Num of times relogin has been
37512 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37513 * retried */
37514 uint32_t default_time2wait; /* Default Min time between
37515 * relogins (+aens) */
37516 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37517 index ce6d3b7..73fac54 100644
37518 --- a/drivers/scsi/qla4xxx/ql4_os.c
37519 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37520 @@ -2178,12 +2178,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37521 */
37522 if (!iscsi_is_session_online(cls_sess)) {
37523 /* Reset retry relogin timer */
37524 - atomic_inc(&ddb_entry->relogin_retry_count);
37525 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37526 DEBUG2(ql4_printk(KERN_INFO, ha,
37527 "%s: index[%d] relogin timed out-retrying"
37528 " relogin (%d), retry (%d)\n", __func__,
37529 ddb_entry->fw_ddb_index,
37530 - atomic_read(&ddb_entry->relogin_retry_count),
37531 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37532 ddb_entry->default_time2wait + 4));
37533 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37534 atomic_set(&ddb_entry->retry_relogin_timer,
37535 @@ -3953,7 +3953,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37536
37537 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37538 atomic_set(&ddb_entry->relogin_timer, 0);
37539 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37540 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37541 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37542 ddb_entry->default_relogin_timeout =
37543 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37544 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37545 index 2aeb2e9..46e3925 100644
37546 --- a/drivers/scsi/scsi.c
37547 +++ b/drivers/scsi/scsi.c
37548 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37549 unsigned long timeout;
37550 int rtn = 0;
37551
37552 - atomic_inc(&cmd->device->iorequest_cnt);
37553 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37554
37555 /* check if the device is still usable */
37556 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37557 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37558 index b2c95db..227d74e 100644
37559 --- a/drivers/scsi/scsi_lib.c
37560 +++ b/drivers/scsi/scsi_lib.c
37561 @@ -1411,7 +1411,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37562 shost = sdev->host;
37563 scsi_init_cmd_errh(cmd);
37564 cmd->result = DID_NO_CONNECT << 16;
37565 - atomic_inc(&cmd->device->iorequest_cnt);
37566 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37567
37568 /*
37569 * SCSI request completion path will do scsi_device_unbusy(),
37570 @@ -1437,9 +1437,9 @@ static void scsi_softirq_done(struct request *rq)
37571
37572 INIT_LIST_HEAD(&cmd->eh_entry);
37573
37574 - atomic_inc(&cmd->device->iodone_cnt);
37575 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37576 if (cmd->result)
37577 - atomic_inc(&cmd->device->ioerr_cnt);
37578 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37579
37580 disposition = scsi_decide_disposition(cmd);
37581 if (disposition != SUCCESS &&
37582 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37583 index 04c2a27..9d8bd66 100644
37584 --- a/drivers/scsi/scsi_sysfs.c
37585 +++ b/drivers/scsi/scsi_sysfs.c
37586 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37587 char *buf) \
37588 { \
37589 struct scsi_device *sdev = to_scsi_device(dev); \
37590 - unsigned long long count = atomic_read(&sdev->field); \
37591 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37592 return snprintf(buf, 20, "0x%llx\n", count); \
37593 } \
37594 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37595 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37596 index 84a1fdf..693b0d6 100644
37597 --- a/drivers/scsi/scsi_tgt_lib.c
37598 +++ b/drivers/scsi/scsi_tgt_lib.c
37599 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37600 int err;
37601
37602 dprintk("%lx %u\n", uaddr, len);
37603 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37604 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37605 if (err) {
37606 /*
37607 * TODO: need to fixup sg_tablesize, max_segment_size,
37608 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37609 index f59d4a0..1d89407 100644
37610 --- a/drivers/scsi/scsi_transport_fc.c
37611 +++ b/drivers/scsi/scsi_transport_fc.c
37612 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37613 * Netlink Infrastructure
37614 */
37615
37616 -static atomic_t fc_event_seq;
37617 +static atomic_unchecked_t fc_event_seq;
37618
37619 /**
37620 * fc_get_event_number - Obtain the next sequential FC event number
37621 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
37622 u32
37623 fc_get_event_number(void)
37624 {
37625 - return atomic_add_return(1, &fc_event_seq);
37626 + return atomic_add_return_unchecked(1, &fc_event_seq);
37627 }
37628 EXPORT_SYMBOL(fc_get_event_number);
37629
37630 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
37631 {
37632 int error;
37633
37634 - atomic_set(&fc_event_seq, 0);
37635 + atomic_set_unchecked(&fc_event_seq, 0);
37636
37637 error = transport_class_register(&fc_host_class);
37638 if (error)
37639 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37640 char *cp;
37641
37642 *val = simple_strtoul(buf, &cp, 0);
37643 - if ((*cp && (*cp != '\n')) || (*val < 0))
37644 + if (*cp && (*cp != '\n'))
37645 return -EINVAL;
37646 /*
37647 * Check for overflow; dev_loss_tmo is u32
37648 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37649 index e3e3c7d..ebdab62 100644
37650 --- a/drivers/scsi/scsi_transport_iscsi.c
37651 +++ b/drivers/scsi/scsi_transport_iscsi.c
37652 @@ -79,7 +79,7 @@ struct iscsi_internal {
37653 struct transport_container session_cont;
37654 };
37655
37656 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37657 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37658 static struct workqueue_struct *iscsi_eh_timer_workq;
37659
37660 static DEFINE_IDA(iscsi_sess_ida);
37661 @@ -1063,7 +1063,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37662 int err;
37663
37664 ihost = shost->shost_data;
37665 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37666 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37667
37668 if (target_id == ISCSI_MAX_TARGET) {
37669 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37670 @@ -2680,7 +2680,7 @@ static __init int iscsi_transport_init(void)
37671 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37672 ISCSI_TRANSPORT_VERSION);
37673
37674 - atomic_set(&iscsi_session_nr, 0);
37675 + atomic_set_unchecked(&iscsi_session_nr, 0);
37676
37677 err = class_register(&iscsi_transport_class);
37678 if (err)
37679 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37680 index 21a045e..ec89e03 100644
37681 --- a/drivers/scsi/scsi_transport_srp.c
37682 +++ b/drivers/scsi/scsi_transport_srp.c
37683 @@ -33,7 +33,7 @@
37684 #include "scsi_transport_srp_internal.h"
37685
37686 struct srp_host_attrs {
37687 - atomic_t next_port_id;
37688 + atomic_unchecked_t next_port_id;
37689 };
37690 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37691
37692 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37693 struct Scsi_Host *shost = dev_to_shost(dev);
37694 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37695
37696 - atomic_set(&srp_host->next_port_id, 0);
37697 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37698 return 0;
37699 }
37700
37701 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37702 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37703 rport->roles = ids->roles;
37704
37705 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37706 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37707 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37708
37709 transport_setup_device(&rport->dev);
37710 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37711 index eacd46b..e3f4d62 100644
37712 --- a/drivers/scsi/sg.c
37713 +++ b/drivers/scsi/sg.c
37714 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37715 sdp->disk->disk_name,
37716 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37717 NULL,
37718 - (char *)arg);
37719 + (char __user *)arg);
37720 case BLKTRACESTART:
37721 return blk_trace_startstop(sdp->device->request_queue, 1);
37722 case BLKTRACESTOP:
37723 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37724 const struct file_operations * fops;
37725 };
37726
37727 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37728 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37729 {"allow_dio", &adio_fops},
37730 {"debug", &debug_fops},
37731 {"def_reserved_size", &dressz_fops},
37732 @@ -2332,7 +2332,7 @@ sg_proc_init(void)
37733 if (!sg_proc_sgp)
37734 return 1;
37735 for (k = 0; k < num_leaves; ++k) {
37736 - struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37737 + const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37738 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37739 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37740 }
37741 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
37742 index f64250e..1ee3049 100644
37743 --- a/drivers/spi/spi-dw-pci.c
37744 +++ b/drivers/spi/spi-dw-pci.c
37745 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
37746 #define spi_resume NULL
37747 #endif
37748
37749 -static const struct pci_device_id pci_ids[] __devinitdata = {
37750 +static const struct pci_device_id pci_ids[] __devinitconst = {
37751 /* Intel MID platform SPI controller 0 */
37752 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
37753 {},
37754 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37755 index b2ccdea..84cde75 100644
37756 --- a/drivers/spi/spi.c
37757 +++ b/drivers/spi/spi.c
37758 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
37759 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37760
37761 /* portable code must never pass more than 32 bytes */
37762 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37763 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37764
37765 static u8 *buf;
37766
37767 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37768 index 400df8c..065d4f4 100644
37769 --- a/drivers/staging/octeon/ethernet-rx.c
37770 +++ b/drivers/staging/octeon/ethernet-rx.c
37771 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37772 /* Increment RX stats for virtual ports */
37773 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37774 #ifdef CONFIG_64BIT
37775 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37776 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37777 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37778 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37779 #else
37780 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37781 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37782 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37783 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37784 #endif
37785 }
37786 netif_receive_skb(skb);
37787 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37788 dev->name);
37789 */
37790 #ifdef CONFIG_64BIT
37791 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37792 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37793 #else
37794 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37795 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37796 #endif
37797 dev_kfree_skb_irq(skb);
37798 }
37799 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37800 index 9112cd8..92f8d51 100644
37801 --- a/drivers/staging/octeon/ethernet.c
37802 +++ b/drivers/staging/octeon/ethernet.c
37803 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37804 * since the RX tasklet also increments it.
37805 */
37806 #ifdef CONFIG_64BIT
37807 - atomic64_add(rx_status.dropped_packets,
37808 - (atomic64_t *)&priv->stats.rx_dropped);
37809 + atomic64_add_unchecked(rx_status.dropped_packets,
37810 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37811 #else
37812 - atomic_add(rx_status.dropped_packets,
37813 - (atomic_t *)&priv->stats.rx_dropped);
37814 + atomic_add_unchecked(rx_status.dropped_packets,
37815 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37816 #endif
37817 }
37818
37819 diff --git a/drivers/staging/rtl8192e/rtllib_module.c b/drivers/staging/rtl8192e/rtllib_module.c
37820 index f9dae95..ff48901 100644
37821 --- a/drivers/staging/rtl8192e/rtllib_module.c
37822 +++ b/drivers/staging/rtl8192e/rtllib_module.c
37823 @@ -215,6 +215,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
37824 }
37825
37826 static int store_debug_level(struct file *file, const char __user *buffer,
37827 + unsigned long count, void *data) __size_overflow(3);
37828 +static int store_debug_level(struct file *file, const char __user *buffer,
37829 unsigned long count, void *data)
37830 {
37831 char buf[] = "0x00000000";
37832 diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37833 index e3d47bc..85f4d0d 100644
37834 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37835 +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37836 @@ -250,6 +250,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
37837 }
37838
37839 static int store_debug_level(struct file *file, const char *buffer,
37840 + unsigned long count, void *data) __size_overflow(3);
37841 +static int store_debug_level(struct file *file, const char *buffer,
37842 unsigned long count, void *data)
37843 {
37844 char buf[] = "0x00000000";
37845 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37846 index 86308a0..feaa925 100644
37847 --- a/drivers/staging/rtl8712/rtl871x_io.h
37848 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37849 @@ -108,7 +108,7 @@ struct _io_ops {
37850 u8 *pmem);
37851 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37852 u8 *pmem);
37853 -};
37854 +} __no_const;
37855
37856 struct io_req {
37857 struct list_head list;
37858 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37859 index c7b5e8b..783d6cb 100644
37860 --- a/drivers/staging/sbe-2t3e3/netdev.c
37861 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37862 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37863 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37864
37865 if (rlen)
37866 - if (copy_to_user(data, &resp, rlen))
37867 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37868 return -EFAULT;
37869
37870 return 0;
37871 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37872 index 42cdafe..2769103 100644
37873 --- a/drivers/staging/speakup/speakup_soft.c
37874 +++ b/drivers/staging/speakup/speakup_soft.c
37875 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37876 break;
37877 } else if (!initialized) {
37878 if (*init) {
37879 - ch = *init;
37880 init++;
37881 } else {
37882 initialized = 1;
37883 }
37884 + ch = *init;
37885 } else {
37886 ch = synth_buffer_getc();
37887 }
37888 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37889 index b8f8c48..1fc5025 100644
37890 --- a/drivers/staging/usbip/usbip_common.h
37891 +++ b/drivers/staging/usbip/usbip_common.h
37892 @@ -289,7 +289,7 @@ struct usbip_device {
37893 void (*shutdown)(struct usbip_device *);
37894 void (*reset)(struct usbip_device *);
37895 void (*unusable)(struct usbip_device *);
37896 - } eh_ops;
37897 + } __no_const eh_ops;
37898 };
37899
37900 /* usbip_common.c */
37901 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37902 index 88b3298..3783eee 100644
37903 --- a/drivers/staging/usbip/vhci.h
37904 +++ b/drivers/staging/usbip/vhci.h
37905 @@ -88,7 +88,7 @@ struct vhci_hcd {
37906 unsigned resuming:1;
37907 unsigned long re_timeout;
37908
37909 - atomic_t seqnum;
37910 + atomic_unchecked_t seqnum;
37911
37912 /*
37913 * NOTE:
37914 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37915 index 2ee97e2..0420b86 100644
37916 --- a/drivers/staging/usbip/vhci_hcd.c
37917 +++ b/drivers/staging/usbip/vhci_hcd.c
37918 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
37919 return;
37920 }
37921
37922 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37923 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37924 if (priv->seqnum == 0xffff)
37925 dev_info(&urb->dev->dev, "seqnum max\n");
37926
37927 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37928 return -ENOMEM;
37929 }
37930
37931 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37932 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37933 if (unlink->seqnum == 0xffff)
37934 pr_info("seqnum max\n");
37935
37936 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
37937 vdev->rhport = rhport;
37938 }
37939
37940 - atomic_set(&vhci->seqnum, 0);
37941 + atomic_set_unchecked(&vhci->seqnum, 0);
37942 spin_lock_init(&vhci->lock);
37943
37944 hcd->power_budget = 0; /* no limit */
37945 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37946 index 3f511b4..d3dbc1e 100644
37947 --- a/drivers/staging/usbip/vhci_rx.c
37948 +++ b/drivers/staging/usbip/vhci_rx.c
37949 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37950 if (!urb) {
37951 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37952 pr_info("max seqnum %d\n",
37953 - atomic_read(&the_controller->seqnum));
37954 + atomic_read_unchecked(&the_controller->seqnum));
37955 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37956 return;
37957 }
37958 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37959 index 7735027..30eed13 100644
37960 --- a/drivers/staging/vt6655/hostap.c
37961 +++ b/drivers/staging/vt6655/hostap.c
37962 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37963 *
37964 */
37965
37966 +static net_device_ops_no_const apdev_netdev_ops;
37967 +
37968 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37969 {
37970 PSDevice apdev_priv;
37971 struct net_device *dev = pDevice->dev;
37972 int ret;
37973 - const struct net_device_ops apdev_netdev_ops = {
37974 - .ndo_start_xmit = pDevice->tx_80211,
37975 - };
37976
37977 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37978
37979 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37980 *apdev_priv = *pDevice;
37981 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37982
37983 + /* only half broken now */
37984 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37985 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37986
37987 pDevice->apdev->type = ARPHRD_IEEE80211;
37988 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37989 index 51b5adf..098e320 100644
37990 --- a/drivers/staging/vt6656/hostap.c
37991 +++ b/drivers/staging/vt6656/hostap.c
37992 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37993 *
37994 */
37995
37996 +static net_device_ops_no_const apdev_netdev_ops;
37997 +
37998 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37999 {
38000 PSDevice apdev_priv;
38001 struct net_device *dev = pDevice->dev;
38002 int ret;
38003 - const struct net_device_ops apdev_netdev_ops = {
38004 - .ndo_start_xmit = pDevice->tx_80211,
38005 - };
38006
38007 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38008
38009 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38010 *apdev_priv = *pDevice;
38011 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38012
38013 + /* only half broken now */
38014 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38015 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38016
38017 pDevice->apdev->type = ARPHRD_IEEE80211;
38018 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
38019 index 7843dfd..3db105f 100644
38020 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
38021 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
38022 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
38023
38024 struct usbctlx_completor {
38025 int (*complete) (struct usbctlx_completor *);
38026 -};
38027 +} __no_const;
38028
38029 static int
38030 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
38031 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
38032 index 1ca66ea..76f1343 100644
38033 --- a/drivers/staging/zcache/tmem.c
38034 +++ b/drivers/staging/zcache/tmem.c
38035 @@ -39,7 +39,7 @@
38036 * A tmem host implementation must use this function to register callbacks
38037 * for memory allocation.
38038 */
38039 -static struct tmem_hostops tmem_hostops;
38040 +static tmem_hostops_no_const tmem_hostops;
38041
38042 static void tmem_objnode_tree_init(void);
38043
38044 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
38045 * A tmem host implementation must use this function to register
38046 * callbacks for a page-accessible memory (PAM) implementation
38047 */
38048 -static struct tmem_pamops tmem_pamops;
38049 +static tmem_pamops_no_const tmem_pamops;
38050
38051 void tmem_register_pamops(struct tmem_pamops *m)
38052 {
38053 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
38054 index ed147c4..94fc3c6 100644
38055 --- a/drivers/staging/zcache/tmem.h
38056 +++ b/drivers/staging/zcache/tmem.h
38057 @@ -180,6 +180,7 @@ struct tmem_pamops {
38058 void (*new_obj)(struct tmem_obj *);
38059 int (*replace_in_obj)(void *, struct tmem_obj *);
38060 };
38061 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
38062 extern void tmem_register_pamops(struct tmem_pamops *m);
38063
38064 /* memory allocation methods provided by the host implementation */
38065 @@ -189,6 +190,7 @@ struct tmem_hostops {
38066 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
38067 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
38068 };
38069 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
38070 extern void tmem_register_hostops(struct tmem_hostops *m);
38071
38072 /* core tmem accessor functions */
38073 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
38074 index 97c74ee..7f6d77d 100644
38075 --- a/drivers/target/iscsi/iscsi_target.c
38076 +++ b/drivers/target/iscsi/iscsi_target.c
38077 @@ -1361,7 +1361,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
38078 * outstanding_r2ts reaches zero, go ahead and send the delayed
38079 * TASK_ABORTED status.
38080 */
38081 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
38082 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
38083 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
38084 if (--cmd->outstanding_r2ts < 1) {
38085 iscsit_stop_dataout_timer(cmd);
38086 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
38087 index dcb0618..97e3d85 100644
38088 --- a/drivers/target/target_core_tmr.c
38089 +++ b/drivers/target/target_core_tmr.c
38090 @@ -260,7 +260,7 @@ static void core_tmr_drain_task_list(
38091 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
38092 cmd->t_task_list_num,
38093 atomic_read(&cmd->t_task_cdbs_left),
38094 - atomic_read(&cmd->t_task_cdbs_sent),
38095 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
38096 atomic_read(&cmd->t_transport_active),
38097 atomic_read(&cmd->t_transport_stop),
38098 atomic_read(&cmd->t_transport_sent));
38099 @@ -291,7 +291,7 @@ static void core_tmr_drain_task_list(
38100 pr_debug("LUN_RESET: got t_transport_active = 1 for"
38101 " task: %p, t_fe_count: %d dev: %p\n", task,
38102 fe_count, dev);
38103 - atomic_set(&cmd->t_transport_aborted, 1);
38104 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
38105 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
38106
38107 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
38108 @@ -299,7 +299,7 @@ static void core_tmr_drain_task_list(
38109 }
38110 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
38111 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
38112 - atomic_set(&cmd->t_transport_aborted, 1);
38113 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
38114 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
38115
38116 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
38117 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
38118 index cd5cd95..5249d30 100644
38119 --- a/drivers/target/target_core_transport.c
38120 +++ b/drivers/target/target_core_transport.c
38121 @@ -1330,7 +1330,7 @@ struct se_device *transport_add_device_to_core_hba(
38122 spin_lock_init(&dev->se_port_lock);
38123 spin_lock_init(&dev->se_tmr_lock);
38124 spin_lock_init(&dev->qf_cmd_lock);
38125 - atomic_set(&dev->dev_ordered_id, 0);
38126 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
38127
38128 se_dev_set_default_attribs(dev, dev_limits);
38129
38130 @@ -1517,7 +1517,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
38131 * Used to determine when ORDERED commands should go from
38132 * Dormant to Active status.
38133 */
38134 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
38135 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
38136 smp_mb__after_atomic_inc();
38137 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
38138 cmd->se_ordered_id, cmd->sam_task_attr,
38139 @@ -1862,7 +1862,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
38140 " t_transport_active: %d t_transport_stop: %d"
38141 " t_transport_sent: %d\n", cmd->t_task_list_num,
38142 atomic_read(&cmd->t_task_cdbs_left),
38143 - atomic_read(&cmd->t_task_cdbs_sent),
38144 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
38145 atomic_read(&cmd->t_task_cdbs_ex_left),
38146 atomic_read(&cmd->t_transport_active),
38147 atomic_read(&cmd->t_transport_stop),
38148 @@ -2121,9 +2121,9 @@ check_depth:
38149 cmd = task->task_se_cmd;
38150 spin_lock_irqsave(&cmd->t_state_lock, flags);
38151 task->task_flags |= (TF_ACTIVE | TF_SENT);
38152 - atomic_inc(&cmd->t_task_cdbs_sent);
38153 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
38154
38155 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
38156 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
38157 cmd->t_task_list_num)
38158 atomic_set(&cmd->t_transport_sent, 1);
38159
38160 @@ -4348,7 +4348,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
38161 atomic_set(&cmd->transport_lun_stop, 0);
38162 }
38163 if (!atomic_read(&cmd->t_transport_active) ||
38164 - atomic_read(&cmd->t_transport_aborted)) {
38165 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
38166 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
38167 return false;
38168 }
38169 @@ -4597,7 +4597,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
38170 {
38171 int ret = 0;
38172
38173 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
38174 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
38175 if (!send_status ||
38176 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
38177 return 1;
38178 @@ -4634,7 +4634,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
38179 */
38180 if (cmd->data_direction == DMA_TO_DEVICE) {
38181 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
38182 - atomic_inc(&cmd->t_transport_aborted);
38183 + atomic_inc_unchecked(&cmd->t_transport_aborted);
38184 smp_mb__after_atomic_inc();
38185 }
38186 }
38187 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38188 index b9040be..e3f5aab 100644
38189 --- a/drivers/tty/hvc/hvcs.c
38190 +++ b/drivers/tty/hvc/hvcs.c
38191 @@ -83,6 +83,7 @@
38192 #include <asm/hvcserver.h>
38193 #include <asm/uaccess.h>
38194 #include <asm/vio.h>
38195 +#include <asm/local.h>
38196
38197 /*
38198 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38199 @@ -270,7 +271,7 @@ struct hvcs_struct {
38200 unsigned int index;
38201
38202 struct tty_struct *tty;
38203 - int open_count;
38204 + local_t open_count;
38205
38206 /*
38207 * Used to tell the driver kernel_thread what operations need to take
38208 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38209
38210 spin_lock_irqsave(&hvcsd->lock, flags);
38211
38212 - if (hvcsd->open_count > 0) {
38213 + if (local_read(&hvcsd->open_count) > 0) {
38214 spin_unlock_irqrestore(&hvcsd->lock, flags);
38215 printk(KERN_INFO "HVCS: vterm state unchanged. "
38216 "The hvcs device node is still in use.\n");
38217 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38218 if ((retval = hvcs_partner_connect(hvcsd)))
38219 goto error_release;
38220
38221 - hvcsd->open_count = 1;
38222 + local_set(&hvcsd->open_count, 1);
38223 hvcsd->tty = tty;
38224 tty->driver_data = hvcsd;
38225
38226 @@ -1179,7 +1180,7 @@ fast_open:
38227
38228 spin_lock_irqsave(&hvcsd->lock, flags);
38229 kref_get(&hvcsd->kref);
38230 - hvcsd->open_count++;
38231 + local_inc(&hvcsd->open_count);
38232 hvcsd->todo_mask |= HVCS_SCHED_READ;
38233 spin_unlock_irqrestore(&hvcsd->lock, flags);
38234
38235 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38236 hvcsd = tty->driver_data;
38237
38238 spin_lock_irqsave(&hvcsd->lock, flags);
38239 - if (--hvcsd->open_count == 0) {
38240 + if (local_dec_and_test(&hvcsd->open_count)) {
38241
38242 vio_disable_interrupts(hvcsd->vdev);
38243
38244 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38245 free_irq(irq, hvcsd);
38246 kref_put(&hvcsd->kref, destroy_hvcs_struct);
38247 return;
38248 - } else if (hvcsd->open_count < 0) {
38249 + } else if (local_read(&hvcsd->open_count) < 0) {
38250 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38251 " is missmanaged.\n",
38252 - hvcsd->vdev->unit_address, hvcsd->open_count);
38253 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
38254 }
38255
38256 spin_unlock_irqrestore(&hvcsd->lock, flags);
38257 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38258
38259 spin_lock_irqsave(&hvcsd->lock, flags);
38260 /* Preserve this so that we know how many kref refs to put */
38261 - temp_open_count = hvcsd->open_count;
38262 + temp_open_count = local_read(&hvcsd->open_count);
38263
38264 /*
38265 * Don't kref put inside the spinlock because the destruction
38266 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38267 hvcsd->tty->driver_data = NULL;
38268 hvcsd->tty = NULL;
38269
38270 - hvcsd->open_count = 0;
38271 + local_set(&hvcsd->open_count, 0);
38272
38273 /* This will drop any buffered data on the floor which is OK in a hangup
38274 * scenario. */
38275 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
38276 * the middle of a write operation? This is a crummy place to do this
38277 * but we want to keep it all in the spinlock.
38278 */
38279 - if (hvcsd->open_count <= 0) {
38280 + if (local_read(&hvcsd->open_count) <= 0) {
38281 spin_unlock_irqrestore(&hvcsd->lock, flags);
38282 return -ENODEV;
38283 }
38284 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38285 {
38286 struct hvcs_struct *hvcsd = tty->driver_data;
38287
38288 - if (!hvcsd || hvcsd->open_count <= 0)
38289 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
38290 return 0;
38291
38292 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38293 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38294 index ef92869..f4ebd88 100644
38295 --- a/drivers/tty/ipwireless/tty.c
38296 +++ b/drivers/tty/ipwireless/tty.c
38297 @@ -29,6 +29,7 @@
38298 #include <linux/tty_driver.h>
38299 #include <linux/tty_flip.h>
38300 #include <linux/uaccess.h>
38301 +#include <asm/local.h>
38302
38303 #include "tty.h"
38304 #include "network.h"
38305 @@ -51,7 +52,7 @@ struct ipw_tty {
38306 int tty_type;
38307 struct ipw_network *network;
38308 struct tty_struct *linux_tty;
38309 - int open_count;
38310 + local_t open_count;
38311 unsigned int control_lines;
38312 struct mutex ipw_tty_mutex;
38313 int tx_bytes_queued;
38314 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38315 mutex_unlock(&tty->ipw_tty_mutex);
38316 return -ENODEV;
38317 }
38318 - if (tty->open_count == 0)
38319 + if (local_read(&tty->open_count) == 0)
38320 tty->tx_bytes_queued = 0;
38321
38322 - tty->open_count++;
38323 + local_inc(&tty->open_count);
38324
38325 tty->linux_tty = linux_tty;
38326 linux_tty->driver_data = tty;
38327 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38328
38329 static void do_ipw_close(struct ipw_tty *tty)
38330 {
38331 - tty->open_count--;
38332 -
38333 - if (tty->open_count == 0) {
38334 + if (local_dec_return(&tty->open_count) == 0) {
38335 struct tty_struct *linux_tty = tty->linux_tty;
38336
38337 if (linux_tty != NULL) {
38338 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38339 return;
38340
38341 mutex_lock(&tty->ipw_tty_mutex);
38342 - if (tty->open_count == 0) {
38343 + if (local_read(&tty->open_count) == 0) {
38344 mutex_unlock(&tty->ipw_tty_mutex);
38345 return;
38346 }
38347 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38348 return;
38349 }
38350
38351 - if (!tty->open_count) {
38352 + if (!local_read(&tty->open_count)) {
38353 mutex_unlock(&tty->ipw_tty_mutex);
38354 return;
38355 }
38356 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38357 return -ENODEV;
38358
38359 mutex_lock(&tty->ipw_tty_mutex);
38360 - if (!tty->open_count) {
38361 + if (!local_read(&tty->open_count)) {
38362 mutex_unlock(&tty->ipw_tty_mutex);
38363 return -EINVAL;
38364 }
38365 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38366 if (!tty)
38367 return -ENODEV;
38368
38369 - if (!tty->open_count)
38370 + if (!local_read(&tty->open_count))
38371 return -EINVAL;
38372
38373 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38374 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38375 if (!tty)
38376 return 0;
38377
38378 - if (!tty->open_count)
38379 + if (!local_read(&tty->open_count))
38380 return 0;
38381
38382 return tty->tx_bytes_queued;
38383 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38384 if (!tty)
38385 return -ENODEV;
38386
38387 - if (!tty->open_count)
38388 + if (!local_read(&tty->open_count))
38389 return -EINVAL;
38390
38391 return get_control_lines(tty);
38392 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38393 if (!tty)
38394 return -ENODEV;
38395
38396 - if (!tty->open_count)
38397 + if (!local_read(&tty->open_count))
38398 return -EINVAL;
38399
38400 return set_control_lines(tty, set, clear);
38401 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38402 if (!tty)
38403 return -ENODEV;
38404
38405 - if (!tty->open_count)
38406 + if (!local_read(&tty->open_count))
38407 return -EINVAL;
38408
38409 /* FIXME: Exactly how is the tty object locked here .. */
38410 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38411 against a parallel ioctl etc */
38412 mutex_lock(&ttyj->ipw_tty_mutex);
38413 }
38414 - while (ttyj->open_count)
38415 + while (local_read(&ttyj->open_count))
38416 do_ipw_close(ttyj);
38417 ipwireless_disassociate_network_ttys(network,
38418 ttyj->channel_idx);
38419 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38420 index fc7bbba..9527e93 100644
38421 --- a/drivers/tty/n_gsm.c
38422 +++ b/drivers/tty/n_gsm.c
38423 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38424 kref_init(&dlci->ref);
38425 mutex_init(&dlci->mutex);
38426 dlci->fifo = &dlci->_fifo;
38427 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38428 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38429 kfree(dlci);
38430 return NULL;
38431 }
38432 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38433 index d2256d0..97476fa 100644
38434 --- a/drivers/tty/n_tty.c
38435 +++ b/drivers/tty/n_tty.c
38436 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38437 {
38438 *ops = tty_ldisc_N_TTY;
38439 ops->owner = NULL;
38440 - ops->refcount = ops->flags = 0;
38441 + atomic_set(&ops->refcount, 0);
38442 + ops->flags = 0;
38443 }
38444 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38445 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38446 index d8653ab..f8afd9d 100644
38447 --- a/drivers/tty/pty.c
38448 +++ b/drivers/tty/pty.c
38449 @@ -765,8 +765,10 @@ static void __init unix98_pty_init(void)
38450 register_sysctl_table(pty_root_table);
38451
38452 /* Now create the /dev/ptmx special device */
38453 + pax_open_kernel();
38454 tty_default_fops(&ptmx_fops);
38455 - ptmx_fops.open = ptmx_open;
38456 + *(void **)&ptmx_fops.open = ptmx_open;
38457 + pax_close_kernel();
38458
38459 cdev_init(&ptmx_cdev, &ptmx_fops);
38460 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38461 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38462 index 2b42a01..32a2ed3 100644
38463 --- a/drivers/tty/serial/kgdboc.c
38464 +++ b/drivers/tty/serial/kgdboc.c
38465 @@ -24,8 +24,9 @@
38466 #define MAX_CONFIG_LEN 40
38467
38468 static struct kgdb_io kgdboc_io_ops;
38469 +static struct kgdb_io kgdboc_io_ops_console;
38470
38471 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38472 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38473 static int configured = -1;
38474
38475 static char config[MAX_CONFIG_LEN];
38476 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38477 kgdboc_unregister_kbd();
38478 if (configured == 1)
38479 kgdb_unregister_io_module(&kgdboc_io_ops);
38480 + else if (configured == 2)
38481 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38482 }
38483
38484 static int configure_kgdboc(void)
38485 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38486 int err;
38487 char *cptr = config;
38488 struct console *cons;
38489 + int is_console = 0;
38490
38491 err = kgdboc_option_setup(config);
38492 if (err || !strlen(config) || isspace(config[0]))
38493 goto noconfig;
38494
38495 err = -ENODEV;
38496 - kgdboc_io_ops.is_console = 0;
38497 kgdb_tty_driver = NULL;
38498
38499 kgdboc_use_kms = 0;
38500 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38501 int idx;
38502 if (cons->device && cons->device(cons, &idx) == p &&
38503 idx == tty_line) {
38504 - kgdboc_io_ops.is_console = 1;
38505 + is_console = 1;
38506 break;
38507 }
38508 cons = cons->next;
38509 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38510 kgdb_tty_line = tty_line;
38511
38512 do_register:
38513 - err = kgdb_register_io_module(&kgdboc_io_ops);
38514 + if (is_console) {
38515 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38516 + configured = 2;
38517 + } else {
38518 + err = kgdb_register_io_module(&kgdboc_io_ops);
38519 + configured = 1;
38520 + }
38521 if (err)
38522 goto noconfig;
38523
38524 - configured = 1;
38525 -
38526 return 0;
38527
38528 noconfig:
38529 @@ -213,7 +220,7 @@ noconfig:
38530 static int __init init_kgdboc(void)
38531 {
38532 /* Already configured? */
38533 - if (configured == 1)
38534 + if (configured >= 1)
38535 return 0;
38536
38537 return configure_kgdboc();
38538 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38539 if (config[len - 1] == '\n')
38540 config[len - 1] = '\0';
38541
38542 - if (configured == 1)
38543 + if (configured >= 1)
38544 cleanup_kgdboc();
38545
38546 /* Go and configure with the new params. */
38547 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38548 .post_exception = kgdboc_post_exp_handler,
38549 };
38550
38551 +static struct kgdb_io kgdboc_io_ops_console = {
38552 + .name = "kgdboc",
38553 + .read_char = kgdboc_get_char,
38554 + .write_char = kgdboc_put_char,
38555 + .pre_exception = kgdboc_pre_exp_handler,
38556 + .post_exception = kgdboc_post_exp_handler,
38557 + .is_console = 1
38558 +};
38559 +
38560 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38561 /* This is only available if kgdboc is a built in for early debugging */
38562 static int __init kgdboc_early_init(char *opt)
38563 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38564 index 7867b7c..b3c119d 100644
38565 --- a/drivers/tty/sysrq.c
38566 +++ b/drivers/tty/sysrq.c
38567 @@ -862,7 +862,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38568 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38569 size_t count, loff_t *ppos)
38570 {
38571 - if (count) {
38572 + if (count && capable(CAP_SYS_ADMIN)) {
38573 char c;
38574
38575 if (get_user(c, buf))
38576 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38577 index e41b9bb..84002fb 100644
38578 --- a/drivers/tty/tty_io.c
38579 +++ b/drivers/tty/tty_io.c
38580 @@ -3291,7 +3291,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38581
38582 void tty_default_fops(struct file_operations *fops)
38583 {
38584 - *fops = tty_fops;
38585 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38586 }
38587
38588 /*
38589 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38590 index 24b95db..9c078d0 100644
38591 --- a/drivers/tty/tty_ldisc.c
38592 +++ b/drivers/tty/tty_ldisc.c
38593 @@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38594 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38595 struct tty_ldisc_ops *ldo = ld->ops;
38596
38597 - ldo->refcount--;
38598 + atomic_dec(&ldo->refcount);
38599 module_put(ldo->owner);
38600 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38601
38602 @@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38603 spin_lock_irqsave(&tty_ldisc_lock, flags);
38604 tty_ldiscs[disc] = new_ldisc;
38605 new_ldisc->num = disc;
38606 - new_ldisc->refcount = 0;
38607 + atomic_set(&new_ldisc->refcount, 0);
38608 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38609
38610 return ret;
38611 @@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
38612 return -EINVAL;
38613
38614 spin_lock_irqsave(&tty_ldisc_lock, flags);
38615 - if (tty_ldiscs[disc]->refcount)
38616 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38617 ret = -EBUSY;
38618 else
38619 tty_ldiscs[disc] = NULL;
38620 @@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38621 if (ldops) {
38622 ret = ERR_PTR(-EAGAIN);
38623 if (try_module_get(ldops->owner)) {
38624 - ldops->refcount++;
38625 + atomic_inc(&ldops->refcount);
38626 ret = ldops;
38627 }
38628 }
38629 @@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38630 unsigned long flags;
38631
38632 spin_lock_irqsave(&tty_ldisc_lock, flags);
38633 - ldops->refcount--;
38634 + atomic_dec(&ldops->refcount);
38635 module_put(ldops->owner);
38636 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38637 }
38638 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38639 index a605549..6bd3c96 100644
38640 --- a/drivers/tty/vt/keyboard.c
38641 +++ b/drivers/tty/vt/keyboard.c
38642 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38643 kbd->kbdmode == VC_OFF) &&
38644 value != KVAL(K_SAK))
38645 return; /* SAK is allowed even in raw mode */
38646 +
38647 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38648 + {
38649 + void *func = fn_handler[value];
38650 + if (func == fn_show_state || func == fn_show_ptregs ||
38651 + func == fn_show_mem)
38652 + return;
38653 + }
38654 +#endif
38655 +
38656 fn_handler[value](vc);
38657 }
38658
38659 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
38660 index 65447c5..0526f0a 100644
38661 --- a/drivers/tty/vt/vt_ioctl.c
38662 +++ b/drivers/tty/vt/vt_ioctl.c
38663 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38664 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38665 return -EFAULT;
38666
38667 - if (!capable(CAP_SYS_TTY_CONFIG))
38668 - perm = 0;
38669 -
38670 switch (cmd) {
38671 case KDGKBENT:
38672 key_map = key_maps[s];
38673 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38674 val = (i ? K_HOLE : K_NOSUCHMAP);
38675 return put_user(val, &user_kbe->kb_value);
38676 case KDSKBENT:
38677 + if (!capable(CAP_SYS_TTY_CONFIG))
38678 + perm = 0;
38679 +
38680 if (!perm)
38681 return -EPERM;
38682 if (!i && v == K_NOSUCHMAP) {
38683 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38684 int i, j, k;
38685 int ret;
38686
38687 - if (!capable(CAP_SYS_TTY_CONFIG))
38688 - perm = 0;
38689 -
38690 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38691 if (!kbs) {
38692 ret = -ENOMEM;
38693 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38694 kfree(kbs);
38695 return ((p && *p) ? -EOVERFLOW : 0);
38696 case KDSKBSENT:
38697 + if (!capable(CAP_SYS_TTY_CONFIG))
38698 + perm = 0;
38699 +
38700 if (!perm) {
38701 ret = -EPERM;
38702 goto reterr;
38703 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38704 index a783d53..cb30d94 100644
38705 --- a/drivers/uio/uio.c
38706 +++ b/drivers/uio/uio.c
38707 @@ -25,6 +25,7 @@
38708 #include <linux/kobject.h>
38709 #include <linux/cdev.h>
38710 #include <linux/uio_driver.h>
38711 +#include <asm/local.h>
38712
38713 #define UIO_MAX_DEVICES (1U << MINORBITS)
38714
38715 @@ -32,10 +33,10 @@ struct uio_device {
38716 struct module *owner;
38717 struct device *dev;
38718 int minor;
38719 - atomic_t event;
38720 + atomic_unchecked_t event;
38721 struct fasync_struct *async_queue;
38722 wait_queue_head_t wait;
38723 - int vma_count;
38724 + local_t vma_count;
38725 struct uio_info *info;
38726 struct kobject *map_dir;
38727 struct kobject *portio_dir;
38728 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38729 struct device_attribute *attr, char *buf)
38730 {
38731 struct uio_device *idev = dev_get_drvdata(dev);
38732 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38733 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38734 }
38735
38736 static struct device_attribute uio_class_attributes[] = {
38737 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38738 {
38739 struct uio_device *idev = info->uio_dev;
38740
38741 - atomic_inc(&idev->event);
38742 + atomic_inc_unchecked(&idev->event);
38743 wake_up_interruptible(&idev->wait);
38744 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38745 }
38746 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38747 }
38748
38749 listener->dev = idev;
38750 - listener->event_count = atomic_read(&idev->event);
38751 + listener->event_count = atomic_read_unchecked(&idev->event);
38752 filep->private_data = listener;
38753
38754 if (idev->info->open) {
38755 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38756 return -EIO;
38757
38758 poll_wait(filep, &idev->wait, wait);
38759 - if (listener->event_count != atomic_read(&idev->event))
38760 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38761 return POLLIN | POLLRDNORM;
38762 return 0;
38763 }
38764 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38765 do {
38766 set_current_state(TASK_INTERRUPTIBLE);
38767
38768 - event_count = atomic_read(&idev->event);
38769 + event_count = atomic_read_unchecked(&idev->event);
38770 if (event_count != listener->event_count) {
38771 if (copy_to_user(buf, &event_count, count))
38772 retval = -EFAULT;
38773 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38774 static void uio_vma_open(struct vm_area_struct *vma)
38775 {
38776 struct uio_device *idev = vma->vm_private_data;
38777 - idev->vma_count++;
38778 + local_inc(&idev->vma_count);
38779 }
38780
38781 static void uio_vma_close(struct vm_area_struct *vma)
38782 {
38783 struct uio_device *idev = vma->vm_private_data;
38784 - idev->vma_count--;
38785 + local_dec(&idev->vma_count);
38786 }
38787
38788 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38789 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38790 idev->owner = owner;
38791 idev->info = info;
38792 init_waitqueue_head(&idev->wait);
38793 - atomic_set(&idev->event, 0);
38794 + atomic_set_unchecked(&idev->event, 0);
38795
38796 ret = uio_get_minor(idev);
38797 if (ret)
38798 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38799 index 98b89fe..aff824e 100644
38800 --- a/drivers/usb/atm/cxacru.c
38801 +++ b/drivers/usb/atm/cxacru.c
38802 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38803 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38804 if (ret < 2)
38805 return -EINVAL;
38806 - if (index < 0 || index > 0x7f)
38807 + if (index > 0x7f)
38808 return -EINVAL;
38809 pos += tmp;
38810
38811 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38812 index d3448ca..d2864ca 100644
38813 --- a/drivers/usb/atm/usbatm.c
38814 +++ b/drivers/usb/atm/usbatm.c
38815 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38816 if (printk_ratelimit())
38817 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38818 __func__, vpi, vci);
38819 - atomic_inc(&vcc->stats->rx_err);
38820 + atomic_inc_unchecked(&vcc->stats->rx_err);
38821 return;
38822 }
38823
38824 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38825 if (length > ATM_MAX_AAL5_PDU) {
38826 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38827 __func__, length, vcc);
38828 - atomic_inc(&vcc->stats->rx_err);
38829 + atomic_inc_unchecked(&vcc->stats->rx_err);
38830 goto out;
38831 }
38832
38833 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38834 if (sarb->len < pdu_length) {
38835 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38836 __func__, pdu_length, sarb->len, vcc);
38837 - atomic_inc(&vcc->stats->rx_err);
38838 + atomic_inc_unchecked(&vcc->stats->rx_err);
38839 goto out;
38840 }
38841
38842 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38843 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38844 __func__, vcc);
38845 - atomic_inc(&vcc->stats->rx_err);
38846 + atomic_inc_unchecked(&vcc->stats->rx_err);
38847 goto out;
38848 }
38849
38850 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38851 if (printk_ratelimit())
38852 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38853 __func__, length);
38854 - atomic_inc(&vcc->stats->rx_drop);
38855 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38856 goto out;
38857 }
38858
38859 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38860
38861 vcc->push(vcc, skb);
38862
38863 - atomic_inc(&vcc->stats->rx);
38864 + atomic_inc_unchecked(&vcc->stats->rx);
38865 out:
38866 skb_trim(sarb, 0);
38867 }
38868 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38869 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38870
38871 usbatm_pop(vcc, skb);
38872 - atomic_inc(&vcc->stats->tx);
38873 + atomic_inc_unchecked(&vcc->stats->tx);
38874
38875 skb = skb_dequeue(&instance->sndqueue);
38876 }
38877 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38878 if (!left--)
38879 return sprintf(page,
38880 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38881 - atomic_read(&atm_dev->stats.aal5.tx),
38882 - atomic_read(&atm_dev->stats.aal5.tx_err),
38883 - atomic_read(&atm_dev->stats.aal5.rx),
38884 - atomic_read(&atm_dev->stats.aal5.rx_err),
38885 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38886 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38887 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38888 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38889 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38890 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38891
38892 if (!left--) {
38893 if (instance->disconnected)
38894 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38895 index d956965..4179a77 100644
38896 --- a/drivers/usb/core/devices.c
38897 +++ b/drivers/usb/core/devices.c
38898 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38899 * time it gets called.
38900 */
38901 static struct device_connect_event {
38902 - atomic_t count;
38903 + atomic_unchecked_t count;
38904 wait_queue_head_t wait;
38905 } device_event = {
38906 .count = ATOMIC_INIT(1),
38907 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38908
38909 void usbfs_conn_disc_event(void)
38910 {
38911 - atomic_add(2, &device_event.count);
38912 + atomic_add_unchecked(2, &device_event.count);
38913 wake_up(&device_event.wait);
38914 }
38915
38916 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38917
38918 poll_wait(file, &device_event.wait, wait);
38919
38920 - event_count = atomic_read(&device_event.count);
38921 + event_count = atomic_read_unchecked(&device_event.count);
38922 if (file->f_version != event_count) {
38923 file->f_version = event_count;
38924 return POLLIN | POLLRDNORM;
38925 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38926 index 1fc8f12..20647c1 100644
38927 --- a/drivers/usb/early/ehci-dbgp.c
38928 +++ b/drivers/usb/early/ehci-dbgp.c
38929 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38930
38931 #ifdef CONFIG_KGDB
38932 static struct kgdb_io kgdbdbgp_io_ops;
38933 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38934 +static struct kgdb_io kgdbdbgp_io_ops_console;
38935 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38936 #else
38937 #define dbgp_kgdb_mode (0)
38938 #endif
38939 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38940 .write_char = kgdbdbgp_write_char,
38941 };
38942
38943 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38944 + .name = "kgdbdbgp",
38945 + .read_char = kgdbdbgp_read_char,
38946 + .write_char = kgdbdbgp_write_char,
38947 + .is_console = 1
38948 +};
38949 +
38950 static int kgdbdbgp_wait_time;
38951
38952 static int __init kgdbdbgp_parse_config(char *str)
38953 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38954 ptr++;
38955 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38956 }
38957 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38958 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38959 + if (early_dbgp_console.index != -1)
38960 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38961 + else
38962 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38963
38964 return 0;
38965 }
38966 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38967 index d6bea3e..60b250e 100644
38968 --- a/drivers/usb/wusbcore/wa-hc.h
38969 +++ b/drivers/usb/wusbcore/wa-hc.h
38970 @@ -192,7 +192,7 @@ struct wahc {
38971 struct list_head xfer_delayed_list;
38972 spinlock_t xfer_list_lock;
38973 struct work_struct xfer_work;
38974 - atomic_t xfer_id_count;
38975 + atomic_unchecked_t xfer_id_count;
38976 };
38977
38978
38979 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38980 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38981 spin_lock_init(&wa->xfer_list_lock);
38982 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38983 - atomic_set(&wa->xfer_id_count, 1);
38984 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38985 }
38986
38987 /**
38988 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38989 index 57c01ab..8a05959 100644
38990 --- a/drivers/usb/wusbcore/wa-xfer.c
38991 +++ b/drivers/usb/wusbcore/wa-xfer.c
38992 @@ -296,7 +296,7 @@ out:
38993 */
38994 static void wa_xfer_id_init(struct wa_xfer *xfer)
38995 {
38996 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38997 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38998 }
38999
39000 /*
39001 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39002 index c14c42b..f955cc2 100644
39003 --- a/drivers/vhost/vhost.c
39004 +++ b/drivers/vhost/vhost.c
39005 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39006 return 0;
39007 }
39008
39009 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39010 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39011 {
39012 struct file *eventfp, *filep = NULL,
39013 *pollstart = NULL, *pollstop = NULL;
39014 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39015 index b0b2ac3..89a4399 100644
39016 --- a/drivers/video/aty/aty128fb.c
39017 +++ b/drivers/video/aty/aty128fb.c
39018 @@ -148,7 +148,7 @@ enum {
39019 };
39020
39021 /* Must match above enum */
39022 -static const char *r128_family[] __devinitdata = {
39023 +static const char *r128_family[] __devinitconst = {
39024 "AGP",
39025 "PCI",
39026 "PRO AGP",
39027 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39028 index 5c3960d..15cf8fc 100644
39029 --- a/drivers/video/fbcmap.c
39030 +++ b/drivers/video/fbcmap.c
39031 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39032 rc = -ENODEV;
39033 goto out;
39034 }
39035 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39036 - !info->fbops->fb_setcmap)) {
39037 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39038 rc = -EINVAL;
39039 goto out1;
39040 }
39041 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39042 index c6ce416..3b9b642 100644
39043 --- a/drivers/video/fbmem.c
39044 +++ b/drivers/video/fbmem.c
39045 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39046 image->dx += image->width + 8;
39047 }
39048 } else if (rotate == FB_ROTATE_UD) {
39049 - for (x = 0; x < num && image->dx >= 0; x++) {
39050 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39051 info->fbops->fb_imageblit(info, image);
39052 image->dx -= image->width + 8;
39053 }
39054 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39055 image->dy += image->height + 8;
39056 }
39057 } else if (rotate == FB_ROTATE_CCW) {
39058 - for (x = 0; x < num && image->dy >= 0; x++) {
39059 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39060 info->fbops->fb_imageblit(info, image);
39061 image->dy -= image->height + 8;
39062 }
39063 @@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39064 return -EFAULT;
39065 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39066 return -EINVAL;
39067 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39068 + if (con2fb.framebuffer >= FB_MAX)
39069 return -EINVAL;
39070 if (!registered_fb[con2fb.framebuffer])
39071 request_module("fb%d", con2fb.framebuffer);
39072 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39073 index 5a5d092..265c5ed 100644
39074 --- a/drivers/video/geode/gx1fb_core.c
39075 +++ b/drivers/video/geode/gx1fb_core.c
39076 @@ -29,7 +29,7 @@ static int crt_option = 1;
39077 static char panel_option[32] = "";
39078
39079 /* Modes relevant to the GX1 (taken from modedb.c) */
39080 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39081 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39082 /* 640x480-60 VESA */
39083 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39084 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39085 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39086 index 0fad23f..0e9afa4 100644
39087 --- a/drivers/video/gxt4500.c
39088 +++ b/drivers/video/gxt4500.c
39089 @@ -156,7 +156,7 @@ struct gxt4500_par {
39090 static char *mode_option;
39091
39092 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39093 -static const struct fb_videomode defaultmode __devinitdata = {
39094 +static const struct fb_videomode defaultmode __devinitconst = {
39095 .refresh = 60,
39096 .xres = 1280,
39097 .yres = 1024,
39098 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39099 return 0;
39100 }
39101
39102 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39103 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39104 .id = "IBM GXT4500P",
39105 .type = FB_TYPE_PACKED_PIXELS,
39106 .visual = FB_VISUAL_PSEUDOCOLOR,
39107 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39108 index 7672d2e..b56437f 100644
39109 --- a/drivers/video/i810/i810_accel.c
39110 +++ b/drivers/video/i810/i810_accel.c
39111 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39112 }
39113 }
39114 printk("ringbuffer lockup!!!\n");
39115 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39116 i810_report_error(mmio);
39117 par->dev_flags |= LOCKUP;
39118 info->pixmap.scan_align = 1;
39119 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39120 index b83f361..2b05a91 100644
39121 --- a/drivers/video/i810/i810_main.c
39122 +++ b/drivers/video/i810/i810_main.c
39123 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39124 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39125
39126 /* PCI */
39127 -static const char *i810_pci_list[] __devinitdata = {
39128 +static const char *i810_pci_list[] __devinitconst = {
39129 "Intel(R) 810 Framebuffer Device" ,
39130 "Intel(R) 810-DC100 Framebuffer Device" ,
39131 "Intel(R) 810E Framebuffer Device" ,
39132 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39133 index de36693..3c63fc2 100644
39134 --- a/drivers/video/jz4740_fb.c
39135 +++ b/drivers/video/jz4740_fb.c
39136 @@ -136,7 +136,7 @@ struct jzfb {
39137 uint32_t pseudo_palette[16];
39138 };
39139
39140 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39141 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39142 .id = "JZ4740 FB",
39143 .type = FB_TYPE_PACKED_PIXELS,
39144 .visual = FB_VISUAL_TRUECOLOR,
39145 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39146 index 3c14e43..eafa544 100644
39147 --- a/drivers/video/logo/logo_linux_clut224.ppm
39148 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39149 @@ -1,1604 +1,1123 @@
39150 P3
39151 -# Standard 224-color Linux logo
39152 80 80
39153 255
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 0 0 0
39163 - 6 6 6 6 6 6 10 10 10 10 10 10
39164 - 10 10 10 6 6 6 6 6 6 6 6 6
39165 - 0 0 0 0 0 0 0 0 0 0 0 0
39166 - 0 0 0 0 0 0 0 0 0 0 0 0
39167 - 0 0 0 0 0 0 0 0 0 0 0 0
39168 - 0 0 0 0 0 0 0 0 0 0 0 0
39169 - 0 0 0 0 0 0 0 0 0 0 0 0
39170 - 0 0 0 0 0 0 0 0 0 0 0 0
39171 - 0 0 0 0 0 0 0 0 0 0 0 0
39172 - 0 0 0 0 0 0 0 0 0 0 0 0
39173 - 0 0 0 0 0 0 0 0 0 0 0 0
39174 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0
39177 - 0 0 0 0 0 0 0 0 0 0 0 0
39178 - 0 0 0 0 0 0 0 0 0 0 0 0
39179 - 0 0 0 0 0 0 0 0 0 0 0 0
39180 - 0 0 0 0 0 0 0 0 0 0 0 0
39181 - 0 0 0 0 0 0 0 0 0 0 0 0
39182 - 0 0 0 6 6 6 10 10 10 14 14 14
39183 - 22 22 22 26 26 26 30 30 30 34 34 34
39184 - 30 30 30 30 30 30 26 26 26 18 18 18
39185 - 14 14 14 10 10 10 6 6 6 0 0 0
39186 - 0 0 0 0 0 0 0 0 0 0 0 0
39187 - 0 0 0 0 0 0 0 0 0 0 0 0
39188 - 0 0 0 0 0 0 0 0 0 0 0 0
39189 - 0 0 0 0 0 0 0 0 0 0 0 0
39190 - 0 0 0 0 0 0 0 0 0 0 0 0
39191 - 0 0 0 0 0 0 0 0 0 0 0 0
39192 - 0 0 0 0 0 0 0 0 0 0 0 0
39193 - 0 0 0 0 0 0 0 0 0 0 0 0
39194 - 0 0 0 0 0 0 0 0 0 0 0 0
39195 - 0 0 0 0 0 1 0 0 1 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 - 6 6 6 14 14 14 26 26 26 42 42 42
39203 - 54 54 54 66 66 66 78 78 78 78 78 78
39204 - 78 78 78 74 74 74 66 66 66 54 54 54
39205 - 42 42 42 26 26 26 18 18 18 10 10 10
39206 - 6 6 6 0 0 0 0 0 0 0 0 0
39207 - 0 0 0 0 0 0 0 0 0 0 0 0
39208 - 0 0 0 0 0 0 0 0 0 0 0 0
39209 - 0 0 0 0 0 0 0 0 0 0 0 0
39210 - 0 0 0 0 0 0 0 0 0 0 0 0
39211 - 0 0 0 0 0 0 0 0 0 0 0 0
39212 - 0 0 0 0 0 0 0 0 0 0 0 0
39213 - 0 0 0 0 0 0 0 0 0 0 0 0
39214 - 0 0 0 0 0 0 0 0 0 0 0 0
39215 - 0 0 1 0 0 0 0 0 0 0 0 0
39216 - 0 0 0 0 0 0 0 0 0 0 0 0
39217 - 0 0 0 0 0 0 0 0 0 0 0 0
39218 - 0 0 0 0 0 0 0 0 0 0 0 0
39219 - 0 0 0 0 0 0 0 0 0 0 0 0
39220 - 0 0 0 0 0 0 0 0 0 0 0 0
39221 - 0 0 0 0 0 0 0 0 0 10 10 10
39222 - 22 22 22 42 42 42 66 66 66 86 86 86
39223 - 66 66 66 38 38 38 38 38 38 22 22 22
39224 - 26 26 26 34 34 34 54 54 54 66 66 66
39225 - 86 86 86 70 70 70 46 46 46 26 26 26
39226 - 14 14 14 6 6 6 0 0 0 0 0 0
39227 - 0 0 0 0 0 0 0 0 0 0 0 0
39228 - 0 0 0 0 0 0 0 0 0 0 0 0
39229 - 0 0 0 0 0 0 0 0 0 0 0 0
39230 - 0 0 0 0 0 0 0 0 0 0 0 0
39231 - 0 0 0 0 0 0 0 0 0 0 0 0
39232 - 0 0 0 0 0 0 0 0 0 0 0 0
39233 - 0 0 0 0 0 0 0 0 0 0 0 0
39234 - 0 0 0 0 0 0 0 0 0 0 0 0
39235 - 0 0 1 0 0 1 0 0 1 0 0 0
39236 - 0 0 0 0 0 0 0 0 0 0 0 0
39237 - 0 0 0 0 0 0 0 0 0 0 0 0
39238 - 0 0 0 0 0 0 0 0 0 0 0 0
39239 - 0 0 0 0 0 0 0 0 0 0 0 0
39240 - 0 0 0 0 0 0 0 0 0 0 0 0
39241 - 0 0 0 0 0 0 10 10 10 26 26 26
39242 - 50 50 50 82 82 82 58 58 58 6 6 6
39243 - 2 2 6 2 2 6 2 2 6 2 2 6
39244 - 2 2 6 2 2 6 2 2 6 2 2 6
39245 - 6 6 6 54 54 54 86 86 86 66 66 66
39246 - 38 38 38 18 18 18 6 6 6 0 0 0
39247 - 0 0 0 0 0 0 0 0 0 0 0 0
39248 - 0 0 0 0 0 0 0 0 0 0 0 0
39249 - 0 0 0 0 0 0 0 0 0 0 0 0
39250 - 0 0 0 0 0 0 0 0 0 0 0 0
39251 - 0 0 0 0 0 0 0 0 0 0 0 0
39252 - 0 0 0 0 0 0 0 0 0 0 0 0
39253 - 0 0 0 0 0 0 0 0 0 0 0 0
39254 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0
39257 - 0 0 0 0 0 0 0 0 0 0 0 0
39258 - 0 0 0 0 0 0 0 0 0 0 0 0
39259 - 0 0 0 0 0 0 0 0 0 0 0 0
39260 - 0 0 0 0 0 0 0 0 0 0 0 0
39261 - 0 0 0 6 6 6 22 22 22 50 50 50
39262 - 78 78 78 34 34 34 2 2 6 2 2 6
39263 - 2 2 6 2 2 6 2 2 6 2 2 6
39264 - 2 2 6 2 2 6 2 2 6 2 2 6
39265 - 2 2 6 2 2 6 6 6 6 70 70 70
39266 - 78 78 78 46 46 46 22 22 22 6 6 6
39267 - 0 0 0 0 0 0 0 0 0 0 0 0
39268 - 0 0 0 0 0 0 0 0 0 0 0 0
39269 - 0 0 0 0 0 0 0 0 0 0 0 0
39270 - 0 0 0 0 0 0 0 0 0 0 0 0
39271 - 0 0 0 0 0 0 0 0 0 0 0 0
39272 - 0 0 0 0 0 0 0 0 0 0 0 0
39273 - 0 0 0 0 0 0 0 0 0 0 0 0
39274 - 0 0 0 0 0 0 0 0 0 0 0 0
39275 - 0 0 1 0 0 1 0 0 1 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 - 6 6 6 18 18 18 42 42 42 82 82 82
39282 - 26 26 26 2 2 6 2 2 6 2 2 6
39283 - 2 2 6 2 2 6 2 2 6 2 2 6
39284 - 2 2 6 2 2 6 2 2 6 14 14 14
39285 - 46 46 46 34 34 34 6 6 6 2 2 6
39286 - 42 42 42 78 78 78 42 42 42 18 18 18
39287 - 6 6 6 0 0 0 0 0 0 0 0 0
39288 - 0 0 0 0 0 0 0 0 0 0 0 0
39289 - 0 0 0 0 0 0 0 0 0 0 0 0
39290 - 0 0 0 0 0 0 0 0 0 0 0 0
39291 - 0 0 0 0 0 0 0 0 0 0 0 0
39292 - 0 0 0 0 0 0 0 0 0 0 0 0
39293 - 0 0 0 0 0 0 0 0 0 0 0 0
39294 - 0 0 0 0 0 0 0 0 0 0 0 0
39295 - 0 0 1 0 0 0 0 0 1 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 - 10 10 10 30 30 30 66 66 66 58 58 58
39302 - 2 2 6 2 2 6 2 2 6 2 2 6
39303 - 2 2 6 2 2 6 2 2 6 2 2 6
39304 - 2 2 6 2 2 6 2 2 6 26 26 26
39305 - 86 86 86 101 101 101 46 46 46 10 10 10
39306 - 2 2 6 58 58 58 70 70 70 34 34 34
39307 - 10 10 10 0 0 0 0 0 0 0 0 0
39308 - 0 0 0 0 0 0 0 0 0 0 0 0
39309 - 0 0 0 0 0 0 0 0 0 0 0 0
39310 - 0 0 0 0 0 0 0 0 0 0 0 0
39311 - 0 0 0 0 0 0 0 0 0 0 0 0
39312 - 0 0 0 0 0 0 0 0 0 0 0 0
39313 - 0 0 0 0 0 0 0 0 0 0 0 0
39314 - 0 0 0 0 0 0 0 0 0 0 0 0
39315 - 0 0 1 0 0 1 0 0 1 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 - 14 14 14 42 42 42 86 86 86 10 10 10
39322 - 2 2 6 2 2 6 2 2 6 2 2 6
39323 - 2 2 6 2 2 6 2 2 6 2 2 6
39324 - 2 2 6 2 2 6 2 2 6 30 30 30
39325 - 94 94 94 94 94 94 58 58 58 26 26 26
39326 - 2 2 6 6 6 6 78 78 78 54 54 54
39327 - 22 22 22 6 6 6 0 0 0 0 0 0
39328 - 0 0 0 0 0 0 0 0 0 0 0 0
39329 - 0 0 0 0 0 0 0 0 0 0 0 0
39330 - 0 0 0 0 0 0 0 0 0 0 0 0
39331 - 0 0 0 0 0 0 0 0 0 0 0 0
39332 - 0 0 0 0 0 0 0 0 0 0 0 0
39333 - 0 0 0 0 0 0 0 0 0 0 0 0
39334 - 0 0 0 0 0 0 0 0 0 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 6 6 6
39341 - 22 22 22 62 62 62 62 62 62 2 2 6
39342 - 2 2 6 2 2 6 2 2 6 2 2 6
39343 - 2 2 6 2 2 6 2 2 6 2 2 6
39344 - 2 2 6 2 2 6 2 2 6 26 26 26
39345 - 54 54 54 38 38 38 18 18 18 10 10 10
39346 - 2 2 6 2 2 6 34 34 34 82 82 82
39347 - 38 38 38 14 14 14 0 0 0 0 0 0
39348 - 0 0 0 0 0 0 0 0 0 0 0 0
39349 - 0 0 0 0 0 0 0 0 0 0 0 0
39350 - 0 0 0 0 0 0 0 0 0 0 0 0
39351 - 0 0 0 0 0 0 0 0 0 0 0 0
39352 - 0 0 0 0 0 0 0 0 0 0 0 0
39353 - 0 0 0 0 0 0 0 0 0 0 0 0
39354 - 0 0 0 0 0 0 0 0 0 0 0 0
39355 - 0 0 0 0 0 1 0 0 1 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 6 6 6
39361 - 30 30 30 78 78 78 30 30 30 2 2 6
39362 - 2 2 6 2 2 6 2 2 6 2 2 6
39363 - 2 2 6 2 2 6 2 2 6 2 2 6
39364 - 2 2 6 2 2 6 2 2 6 10 10 10
39365 - 10 10 10 2 2 6 2 2 6 2 2 6
39366 - 2 2 6 2 2 6 2 2 6 78 78 78
39367 - 50 50 50 18 18 18 6 6 6 0 0 0
39368 - 0 0 0 0 0 0 0 0 0 0 0 0
39369 - 0 0 0 0 0 0 0 0 0 0 0 0
39370 - 0 0 0 0 0 0 0 0 0 0 0 0
39371 - 0 0 0 0 0 0 0 0 0 0 0 0
39372 - 0 0 0 0 0 0 0 0 0 0 0 0
39373 - 0 0 0 0 0 0 0 0 0 0 0 0
39374 - 0 0 0 0 0 0 0 0 0 0 0 0
39375 - 0 0 1 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 10 10 10
39381 - 38 38 38 86 86 86 14 14 14 2 2 6
39382 - 2 2 6 2 2 6 2 2 6 2 2 6
39383 - 2 2 6 2 2 6 2 2 6 2 2 6
39384 - 2 2 6 2 2 6 2 2 6 2 2 6
39385 - 2 2 6 2 2 6 2 2 6 2 2 6
39386 - 2 2 6 2 2 6 2 2 6 54 54 54
39387 - 66 66 66 26 26 26 6 6 6 0 0 0
39388 - 0 0 0 0 0 0 0 0 0 0 0 0
39389 - 0 0 0 0 0 0 0 0 0 0 0 0
39390 - 0 0 0 0 0 0 0 0 0 0 0 0
39391 - 0 0 0 0 0 0 0 0 0 0 0 0
39392 - 0 0 0 0 0 0 0 0 0 0 0 0
39393 - 0 0 0 0 0 0 0 0 0 0 0 0
39394 - 0 0 0 0 0 0 0 0 0 0 0 0
39395 - 0 0 0 0 0 1 0 0 1 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 14 14 14
39401 - 42 42 42 82 82 82 2 2 6 2 2 6
39402 - 2 2 6 6 6 6 10 10 10 2 2 6
39403 - 2 2 6 2 2 6 2 2 6 2 2 6
39404 - 2 2 6 2 2 6 2 2 6 6 6 6
39405 - 14 14 14 10 10 10 2 2 6 2 2 6
39406 - 2 2 6 2 2 6 2 2 6 18 18 18
39407 - 82 82 82 34 34 34 10 10 10 0 0 0
39408 - 0 0 0 0 0 0 0 0 0 0 0 0
39409 - 0 0 0 0 0 0 0 0 0 0 0 0
39410 - 0 0 0 0 0 0 0 0 0 0 0 0
39411 - 0 0 0 0 0 0 0 0 0 0 0 0
39412 - 0 0 0 0 0 0 0 0 0 0 0 0
39413 - 0 0 0 0 0 0 0 0 0 0 0 0
39414 - 0 0 0 0 0 0 0 0 0 0 0 0
39415 - 0 0 1 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 14 14 14
39421 - 46 46 46 86 86 86 2 2 6 2 2 6
39422 - 6 6 6 6 6 6 22 22 22 34 34 34
39423 - 6 6 6 2 2 6 2 2 6 2 2 6
39424 - 2 2 6 2 2 6 18 18 18 34 34 34
39425 - 10 10 10 50 50 50 22 22 22 2 2 6
39426 - 2 2 6 2 2 6 2 2 6 10 10 10
39427 - 86 86 86 42 42 42 14 14 14 0 0 0
39428 - 0 0 0 0 0 0 0 0 0 0 0 0
39429 - 0 0 0 0 0 0 0 0 0 0 0 0
39430 - 0 0 0 0 0 0 0 0 0 0 0 0
39431 - 0 0 0 0 0 0 0 0 0 0 0 0
39432 - 0 0 0 0 0 0 0 0 0 0 0 0
39433 - 0 0 0 0 0 0 0 0 0 0 0 0
39434 - 0 0 0 0 0 0 0 0 0 0 0 0
39435 - 0 0 1 0 0 1 0 0 1 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 14 14 14
39441 - 46 46 46 86 86 86 2 2 6 2 2 6
39442 - 38 38 38 116 116 116 94 94 94 22 22 22
39443 - 22 22 22 2 2 6 2 2 6 2 2 6
39444 - 14 14 14 86 86 86 138 138 138 162 162 162
39445 -154 154 154 38 38 38 26 26 26 6 6 6
39446 - 2 2 6 2 2 6 2 2 6 2 2 6
39447 - 86 86 86 46 46 46 14 14 14 0 0 0
39448 - 0 0 0 0 0 0 0 0 0 0 0 0
39449 - 0 0 0 0 0 0 0 0 0 0 0 0
39450 - 0 0 0 0 0 0 0 0 0 0 0 0
39451 - 0 0 0 0 0 0 0 0 0 0 0 0
39452 - 0 0 0 0 0 0 0 0 0 0 0 0
39453 - 0 0 0 0 0 0 0 0 0 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 14 14 14
39461 - 46 46 46 86 86 86 2 2 6 14 14 14
39462 -134 134 134 198 198 198 195 195 195 116 116 116
39463 - 10 10 10 2 2 6 2 2 6 6 6 6
39464 -101 98 89 187 187 187 210 210 210 218 218 218
39465 -214 214 214 134 134 134 14 14 14 6 6 6
39466 - 2 2 6 2 2 6 2 2 6 2 2 6
39467 - 86 86 86 50 50 50 18 18 18 6 6 6
39468 - 0 0 0 0 0 0 0 0 0 0 0 0
39469 - 0 0 0 0 0 0 0 0 0 0 0 0
39470 - 0 0 0 0 0 0 0 0 0 0 0 0
39471 - 0 0 0 0 0 0 0 0 0 0 0 0
39472 - 0 0 0 0 0 0 0 0 0 0 0 0
39473 - 0 0 0 0 0 0 0 0 0 0 0 0
39474 - 0 0 0 0 0 0 0 0 1 0 0 0
39475 - 0 0 1 0 0 1 0 0 1 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 14 14 14
39481 - 46 46 46 86 86 86 2 2 6 54 54 54
39482 -218 218 218 195 195 195 226 226 226 246 246 246
39483 - 58 58 58 2 2 6 2 2 6 30 30 30
39484 -210 210 210 253 253 253 174 174 174 123 123 123
39485 -221 221 221 234 234 234 74 74 74 2 2 6
39486 - 2 2 6 2 2 6 2 2 6 2 2 6
39487 - 70 70 70 58 58 58 22 22 22 6 6 6
39488 - 0 0 0 0 0 0 0 0 0 0 0 0
39489 - 0 0 0 0 0 0 0 0 0 0 0 0
39490 - 0 0 0 0 0 0 0 0 0 0 0 0
39491 - 0 0 0 0 0 0 0 0 0 0 0 0
39492 - 0 0 0 0 0 0 0 0 0 0 0 0
39493 - 0 0 0 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 14 14 14
39501 - 46 46 46 82 82 82 2 2 6 106 106 106
39502 -170 170 170 26 26 26 86 86 86 226 226 226
39503 -123 123 123 10 10 10 14 14 14 46 46 46
39504 -231 231 231 190 190 190 6 6 6 70 70 70
39505 - 90 90 90 238 238 238 158 158 158 2 2 6
39506 - 2 2 6 2 2 6 2 2 6 2 2 6
39507 - 70 70 70 58 58 58 22 22 22 6 6 6
39508 - 0 0 0 0 0 0 0 0 0 0 0 0
39509 - 0 0 0 0 0 0 0 0 0 0 0 0
39510 - 0 0 0 0 0 0 0 0 0 0 0 0
39511 - 0 0 0 0 0 0 0 0 0 0 0 0
39512 - 0 0 0 0 0 0 0 0 0 0 0 0
39513 - 0 0 0 0 0 0 0 0 0 0 0 0
39514 - 0 0 0 0 0 0 0 0 1 0 0 0
39515 - 0 0 1 0 0 1 0 0 1 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 14 14 14
39521 - 42 42 42 86 86 86 6 6 6 116 116 116
39522 -106 106 106 6 6 6 70 70 70 149 149 149
39523 -128 128 128 18 18 18 38 38 38 54 54 54
39524 -221 221 221 106 106 106 2 2 6 14 14 14
39525 - 46 46 46 190 190 190 198 198 198 2 2 6
39526 - 2 2 6 2 2 6 2 2 6 2 2 6
39527 - 74 74 74 62 62 62 22 22 22 6 6 6
39528 - 0 0 0 0 0 0 0 0 0 0 0 0
39529 - 0 0 0 0 0 0 0 0 0 0 0 0
39530 - 0 0 0 0 0 0 0 0 0 0 0 0
39531 - 0 0 0 0 0 0 0 0 0 0 0 0
39532 - 0 0 0 0 0 0 0 0 0 0 0 0
39533 - 0 0 0 0 0 0 0 0 0 0 0 0
39534 - 0 0 0 0 0 0 0 0 1 0 0 0
39535 - 0 0 1 0 0 0 0 0 1 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 14 14 14
39541 - 42 42 42 94 94 94 14 14 14 101 101 101
39542 -128 128 128 2 2 6 18 18 18 116 116 116
39543 -118 98 46 121 92 8 121 92 8 98 78 10
39544 -162 162 162 106 106 106 2 2 6 2 2 6
39545 - 2 2 6 195 195 195 195 195 195 6 6 6
39546 - 2 2 6 2 2 6 2 2 6 2 2 6
39547 - 74 74 74 62 62 62 22 22 22 6 6 6
39548 - 0 0 0 0 0 0 0 0 0 0 0 0
39549 - 0 0 0 0 0 0 0 0 0 0 0 0
39550 - 0 0 0 0 0 0 0 0 0 0 0 0
39551 - 0 0 0 0 0 0 0 0 0 0 0 0
39552 - 0 0 0 0 0 0 0 0 0 0 0 0
39553 - 0 0 0 0 0 0 0 0 0 0 0 0
39554 - 0 0 0 0 0 0 0 0 1 0 0 1
39555 - 0 0 1 0 0 0 0 0 1 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 10 10 10
39561 - 38 38 38 90 90 90 14 14 14 58 58 58
39562 -210 210 210 26 26 26 54 38 6 154 114 10
39563 -226 170 11 236 186 11 225 175 15 184 144 12
39564 -215 174 15 175 146 61 37 26 9 2 2 6
39565 - 70 70 70 246 246 246 138 138 138 2 2 6
39566 - 2 2 6 2 2 6 2 2 6 2 2 6
39567 - 70 70 70 66 66 66 26 26 26 6 6 6
39568 - 0 0 0 0 0 0 0 0 0 0 0 0
39569 - 0 0 0 0 0 0 0 0 0 0 0 0
39570 - 0 0 0 0 0 0 0 0 0 0 0 0
39571 - 0 0 0 0 0 0 0 0 0 0 0 0
39572 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39581 - 38 38 38 86 86 86 14 14 14 10 10 10
39582 -195 195 195 188 164 115 192 133 9 225 175 15
39583 -239 182 13 234 190 10 232 195 16 232 200 30
39584 -245 207 45 241 208 19 232 195 16 184 144 12
39585 -218 194 134 211 206 186 42 42 42 2 2 6
39586 - 2 2 6 2 2 6 2 2 6 2 2 6
39587 - 50 50 50 74 74 74 30 30 30 6 6 6
39588 - 0 0 0 0 0 0 0 0 0 0 0 0
39589 - 0 0 0 0 0 0 0 0 0 0 0 0
39590 - 0 0 0 0 0 0 0 0 0 0 0 0
39591 - 0 0 0 0 0 0 0 0 0 0 0 0
39592 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39601 - 34 34 34 86 86 86 14 14 14 2 2 6
39602 -121 87 25 192 133 9 219 162 10 239 182 13
39603 -236 186 11 232 195 16 241 208 19 244 214 54
39604 -246 218 60 246 218 38 246 215 20 241 208 19
39605 -241 208 19 226 184 13 121 87 25 2 2 6
39606 - 2 2 6 2 2 6 2 2 6 2 2 6
39607 - 50 50 50 82 82 82 34 34 34 10 10 10
39608 - 0 0 0 0 0 0 0 0 0 0 0 0
39609 - 0 0 0 0 0 0 0 0 0 0 0 0
39610 - 0 0 0 0 0 0 0 0 0 0 0 0
39611 - 0 0 0 0 0 0 0 0 0 0 0 0
39612 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39621 - 34 34 34 82 82 82 30 30 30 61 42 6
39622 -180 123 7 206 145 10 230 174 11 239 182 13
39623 -234 190 10 238 202 15 241 208 19 246 218 74
39624 -246 218 38 246 215 20 246 215 20 246 215 20
39625 -226 184 13 215 174 15 184 144 12 6 6 6
39626 - 2 2 6 2 2 6 2 2 6 2 2 6
39627 - 26 26 26 94 94 94 42 42 42 14 14 14
39628 - 0 0 0 0 0 0 0 0 0 0 0 0
39629 - 0 0 0 0 0 0 0 0 0 0 0 0
39630 - 0 0 0 0 0 0 0 0 0 0 0 0
39631 - 0 0 0 0 0 0 0 0 0 0 0 0
39632 - 0 0 0 0 0 0 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 10 10 10
39641 - 30 30 30 78 78 78 50 50 50 104 69 6
39642 -192 133 9 216 158 10 236 178 12 236 186 11
39643 -232 195 16 241 208 19 244 214 54 245 215 43
39644 -246 215 20 246 215 20 241 208 19 198 155 10
39645 -200 144 11 216 158 10 156 118 10 2 2 6
39646 - 2 2 6 2 2 6 2 2 6 2 2 6
39647 - 6 6 6 90 90 90 54 54 54 18 18 18
39648 - 6 6 6 0 0 0 0 0 0 0 0 0
39649 - 0 0 0 0 0 0 0 0 0 0 0 0
39650 - 0 0 0 0 0 0 0 0 0 0 0 0
39651 - 0 0 0 0 0 0 0 0 0 0 0 0
39652 - 0 0 0 0 0 0 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 78 78 78 46 46 46 22 22 22
39662 -137 92 6 210 162 10 239 182 13 238 190 10
39663 -238 202 15 241 208 19 246 215 20 246 215 20
39664 -241 208 19 203 166 17 185 133 11 210 150 10
39665 -216 158 10 210 150 10 102 78 10 2 2 6
39666 - 6 6 6 54 54 54 14 14 14 2 2 6
39667 - 2 2 6 62 62 62 74 74 74 30 30 30
39668 - 10 10 10 0 0 0 0 0 0 0 0 0
39669 - 0 0 0 0 0 0 0 0 0 0 0 0
39670 - 0 0 0 0 0 0 0 0 0 0 0 0
39671 - 0 0 0 0 0 0 0 0 0 0 0 0
39672 - 0 0 0 0 0 0 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 10 10 10
39681 - 34 34 34 78 78 78 50 50 50 6 6 6
39682 - 94 70 30 139 102 15 190 146 13 226 184 13
39683 -232 200 30 232 195 16 215 174 15 190 146 13
39684 -168 122 10 192 133 9 210 150 10 213 154 11
39685 -202 150 34 182 157 106 101 98 89 2 2 6
39686 - 2 2 6 78 78 78 116 116 116 58 58 58
39687 - 2 2 6 22 22 22 90 90 90 46 46 46
39688 - 18 18 18 6 6 6 0 0 0 0 0 0
39689 - 0 0 0 0 0 0 0 0 0 0 0 0
39690 - 0 0 0 0 0 0 0 0 0 0 0 0
39691 - 0 0 0 0 0 0 0 0 0 0 0 0
39692 - 0 0 0 0 0 0 0 0 0 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 0 0 0 10 10 10
39701 - 38 38 38 86 86 86 50 50 50 6 6 6
39702 -128 128 128 174 154 114 156 107 11 168 122 10
39703 -198 155 10 184 144 12 197 138 11 200 144 11
39704 -206 145 10 206 145 10 197 138 11 188 164 115
39705 -195 195 195 198 198 198 174 174 174 14 14 14
39706 - 2 2 6 22 22 22 116 116 116 116 116 116
39707 - 22 22 22 2 2 6 74 74 74 70 70 70
39708 - 30 30 30 10 10 10 0 0 0 0 0 0
39709 - 0 0 0 0 0 0 0 0 0 0 0 0
39710 - 0 0 0 0 0 0 0 0 0 0 0 0
39711 - 0 0 0 0 0 0 0 0 0 0 0 0
39712 - 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
39721 - 50 50 50 101 101 101 26 26 26 10 10 10
39722 -138 138 138 190 190 190 174 154 114 156 107 11
39723 -197 138 11 200 144 11 197 138 11 192 133 9
39724 -180 123 7 190 142 34 190 178 144 187 187 187
39725 -202 202 202 221 221 221 214 214 214 66 66 66
39726 - 2 2 6 2 2 6 50 50 50 62 62 62
39727 - 6 6 6 2 2 6 10 10 10 90 90 90
39728 - 50 50 50 18 18 18 6 6 6 0 0 0
39729 - 0 0 0 0 0 0 0 0 0 0 0 0
39730 - 0 0 0 0 0 0 0 0 0 0 0 0
39731 - 0 0 0 0 0 0 0 0 0 0 0 0
39732 - 0 0 0 0 0 0 0 0 0 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 0 0 0 10 10 10 34 34 34
39741 - 74 74 74 74 74 74 2 2 6 6 6 6
39742 -144 144 144 198 198 198 190 190 190 178 166 146
39743 -154 121 60 156 107 11 156 107 11 168 124 44
39744 -174 154 114 187 187 187 190 190 190 210 210 210
39745 -246 246 246 253 253 253 253 253 253 182 182 182
39746 - 6 6 6 2 2 6 2 2 6 2 2 6
39747 - 2 2 6 2 2 6 2 2 6 62 62 62
39748 - 74 74 74 34 34 34 14 14 14 0 0 0
39749 - 0 0 0 0 0 0 0 0 0 0 0 0
39750 - 0 0 0 0 0 0 0 0 0 0 0 0
39751 - 0 0 0 0 0 0 0 0 0 0 0 0
39752 - 0 0 0 0 0 0 0 0 0 0 0 0
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 22 22 22 54 54 54
39761 - 94 94 94 18 18 18 2 2 6 46 46 46
39762 -234 234 234 221 221 221 190 190 190 190 190 190
39763 -190 190 190 187 187 187 187 187 187 190 190 190
39764 -190 190 190 195 195 195 214 214 214 242 242 242
39765 -253 253 253 253 253 253 253 253 253 253 253 253
39766 - 82 82 82 2 2 6 2 2 6 2 2 6
39767 - 2 2 6 2 2 6 2 2 6 14 14 14
39768 - 86 86 86 54 54 54 22 22 22 6 6 6
39769 - 0 0 0 0 0 0 0 0 0 0 0 0
39770 - 0 0 0 0 0 0 0 0 0 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 0 0 0
39772 - 0 0 0 0 0 0 0 0 0 0 0 0
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 18 18 18 46 46 46 90 90 90
39781 - 46 46 46 18 18 18 6 6 6 182 182 182
39782 -253 253 253 246 246 246 206 206 206 190 190 190
39783 -190 190 190 190 190 190 190 190 190 190 190 190
39784 -206 206 206 231 231 231 250 250 250 253 253 253
39785 -253 253 253 253 253 253 253 253 253 253 253 253
39786 -202 202 202 14 14 14 2 2 6 2 2 6
39787 - 2 2 6 2 2 6 2 2 6 2 2 6
39788 - 42 42 42 86 86 86 42 42 42 18 18 18
39789 - 6 6 6 0 0 0 0 0 0 0 0 0
39790 - 0 0 0 0 0 0 0 0 0 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 0 0 0
39792 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
39800 - 14 14 14 38 38 38 74 74 74 66 66 66
39801 - 2 2 6 6 6 6 90 90 90 250 250 250
39802 -253 253 253 253 253 253 238 238 238 198 198 198
39803 -190 190 190 190 190 190 195 195 195 221 221 221
39804 -246 246 246 253 253 253 253 253 253 253 253 253
39805 -253 253 253 253 253 253 253 253 253 253 253 253
39806 -253 253 253 82 82 82 2 2 6 2 2 6
39807 - 2 2 6 2 2 6 2 2 6 2 2 6
39808 - 2 2 6 78 78 78 70 70 70 34 34 34
39809 - 14 14 14 6 6 6 0 0 0 0 0 0
39810 - 0 0 0 0 0 0 0 0 0 0 0 0
39811 - 0 0 0 0 0 0 0 0 0 0 0 0
39812 - 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
39820 - 34 34 34 66 66 66 78 78 78 6 6 6
39821 - 2 2 6 18 18 18 218 218 218 253 253 253
39822 -253 253 253 253 253 253 253 253 253 246 246 246
39823 -226 226 226 231 231 231 246 246 246 253 253 253
39824 -253 253 253 253 253 253 253 253 253 253 253 253
39825 -253 253 253 253 253 253 253 253 253 253 253 253
39826 -253 253 253 178 178 178 2 2 6 2 2 6
39827 - 2 2 6 2 2 6 2 2 6 2 2 6
39828 - 2 2 6 18 18 18 90 90 90 62 62 62
39829 - 30 30 30 10 10 10 0 0 0 0 0 0
39830 - 0 0 0 0 0 0 0 0 0 0 0 0
39831 - 0 0 0 0 0 0 0 0 0 0 0 0
39832 - 0 0 0 0 0 0 0 0 0 0 0 0
39833 - 0 0 0 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 10 10 10 26 26 26
39840 - 58 58 58 90 90 90 18 18 18 2 2 6
39841 - 2 2 6 110 110 110 253 253 253 253 253 253
39842 -253 253 253 253 253 253 253 253 253 253 253 253
39843 -250 250 250 253 253 253 253 253 253 253 253 253
39844 -253 253 253 253 253 253 253 253 253 253 253 253
39845 -253 253 253 253 253 253 253 253 253 253 253 253
39846 -253 253 253 231 231 231 18 18 18 2 2 6
39847 - 2 2 6 2 2 6 2 2 6 2 2 6
39848 - 2 2 6 2 2 6 18 18 18 94 94 94
39849 - 54 54 54 26 26 26 10 10 10 0 0 0
39850 - 0 0 0 0 0 0 0 0 0 0 0 0
39851 - 0 0 0 0 0 0 0 0 0 0 0 0
39852 - 0 0 0 0 0 0 0 0 0 0 0 0
39853 - 0 0 0 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 6 6 6 22 22 22 50 50 50
39860 - 90 90 90 26 26 26 2 2 6 2 2 6
39861 - 14 14 14 195 195 195 250 250 250 253 253 253
39862 -253 253 253 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 253 253 253 253 253 253
39865 -253 253 253 253 253 253 253 253 253 253 253 253
39866 -250 250 250 242 242 242 54 54 54 2 2 6
39867 - 2 2 6 2 2 6 2 2 6 2 2 6
39868 - 2 2 6 2 2 6 2 2 6 38 38 38
39869 - 86 86 86 50 50 50 22 22 22 6 6 6
39870 - 0 0 0 0 0 0 0 0 0 0 0 0
39871 - 0 0 0 0 0 0 0 0 0 0 0 0
39872 - 0 0 0 0 0 0 0 0 0 0 0 0
39873 - 0 0 0 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 - 6 6 6 14 14 14 38 38 38 82 82 82
39880 - 34 34 34 2 2 6 2 2 6 2 2 6
39881 - 42 42 42 195 195 195 246 246 246 253 253 253
39882 -253 253 253 253 253 253 253 253 253 250 250 250
39883 -242 242 242 242 242 242 250 250 250 253 253 253
39884 -253 253 253 253 253 253 253 253 253 253 253 253
39885 -253 253 253 250 250 250 246 246 246 238 238 238
39886 -226 226 226 231 231 231 101 101 101 6 6 6
39887 - 2 2 6 2 2 6 2 2 6 2 2 6
39888 - 2 2 6 2 2 6 2 2 6 2 2 6
39889 - 38 38 38 82 82 82 42 42 42 14 14 14
39890 - 6 6 6 0 0 0 0 0 0 0 0 0
39891 - 0 0 0 0 0 0 0 0 0 0 0 0
39892 - 0 0 0 0 0 0 0 0 0 0 0 0
39893 - 0 0 0 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 - 10 10 10 26 26 26 62 62 62 66 66 66
39900 - 2 2 6 2 2 6 2 2 6 6 6 6
39901 - 70 70 70 170 170 170 206 206 206 234 234 234
39902 -246 246 246 250 250 250 250 250 250 238 238 238
39903 -226 226 226 231 231 231 238 238 238 250 250 250
39904 -250 250 250 250 250 250 246 246 246 231 231 231
39905 -214 214 214 206 206 206 202 202 202 202 202 202
39906 -198 198 198 202 202 202 182 182 182 18 18 18
39907 - 2 2 6 2 2 6 2 2 6 2 2 6
39908 - 2 2 6 2 2 6 2 2 6 2 2 6
39909 - 2 2 6 62 62 62 66 66 66 30 30 30
39910 - 10 10 10 0 0 0 0 0 0 0 0 0
39911 - 0 0 0 0 0 0 0 0 0 0 0 0
39912 - 0 0 0 0 0 0 0 0 0 0 0 0
39913 - 0 0 0 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 - 14 14 14 42 42 42 82 82 82 18 18 18
39920 - 2 2 6 2 2 6 2 2 6 10 10 10
39921 - 94 94 94 182 182 182 218 218 218 242 242 242
39922 -250 250 250 253 253 253 253 253 253 250 250 250
39923 -234 234 234 253 253 253 253 253 253 253 253 253
39924 -253 253 253 253 253 253 253 253 253 246 246 246
39925 -238 238 238 226 226 226 210 210 210 202 202 202
39926 -195 195 195 195 195 195 210 210 210 158 158 158
39927 - 6 6 6 14 14 14 50 50 50 14 14 14
39928 - 2 2 6 2 2 6 2 2 6 2 2 6
39929 - 2 2 6 6 6 6 86 86 86 46 46 46
39930 - 18 18 18 6 6 6 0 0 0 0 0 0
39931 - 0 0 0 0 0 0 0 0 0 0 0 0
39932 - 0 0 0 0 0 0 0 0 0 0 0 0
39933 - 0 0 0 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 6 6 6
39939 - 22 22 22 54 54 54 70 70 70 2 2 6
39940 - 2 2 6 10 10 10 2 2 6 22 22 22
39941 -166 166 166 231 231 231 250 250 250 253 253 253
39942 -253 253 253 253 253 253 253 253 253 250 250 250
39943 -242 242 242 253 253 253 253 253 253 253 253 253
39944 -253 253 253 253 253 253 253 253 253 253 253 253
39945 -253 253 253 253 253 253 253 253 253 246 246 246
39946 -231 231 231 206 206 206 198 198 198 226 226 226
39947 - 94 94 94 2 2 6 6 6 6 38 38 38
39948 - 30 30 30 2 2 6 2 2 6 2 2 6
39949 - 2 2 6 2 2 6 62 62 62 66 66 66
39950 - 26 26 26 10 10 10 0 0 0 0 0 0
39951 - 0 0 0 0 0 0 0 0 0 0 0 0
39952 - 0 0 0 0 0 0 0 0 0 0 0 0
39953 - 0 0 0 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 10 10 10
39959 - 30 30 30 74 74 74 50 50 50 2 2 6
39960 - 26 26 26 26 26 26 2 2 6 106 106 106
39961 -238 238 238 253 253 253 253 253 253 253 253 253
39962 -253 253 253 253 253 253 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 253 253 253 253 253 253
39965 -253 253 253 253 253 253 253 253 253 253 253 253
39966 -253 253 253 246 246 246 218 218 218 202 202 202
39967 -210 210 210 14 14 14 2 2 6 2 2 6
39968 - 30 30 30 22 22 22 2 2 6 2 2 6
39969 - 2 2 6 2 2 6 18 18 18 86 86 86
39970 - 42 42 42 14 14 14 0 0 0 0 0 0
39971 - 0 0 0 0 0 0 0 0 0 0 0 0
39972 - 0 0 0 0 0 0 0 0 0 0 0 0
39973 - 0 0 0 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 0 0 0 0 0 0 14 14 14
39979 - 42 42 42 90 90 90 22 22 22 2 2 6
39980 - 42 42 42 2 2 6 18 18 18 218 218 218
39981 -253 253 253 253 253 253 253 253 253 253 253 253
39982 -253 253 253 253 253 253 253 253 253 253 253 253
39983 -253 253 253 253 253 253 253 253 253 253 253 253
39984 -253 253 253 253 253 253 253 253 253 253 253 253
39985 -253 253 253 253 253 253 253 253 253 253 253 253
39986 -253 253 253 253 253 253 250 250 250 221 221 221
39987 -218 218 218 101 101 101 2 2 6 14 14 14
39988 - 18 18 18 38 38 38 10 10 10 2 2 6
39989 - 2 2 6 2 2 6 2 2 6 78 78 78
39990 - 58 58 58 22 22 22 6 6 6 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 0 0 0
39993 - 0 0 0 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 - 0 0 0 0 0 0 6 6 6 18 18 18
39999 - 54 54 54 82 82 82 2 2 6 26 26 26
40000 - 22 22 22 2 2 6 123 123 123 253 253 253
40001 -253 253 253 253 253 253 253 253 253 253 253 253
40002 -253 253 253 253 253 253 253 253 253 253 253 253
40003 -253 253 253 253 253 253 253 253 253 253 253 253
40004 -253 253 253 253 253 253 253 253 253 253 253 253
40005 -253 253 253 253 253 253 253 253 253 253 253 253
40006 -253 253 253 253 253 253 253 253 253 250 250 250
40007 -238 238 238 198 198 198 6 6 6 38 38 38
40008 - 58 58 58 26 26 26 38 38 38 2 2 6
40009 - 2 2 6 2 2 6 2 2 6 46 46 46
40010 - 78 78 78 30 30 30 10 10 10 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 0 0 0 0 0 0 0 0 0
40013 - 0 0 0 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 - 0 0 0 0 0 0 10 10 10 30 30 30
40019 - 74 74 74 58 58 58 2 2 6 42 42 42
40020 - 2 2 6 22 22 22 231 231 231 253 253 253
40021 -253 253 253 253 253 253 253 253 253 253 253 253
40022 -253 253 253 253 253 253 253 253 253 250 250 250
40023 -253 253 253 253 253 253 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 246 246 246 46 46 46 38 38 38
40028 - 42 42 42 14 14 14 38 38 38 14 14 14
40029 - 2 2 6 2 2 6 2 2 6 6 6 6
40030 - 86 86 86 46 46 46 14 14 14 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 0 0 0
40032 - 0 0 0 0 0 0 0 0 0 0 0 0
40033 - 0 0 0 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 0 0 0
40038 - 0 0 0 6 6 6 14 14 14 42 42 42
40039 - 90 90 90 18 18 18 18 18 18 26 26 26
40040 - 2 2 6 116 116 116 253 253 253 253 253 253
40041 -253 253 253 253 253 253 253 253 253 253 253 253
40042 -253 253 253 253 253 253 250 250 250 238 238 238
40043 -253 253 253 253 253 253 253 253 253 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 94 94 94 6 6 6
40048 - 2 2 6 2 2 6 10 10 10 34 34 34
40049 - 2 2 6 2 2 6 2 2 6 2 2 6
40050 - 74 74 74 58 58 58 22 22 22 6 6 6
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 0 0 0
40053 - 0 0 0 0 0 0 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 0 0 0
40058 - 0 0 0 10 10 10 26 26 26 66 66 66
40059 - 82 82 82 2 2 6 38 38 38 6 6 6
40060 - 14 14 14 210 210 210 253 253 253 253 253 253
40061 -253 253 253 253 253 253 253 253 253 253 253 253
40062 -253 253 253 253 253 253 246 246 246 242 242 242
40063 -253 253 253 253 253 253 253 253 253 253 253 253
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 144 144 144 2 2 6
40068 - 2 2 6 2 2 6 2 2 6 46 46 46
40069 - 2 2 6 2 2 6 2 2 6 2 2 6
40070 - 42 42 42 74 74 74 30 30 30 10 10 10
40071 - 0 0 0 0 0 0 0 0 0 0 0 0
40072 - 0 0 0 0 0 0 0 0 0 0 0 0
40073 - 0 0 0 0 0 0 0 0 0 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 0 0 0
40078 - 6 6 6 14 14 14 42 42 42 90 90 90
40079 - 26 26 26 6 6 6 42 42 42 2 2 6
40080 - 74 74 74 250 250 250 253 253 253 253 253 253
40081 -253 253 253 253 253 253 253 253 253 253 253 253
40082 -253 253 253 253 253 253 242 242 242 242 242 242
40083 -253 253 253 253 253 253 253 253 253 253 253 253
40084 -253 253 253 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 182 182 182 2 2 6
40088 - 2 2 6 2 2 6 2 2 6 46 46 46
40089 - 2 2 6 2 2 6 2 2 6 2 2 6
40090 - 10 10 10 86 86 86 38 38 38 10 10 10
40091 - 0 0 0 0 0 0 0 0 0 0 0 0
40092 - 0 0 0 0 0 0 0 0 0 0 0 0
40093 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
40098 - 10 10 10 26 26 26 66 66 66 82 82 82
40099 - 2 2 6 22 22 22 18 18 18 2 2 6
40100 -149 149 149 253 253 253 253 253 253 253 253 253
40101 -253 253 253 253 253 253 253 253 253 253 253 253
40102 -253 253 253 253 253 253 234 234 234 242 242 242
40103 -253 253 253 253 253 253 253 253 253 253 253 253
40104 -253 253 253 253 253 253 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 206 206 206 2 2 6
40108 - 2 2 6 2 2 6 2 2 6 38 38 38
40109 - 2 2 6 2 2 6 2 2 6 2 2 6
40110 - 6 6 6 86 86 86 46 46 46 14 14 14
40111 - 0 0 0 0 0 0 0 0 0 0 0 0
40112 - 0 0 0 0 0 0 0 0 0 0 0 0
40113 - 0 0 0 0 0 0 0 0 0 0 0 0
40114 - 0 0 0 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 6 6 6
40118 - 18 18 18 46 46 46 86 86 86 18 18 18
40119 - 2 2 6 34 34 34 10 10 10 6 6 6
40120 -210 210 210 253 253 253 253 253 253 253 253 253
40121 -253 253 253 253 253 253 253 253 253 253 253 253
40122 -253 253 253 253 253 253 234 234 234 242 242 242
40123 -253 253 253 253 253 253 253 253 253 253 253 253
40124 -253 253 253 253 253 253 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 221 221 221 6 6 6
40128 - 2 2 6 2 2 6 6 6 6 30 30 30
40129 - 2 2 6 2 2 6 2 2 6 2 2 6
40130 - 2 2 6 82 82 82 54 54 54 18 18 18
40131 - 6 6 6 0 0 0 0 0 0 0 0 0
40132 - 0 0 0 0 0 0 0 0 0 0 0 0
40133 - 0 0 0 0 0 0 0 0 0 0 0 0
40134 - 0 0 0 0 0 0 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 10 10 10
40138 - 26 26 26 66 66 66 62 62 62 2 2 6
40139 - 2 2 6 38 38 38 10 10 10 26 26 26
40140 -238 238 238 253 253 253 253 253 253 253 253 253
40141 -253 253 253 253 253 253 253 253 253 253 253 253
40142 -253 253 253 253 253 253 231 231 231 238 238 238
40143 -253 253 253 253 253 253 253 253 253 253 253 253
40144 -253 253 253 253 253 253 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 231 231 231 6 6 6
40148 - 2 2 6 2 2 6 10 10 10 30 30 30
40149 - 2 2 6 2 2 6 2 2 6 2 2 6
40150 - 2 2 6 66 66 66 58 58 58 22 22 22
40151 - 6 6 6 0 0 0 0 0 0 0 0 0
40152 - 0 0 0 0 0 0 0 0 0 0 0 0
40153 - 0 0 0 0 0 0 0 0 0 0 0 0
40154 - 0 0 0 0 0 0 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 10 10 10
40158 - 38 38 38 78 78 78 6 6 6 2 2 6
40159 - 2 2 6 46 46 46 14 14 14 42 42 42
40160 -246 246 246 253 253 253 253 253 253 253 253 253
40161 -253 253 253 253 253 253 253 253 253 253 253 253
40162 -253 253 253 253 253 253 231 231 231 242 242 242
40163 -253 253 253 253 253 253 253 253 253 253 253 253
40164 -253 253 253 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 234 234 234 10 10 10
40168 - 2 2 6 2 2 6 22 22 22 14 14 14
40169 - 2 2 6 2 2 6 2 2 6 2 2 6
40170 - 2 2 6 66 66 66 62 62 62 22 22 22
40171 - 6 6 6 0 0 0 0 0 0 0 0 0
40172 - 0 0 0 0 0 0 0 0 0 0 0 0
40173 - 0 0 0 0 0 0 0 0 0 0 0 0
40174 - 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
40178 - 50 50 50 74 74 74 2 2 6 2 2 6
40179 - 14 14 14 70 70 70 34 34 34 62 62 62
40180 -250 250 250 253 253 253 253 253 253 253 253 253
40181 -253 253 253 253 253 253 253 253 253 253 253 253
40182 -253 253 253 253 253 253 231 231 231 246 246 246
40183 -253 253 253 253 253 253 253 253 253 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 234 234 234 14 14 14
40188 - 2 2 6 2 2 6 30 30 30 2 2 6
40189 - 2 2 6 2 2 6 2 2 6 2 2 6
40190 - 2 2 6 66 66 66 62 62 62 22 22 22
40191 - 6 6 6 0 0 0 0 0 0 0 0 0
40192 - 0 0 0 0 0 0 0 0 0 0 0 0
40193 - 0 0 0 0 0 0 0 0 0 0 0 0
40194 - 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
40198 - 54 54 54 62 62 62 2 2 6 2 2 6
40199 - 2 2 6 30 30 30 46 46 46 70 70 70
40200 -250 250 250 253 253 253 253 253 253 253 253 253
40201 -253 253 253 253 253 253 253 253 253 253 253 253
40202 -253 253 253 253 253 253 231 231 231 246 246 246
40203 -253 253 253 253 253 253 253 253 253 253 253 253
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 253 253 253 226 226 226 10 10 10
40208 - 2 2 6 6 6 6 30 30 30 2 2 6
40209 - 2 2 6 2 2 6 2 2 6 2 2 6
40210 - 2 2 6 66 66 66 58 58 58 22 22 22
40211 - 6 6 6 0 0 0 0 0 0 0 0 0
40212 - 0 0 0 0 0 0 0 0 0 0 0 0
40213 - 0 0 0 0 0 0 0 0 0 0 0 0
40214 - 0 0 0 0 0 0 0 0 0 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 22 22 22
40218 - 58 58 58 62 62 62 2 2 6 2 2 6
40219 - 2 2 6 2 2 6 30 30 30 78 78 78
40220 -250 250 250 253 253 253 253 253 253 253 253 253
40221 -253 253 253 253 253 253 253 253 253 253 253 253
40222 -253 253 253 253 253 253 231 231 231 246 246 246
40223 -253 253 253 253 253 253 253 253 253 253 253 253
40224 -253 253 253 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 -253 253 253 253 253 253 206 206 206 2 2 6
40228 - 22 22 22 34 34 34 18 14 6 22 22 22
40229 - 26 26 26 18 18 18 6 6 6 2 2 6
40230 - 2 2 6 82 82 82 54 54 54 18 18 18
40231 - 6 6 6 0 0 0 0 0 0 0 0 0
40232 - 0 0 0 0 0 0 0 0 0 0 0 0
40233 - 0 0 0 0 0 0 0 0 0 0 0 0
40234 - 0 0 0 0 0 0 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 26 26 26
40238 - 62 62 62 106 106 106 74 54 14 185 133 11
40239 -210 162 10 121 92 8 6 6 6 62 62 62
40240 -238 238 238 253 253 253 253 253 253 253 253 253
40241 -253 253 253 253 253 253 253 253 253 253 253 253
40242 -253 253 253 253 253 253 231 231 231 246 246 246
40243 -253 253 253 253 253 253 253 253 253 253 253 253
40244 -253 253 253 253 253 253 253 253 253 253 253 253
40245 -253 253 253 253 253 253 253 253 253 253 253 253
40246 -253 253 253 253 253 253 253 253 253 253 253 253
40247 -253 253 253 253 253 253 158 158 158 18 18 18
40248 - 14 14 14 2 2 6 2 2 6 2 2 6
40249 - 6 6 6 18 18 18 66 66 66 38 38 38
40250 - 6 6 6 94 94 94 50 50 50 18 18 18
40251 - 6 6 6 0 0 0 0 0 0 0 0 0
40252 - 0 0 0 0 0 0 0 0 0 0 0 0
40253 - 0 0 0 0 0 0 0 0 0 0 0 0
40254 - 0 0 0 0 0 0 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 6 6 6
40257 - 10 10 10 10 10 10 18 18 18 38 38 38
40258 - 78 78 78 142 134 106 216 158 10 242 186 14
40259 -246 190 14 246 190 14 156 118 10 10 10 10
40260 - 90 90 90 238 238 238 253 253 253 253 253 253
40261 -253 253 253 253 253 253 253 253 253 253 253 253
40262 -253 253 253 253 253 253 231 231 231 250 250 250
40263 -253 253 253 253 253 253 253 253 253 253 253 253
40264 -253 253 253 253 253 253 253 253 253 253 253 253
40265 -253 253 253 253 253 253 253 253 253 253 253 253
40266 -253 253 253 253 253 253 253 253 253 246 230 190
40267 -238 204 91 238 204 91 181 142 44 37 26 9
40268 - 2 2 6 2 2 6 2 2 6 2 2 6
40269 - 2 2 6 2 2 6 38 38 38 46 46 46
40270 - 26 26 26 106 106 106 54 54 54 18 18 18
40271 - 6 6 6 0 0 0 0 0 0 0 0 0
40272 - 0 0 0 0 0 0 0 0 0 0 0 0
40273 - 0 0 0 0 0 0 0 0 0 0 0 0
40274 - 0 0 0 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 6 6 6 14 14 14 22 22 22
40277 - 30 30 30 38 38 38 50 50 50 70 70 70
40278 -106 106 106 190 142 34 226 170 11 242 186 14
40279 -246 190 14 246 190 14 246 190 14 154 114 10
40280 - 6 6 6 74 74 74 226 226 226 253 253 253
40281 -253 253 253 253 253 253 253 253 253 253 253 253
40282 -253 253 253 253 253 253 231 231 231 250 250 250
40283 -253 253 253 253 253 253 253 253 253 253 253 253
40284 -253 253 253 253 253 253 253 253 253 253 253 253
40285 -253 253 253 253 253 253 253 253 253 253 253 253
40286 -253 253 253 253 253 253 253 253 253 228 184 62
40287 -241 196 14 241 208 19 232 195 16 38 30 10
40288 - 2 2 6 2 2 6 2 2 6 2 2 6
40289 - 2 2 6 6 6 6 30 30 30 26 26 26
40290 -203 166 17 154 142 90 66 66 66 26 26 26
40291 - 6 6 6 0 0 0 0 0 0 0 0 0
40292 - 0 0 0 0 0 0 0 0 0 0 0 0
40293 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 18 18 18 38 38 38 58 58 58
40297 - 78 78 78 86 86 86 101 101 101 123 123 123
40298 -175 146 61 210 150 10 234 174 13 246 186 14
40299 -246 190 14 246 190 14 246 190 14 238 190 10
40300 -102 78 10 2 2 6 46 46 46 198 198 198
40301 -253 253 253 253 253 253 253 253 253 253 253 253
40302 -253 253 253 253 253 253 234 234 234 242 242 242
40303 -253 253 253 253 253 253 253 253 253 253 253 253
40304 -253 253 253 253 253 253 253 253 253 253 253 253
40305 -253 253 253 253 253 253 253 253 253 253 253 253
40306 -253 253 253 253 253 253 253 253 253 224 178 62
40307 -242 186 14 241 196 14 210 166 10 22 18 6
40308 - 2 2 6 2 2 6 2 2 6 2 2 6
40309 - 2 2 6 2 2 6 6 6 6 121 92 8
40310 -238 202 15 232 195 16 82 82 82 34 34 34
40311 - 10 10 10 0 0 0 0 0 0 0 0 0
40312 - 0 0 0 0 0 0 0 0 0 0 0 0
40313 - 0 0 0 0 0 0 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 - 14 14 14 38 38 38 70 70 70 154 122 46
40317 -190 142 34 200 144 11 197 138 11 197 138 11
40318 -213 154 11 226 170 11 242 186 14 246 190 14
40319 -246 190 14 246 190 14 246 190 14 246 190 14
40320 -225 175 15 46 32 6 2 2 6 22 22 22
40321 -158 158 158 250 250 250 253 253 253 253 253 253
40322 -253 253 253 253 253 253 253 253 253 253 253 253
40323 -253 253 253 253 253 253 253 253 253 253 253 253
40324 -253 253 253 253 253 253 253 253 253 253 253 253
40325 -253 253 253 253 253 253 253 253 253 253 253 253
40326 -253 253 253 250 250 250 242 242 242 224 178 62
40327 -239 182 13 236 186 11 213 154 11 46 32 6
40328 - 2 2 6 2 2 6 2 2 6 2 2 6
40329 - 2 2 6 2 2 6 61 42 6 225 175 15
40330 -238 190 10 236 186 11 112 100 78 42 42 42
40331 - 14 14 14 0 0 0 0 0 0 0 0 0
40332 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
40336 - 22 22 22 54 54 54 154 122 46 213 154 11
40337 -226 170 11 230 174 11 226 170 11 226 170 11
40338 -236 178 12 242 186 14 246 190 14 246 190 14
40339 -246 190 14 246 190 14 246 190 14 246 190 14
40340 -241 196 14 184 144 12 10 10 10 2 2 6
40341 - 6 6 6 116 116 116 242 242 242 253 253 253
40342 -253 253 253 253 253 253 253 253 253 253 253 253
40343 -253 253 253 253 253 253 253 253 253 253 253 253
40344 -253 253 253 253 253 253 253 253 253 253 253 253
40345 -253 253 253 253 253 253 253 253 253 253 253 253
40346 -253 253 253 231 231 231 198 198 198 214 170 54
40347 -236 178 12 236 178 12 210 150 10 137 92 6
40348 - 18 14 6 2 2 6 2 2 6 2 2 6
40349 - 6 6 6 70 47 6 200 144 11 236 178 12
40350 -239 182 13 239 182 13 124 112 88 58 58 58
40351 - 22 22 22 6 6 6 0 0 0 0 0 0
40352 - 0 0 0 0 0 0 0 0 0 0 0 0
40353 - 0 0 0 0 0 0 0 0 0 0 0 0
40354 - 0 0 0 0 0 0 0 0 0 0 0 0
40355 - 0 0 0 0 0 0 0 0 0 10 10 10
40356 - 30 30 30 70 70 70 180 133 36 226 170 11
40357 -239 182 13 242 186 14 242 186 14 246 186 14
40358 -246 190 14 246 190 14 246 190 14 246 190 14
40359 -246 190 14 246 190 14 246 190 14 246 190 14
40360 -246 190 14 232 195 16 98 70 6 2 2 6
40361 - 2 2 6 2 2 6 66 66 66 221 221 221
40362 -253 253 253 253 253 253 253 253 253 253 253 253
40363 -253 253 253 253 253 253 253 253 253 253 253 253
40364 -253 253 253 253 253 253 253 253 253 253 253 253
40365 -253 253 253 253 253 253 253 253 253 253 253 253
40366 -253 253 253 206 206 206 198 198 198 214 166 58
40367 -230 174 11 230 174 11 216 158 10 192 133 9
40368 -163 110 8 116 81 8 102 78 10 116 81 8
40369 -167 114 7 197 138 11 226 170 11 239 182 13
40370 -242 186 14 242 186 14 162 146 94 78 78 78
40371 - 34 34 34 14 14 14 6 6 6 0 0 0
40372 - 0 0 0 0 0 0 0 0 0 0 0 0
40373 - 0 0 0 0 0 0 0 0 0 0 0 0
40374 - 0 0 0 0 0 0 0 0 0 0 0 0
40375 - 0 0 0 0 0 0 0 0 0 6 6 6
40376 - 30 30 30 78 78 78 190 142 34 226 170 11
40377 -239 182 13 246 190 14 246 190 14 246 190 14
40378 -246 190 14 246 190 14 246 190 14 246 190 14
40379 -246 190 14 246 190 14 246 190 14 246 190 14
40380 -246 190 14 241 196 14 203 166 17 22 18 6
40381 - 2 2 6 2 2 6 2 2 6 38 38 38
40382 -218 218 218 253 253 253 253 253 253 253 253 253
40383 -253 253 253 253 253 253 253 253 253 253 253 253
40384 -253 253 253 253 253 253 253 253 253 253 253 253
40385 -253 253 253 253 253 253 253 253 253 253 253 253
40386 -250 250 250 206 206 206 198 198 198 202 162 69
40387 -226 170 11 236 178 12 224 166 10 210 150 10
40388 -200 144 11 197 138 11 192 133 9 197 138 11
40389 -210 150 10 226 170 11 242 186 14 246 190 14
40390 -246 190 14 246 186 14 225 175 15 124 112 88
40391 - 62 62 62 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 10 10 10
40396 - 30 30 30 78 78 78 174 135 50 224 166 10
40397 -239 182 13 246 190 14 246 190 14 246 190 14
40398 -246 190 14 246 190 14 246 190 14 246 190 14
40399 -246 190 14 246 190 14 246 190 14 246 190 14
40400 -246 190 14 246 190 14 241 196 14 139 102 15
40401 - 2 2 6 2 2 6 2 2 6 2 2 6
40402 - 78 78 78 250 250 250 253 253 253 253 253 253
40403 -253 253 253 253 253 253 253 253 253 253 253 253
40404 -253 253 253 253 253 253 253 253 253 253 253 253
40405 -253 253 253 253 253 253 253 253 253 253 253 253
40406 -250 250 250 214 214 214 198 198 198 190 150 46
40407 -219 162 10 236 178 12 234 174 13 224 166 10
40408 -216 158 10 213 154 11 213 154 11 216 158 10
40409 -226 170 11 239 182 13 246 190 14 246 190 14
40410 -246 190 14 246 190 14 242 186 14 206 162 42
40411 -101 101 101 58 58 58 30 30 30 14 14 14
40412 - 6 6 6 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 10 10 10
40416 - 30 30 30 74 74 74 174 135 50 216 158 10
40417 -236 178 12 246 190 14 246 190 14 246 190 14
40418 -246 190 14 246 190 14 246 190 14 246 190 14
40419 -246 190 14 246 190 14 246 190 14 246 190 14
40420 -246 190 14 246 190 14 241 196 14 226 184 13
40421 - 61 42 6 2 2 6 2 2 6 2 2 6
40422 - 22 22 22 238 238 238 253 253 253 253 253 253
40423 -253 253 253 253 253 253 253 253 253 253 253 253
40424 -253 253 253 253 253 253 253 253 253 253 253 253
40425 -253 253 253 253 253 253 253 253 253 253 253 253
40426 -253 253 253 226 226 226 187 187 187 180 133 36
40427 -216 158 10 236 178 12 239 182 13 236 178 12
40428 -230 174 11 226 170 11 226 170 11 230 174 11
40429 -236 178 12 242 186 14 246 190 14 246 190 14
40430 -246 190 14 246 190 14 246 186 14 239 182 13
40431 -206 162 42 106 106 106 66 66 66 34 34 34
40432 - 14 14 14 6 6 6 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 6 6 6
40436 - 26 26 26 70 70 70 163 133 67 213 154 11
40437 -236 178 12 246 190 14 246 190 14 246 190 14
40438 -246 190 14 246 190 14 246 190 14 246 190 14
40439 -246 190 14 246 190 14 246 190 14 246 190 14
40440 -246 190 14 246 190 14 246 190 14 241 196 14
40441 -190 146 13 18 14 6 2 2 6 2 2 6
40442 - 46 46 46 246 246 246 253 253 253 253 253 253
40443 -253 253 253 253 253 253 253 253 253 253 253 253
40444 -253 253 253 253 253 253 253 253 253 253 253 253
40445 -253 253 253 253 253 253 253 253 253 253 253 253
40446 -253 253 253 221 221 221 86 86 86 156 107 11
40447 -216 158 10 236 178 12 242 186 14 246 186 14
40448 -242 186 14 239 182 13 239 182 13 242 186 14
40449 -242 186 14 246 186 14 246 190 14 246 190 14
40450 -246 190 14 246 190 14 246 190 14 246 190 14
40451 -242 186 14 225 175 15 142 122 72 66 66 66
40452 - 30 30 30 10 10 10 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 6 6 6
40456 - 26 26 26 70 70 70 163 133 67 210 150 10
40457 -236 178 12 246 190 14 246 190 14 246 190 14
40458 -246 190 14 246 190 14 246 190 14 246 190 14
40459 -246 190 14 246 190 14 246 190 14 246 190 14
40460 -246 190 14 246 190 14 246 190 14 246 190 14
40461 -232 195 16 121 92 8 34 34 34 106 106 106
40462 -221 221 221 253 253 253 253 253 253 253 253 253
40463 -253 253 253 253 253 253 253 253 253 253 253 253
40464 -253 253 253 253 253 253 253 253 253 253 253 253
40465 -253 253 253 253 253 253 253 253 253 253 253 253
40466 -242 242 242 82 82 82 18 14 6 163 110 8
40467 -216 158 10 236 178 12 242 186 14 246 190 14
40468 -246 190 14 246 190 14 246 190 14 246 190 14
40469 -246 190 14 246 190 14 246 190 14 246 190 14
40470 -246 190 14 246 190 14 246 190 14 246 190 14
40471 -246 190 14 246 190 14 242 186 14 163 133 67
40472 - 46 46 46 18 18 18 6 6 6 0 0 0
40473 - 0 0 0 0 0 0 0 0 0 0 0 0
40474 - 0 0 0 0 0 0 0 0 0 0 0 0
40475 - 0 0 0 0 0 0 0 0 0 10 10 10
40476 - 30 30 30 78 78 78 163 133 67 210 150 10
40477 -236 178 12 246 186 14 246 190 14 246 190 14
40478 -246 190 14 246 190 14 246 190 14 246 190 14
40479 -246 190 14 246 190 14 246 190 14 246 190 14
40480 -246 190 14 246 190 14 246 190 14 246 190 14
40481 -241 196 14 215 174 15 190 178 144 253 253 253
40482 -253 253 253 253 253 253 253 253 253 253 253 253
40483 -253 253 253 253 253 253 253 253 253 253 253 253
40484 -253 253 253 253 253 253 253 253 253 253 253 253
40485 -253 253 253 253 253 253 253 253 253 218 218 218
40486 - 58 58 58 2 2 6 22 18 6 167 114 7
40487 -216 158 10 236 178 12 246 186 14 246 190 14
40488 -246 190 14 246 190 14 246 190 14 246 190 14
40489 -246 190 14 246 190 14 246 190 14 246 190 14
40490 -246 190 14 246 190 14 246 190 14 246 190 14
40491 -246 190 14 246 186 14 242 186 14 190 150 46
40492 - 54 54 54 22 22 22 6 6 6 0 0 0
40493 - 0 0 0 0 0 0 0 0 0 0 0 0
40494 - 0 0 0 0 0 0 0 0 0 0 0 0
40495 - 0 0 0 0 0 0 0 0 0 14 14 14
40496 - 38 38 38 86 86 86 180 133 36 213 154 11
40497 -236 178 12 246 186 14 246 190 14 246 190 14
40498 -246 190 14 246 190 14 246 190 14 246 190 14
40499 -246 190 14 246 190 14 246 190 14 246 190 14
40500 -246 190 14 246 190 14 246 190 14 246 190 14
40501 -246 190 14 232 195 16 190 146 13 214 214 214
40502 -253 253 253 253 253 253 253 253 253 253 253 253
40503 -253 253 253 253 253 253 253 253 253 253 253 253
40504 -253 253 253 253 253 253 253 253 253 253 253 253
40505 -253 253 253 250 250 250 170 170 170 26 26 26
40506 - 2 2 6 2 2 6 37 26 9 163 110 8
40507 -219 162 10 239 182 13 246 186 14 246 190 14
40508 -246 190 14 246 190 14 246 190 14 246 190 14
40509 -246 190 14 246 190 14 246 190 14 246 190 14
40510 -246 190 14 246 190 14 246 190 14 246 190 14
40511 -246 186 14 236 178 12 224 166 10 142 122 72
40512 - 46 46 46 18 18 18 6 6 6 0 0 0
40513 - 0 0 0 0 0 0 0 0 0 0 0 0
40514 - 0 0 0 0 0 0 0 0 0 0 0 0
40515 - 0 0 0 0 0 0 6 6 6 18 18 18
40516 - 50 50 50 109 106 95 192 133 9 224 166 10
40517 -242 186 14 246 190 14 246 190 14 246 190 14
40518 -246 190 14 246 190 14 246 190 14 246 190 14
40519 -246 190 14 246 190 14 246 190 14 246 190 14
40520 -246 190 14 246 190 14 246 190 14 246 190 14
40521 -242 186 14 226 184 13 210 162 10 142 110 46
40522 -226 226 226 253 253 253 253 253 253 253 253 253
40523 -253 253 253 253 253 253 253 253 253 253 253 253
40524 -253 253 253 253 253 253 253 253 253 253 253 253
40525 -198 198 198 66 66 66 2 2 6 2 2 6
40526 - 2 2 6 2 2 6 50 34 6 156 107 11
40527 -219 162 10 239 182 13 246 186 14 246 190 14
40528 -246 190 14 246 190 14 246 190 14 246 190 14
40529 -246 190 14 246 190 14 246 190 14 246 190 14
40530 -246 190 14 246 190 14 246 190 14 242 186 14
40531 -234 174 13 213 154 11 154 122 46 66 66 66
40532 - 30 30 30 10 10 10 0 0 0 0 0 0
40533 - 0 0 0 0 0 0 0 0 0 0 0 0
40534 - 0 0 0 0 0 0 0 0 0 0 0 0
40535 - 0 0 0 0 0 0 6 6 6 22 22 22
40536 - 58 58 58 154 121 60 206 145 10 234 174 13
40537 -242 186 14 246 186 14 246 190 14 246 190 14
40538 -246 190 14 246 190 14 246 190 14 246 190 14
40539 -246 190 14 246 190 14 246 190 14 246 190 14
40540 -246 190 14 246 190 14 246 190 14 246 190 14
40541 -246 186 14 236 178 12 210 162 10 163 110 8
40542 - 61 42 6 138 138 138 218 218 218 250 250 250
40543 -253 253 253 253 253 253 253 253 253 250 250 250
40544 -242 242 242 210 210 210 144 144 144 66 66 66
40545 - 6 6 6 2 2 6 2 2 6 2 2 6
40546 - 2 2 6 2 2 6 61 42 6 163 110 8
40547 -216 158 10 236 178 12 246 190 14 246 190 14
40548 -246 190 14 246 190 14 246 190 14 246 190 14
40549 -246 190 14 246 190 14 246 190 14 246 190 14
40550 -246 190 14 239 182 13 230 174 11 216 158 10
40551 -190 142 34 124 112 88 70 70 70 38 38 38
40552 - 18 18 18 6 6 6 0 0 0 0 0 0
40553 - 0 0 0 0 0 0 0 0 0 0 0 0
40554 - 0 0 0 0 0 0 0 0 0 0 0 0
40555 - 0 0 0 0 0 0 6 6 6 22 22 22
40556 - 62 62 62 168 124 44 206 145 10 224 166 10
40557 -236 178 12 239 182 13 242 186 14 242 186 14
40558 -246 186 14 246 190 14 246 190 14 246 190 14
40559 -246 190 14 246 190 14 246 190 14 246 190 14
40560 -246 190 14 246 190 14 246 190 14 246 190 14
40561 -246 190 14 236 178 12 216 158 10 175 118 6
40562 - 80 54 7 2 2 6 6 6 6 30 30 30
40563 - 54 54 54 62 62 62 50 50 50 38 38 38
40564 - 14 14 14 2 2 6 2 2 6 2 2 6
40565 - 2 2 6 2 2 6 2 2 6 2 2 6
40566 - 2 2 6 6 6 6 80 54 7 167 114 7
40567 -213 154 11 236 178 12 246 190 14 246 190 14
40568 -246 190 14 246 190 14 246 190 14 246 190 14
40569 -246 190 14 242 186 14 239 182 13 239 182 13
40570 -230 174 11 210 150 10 174 135 50 124 112 88
40571 - 82 82 82 54 54 54 34 34 34 18 18 18
40572 - 6 6 6 0 0 0 0 0 0 0 0 0
40573 - 0 0 0 0 0 0 0 0 0 0 0 0
40574 - 0 0 0 0 0 0 0 0 0 0 0 0
40575 - 0 0 0 0 0 0 6 6 6 18 18 18
40576 - 50 50 50 158 118 36 192 133 9 200 144 11
40577 -216 158 10 219 162 10 224 166 10 226 170 11
40578 -230 174 11 236 178 12 239 182 13 239 182 13
40579 -242 186 14 246 186 14 246 190 14 246 190 14
40580 -246 190 14 246 190 14 246 190 14 246 190 14
40581 -246 186 14 230 174 11 210 150 10 163 110 8
40582 -104 69 6 10 10 10 2 2 6 2 2 6
40583 - 2 2 6 2 2 6 2 2 6 2 2 6
40584 - 2 2 6 2 2 6 2 2 6 2 2 6
40585 - 2 2 6 2 2 6 2 2 6 2 2 6
40586 - 2 2 6 6 6 6 91 60 6 167 114 7
40587 -206 145 10 230 174 11 242 186 14 246 190 14
40588 -246 190 14 246 190 14 246 186 14 242 186 14
40589 -239 182 13 230 174 11 224 166 10 213 154 11
40590 -180 133 36 124 112 88 86 86 86 58 58 58
40591 - 38 38 38 22 22 22 10 10 10 6 6 6
40592 - 0 0 0 0 0 0 0 0 0 0 0 0
40593 - 0 0 0 0 0 0 0 0 0 0 0 0
40594 - 0 0 0 0 0 0 0 0 0 0 0 0
40595 - 0 0 0 0 0 0 0 0 0 14 14 14
40596 - 34 34 34 70 70 70 138 110 50 158 118 36
40597 -167 114 7 180 123 7 192 133 9 197 138 11
40598 -200 144 11 206 145 10 213 154 11 219 162 10
40599 -224 166 10 230 174 11 239 182 13 242 186 14
40600 -246 186 14 246 186 14 246 186 14 246 186 14
40601 -239 182 13 216 158 10 185 133 11 152 99 6
40602 -104 69 6 18 14 6 2 2 6 2 2 6
40603 - 2 2 6 2 2 6 2 2 6 2 2 6
40604 - 2 2 6 2 2 6 2 2 6 2 2 6
40605 - 2 2 6 2 2 6 2 2 6 2 2 6
40606 - 2 2 6 6 6 6 80 54 7 152 99 6
40607 -192 133 9 219 162 10 236 178 12 239 182 13
40608 -246 186 14 242 186 14 239 182 13 236 178 12
40609 -224 166 10 206 145 10 192 133 9 154 121 60
40610 - 94 94 94 62 62 62 42 42 42 22 22 22
40611 - 14 14 14 6 6 6 0 0 0 0 0 0
40612 - 0 0 0 0 0 0 0 0 0 0 0 0
40613 - 0 0 0 0 0 0 0 0 0 0 0 0
40614 - 0 0 0 0 0 0 0 0 0 0 0 0
40615 - 0 0 0 0 0 0 0 0 0 6 6 6
40616 - 18 18 18 34 34 34 58 58 58 78 78 78
40617 -101 98 89 124 112 88 142 110 46 156 107 11
40618 -163 110 8 167 114 7 175 118 6 180 123 7
40619 -185 133 11 197 138 11 210 150 10 219 162 10
40620 -226 170 11 236 178 12 236 178 12 234 174 13
40621 -219 162 10 197 138 11 163 110 8 130 83 6
40622 - 91 60 6 10 10 10 2 2 6 2 2 6
40623 - 18 18 18 38 38 38 38 38 38 38 38 38
40624 - 38 38 38 38 38 38 38 38 38 38 38 38
40625 - 38 38 38 38 38 38 26 26 26 2 2 6
40626 - 2 2 6 6 6 6 70 47 6 137 92 6
40627 -175 118 6 200 144 11 219 162 10 230 174 11
40628 -234 174 13 230 174 11 219 162 10 210 150 10
40629 -192 133 9 163 110 8 124 112 88 82 82 82
40630 - 50 50 50 30 30 30 14 14 14 6 6 6
40631 - 0 0 0 0 0 0 0 0 0 0 0 0
40632 - 0 0 0 0 0 0 0 0 0 0 0 0
40633 - 0 0 0 0 0 0 0 0 0 0 0 0
40634 - 0 0 0 0 0 0 0 0 0 0 0 0
40635 - 0 0 0 0 0 0 0 0 0 0 0 0
40636 - 6 6 6 14 14 14 22 22 22 34 34 34
40637 - 42 42 42 58 58 58 74 74 74 86 86 86
40638 -101 98 89 122 102 70 130 98 46 121 87 25
40639 -137 92 6 152 99 6 163 110 8 180 123 7
40640 -185 133 11 197 138 11 206 145 10 200 144 11
40641 -180 123 7 156 107 11 130 83 6 104 69 6
40642 - 50 34 6 54 54 54 110 110 110 101 98 89
40643 - 86 86 86 82 82 82 78 78 78 78 78 78
40644 - 78 78 78 78 78 78 78 78 78 78 78 78
40645 - 78 78 78 82 82 82 86 86 86 94 94 94
40646 -106 106 106 101 101 101 86 66 34 124 80 6
40647 -156 107 11 180 123 7 192 133 9 200 144 11
40648 -206 145 10 200 144 11 192 133 9 175 118 6
40649 -139 102 15 109 106 95 70 70 70 42 42 42
40650 - 22 22 22 10 10 10 0 0 0 0 0 0
40651 - 0 0 0 0 0 0 0 0 0 0 0 0
40652 - 0 0 0 0 0 0 0 0 0 0 0 0
40653 - 0 0 0 0 0 0 0 0 0 0 0 0
40654 - 0 0 0 0 0 0 0 0 0 0 0 0
40655 - 0 0 0 0 0 0 0 0 0 0 0 0
40656 - 0 0 0 0 0 0 6 6 6 10 10 10
40657 - 14 14 14 22 22 22 30 30 30 38 38 38
40658 - 50 50 50 62 62 62 74 74 74 90 90 90
40659 -101 98 89 112 100 78 121 87 25 124 80 6
40660 -137 92 6 152 99 6 152 99 6 152 99 6
40661 -138 86 6 124 80 6 98 70 6 86 66 30
40662 -101 98 89 82 82 82 58 58 58 46 46 46
40663 - 38 38 38 34 34 34 34 34 34 34 34 34
40664 - 34 34 34 34 34 34 34 34 34 34 34 34
40665 - 34 34 34 34 34 34 38 38 38 42 42 42
40666 - 54 54 54 82 82 82 94 86 76 91 60 6
40667 -134 86 6 156 107 11 167 114 7 175 118 6
40668 -175 118 6 167 114 7 152 99 6 121 87 25
40669 -101 98 89 62 62 62 34 34 34 18 18 18
40670 - 6 6 6 0 0 0 0 0 0 0 0 0
40671 - 0 0 0 0 0 0 0 0 0 0 0 0
40672 - 0 0 0 0 0 0 0 0 0 0 0 0
40673 - 0 0 0 0 0 0 0 0 0 0 0 0
40674 - 0 0 0 0 0 0 0 0 0 0 0 0
40675 - 0 0 0 0 0 0 0 0 0 0 0 0
40676 - 0 0 0 0 0 0 0 0 0 0 0 0
40677 - 0 0 0 6 6 6 6 6 6 10 10 10
40678 - 18 18 18 22 22 22 30 30 30 42 42 42
40679 - 50 50 50 66 66 66 86 86 86 101 98 89
40680 -106 86 58 98 70 6 104 69 6 104 69 6
40681 -104 69 6 91 60 6 82 62 34 90 90 90
40682 - 62 62 62 38 38 38 22 22 22 14 14 14
40683 - 10 10 10 10 10 10 10 10 10 10 10 10
40684 - 10 10 10 10 10 10 6 6 6 10 10 10
40685 - 10 10 10 10 10 10 10 10 10 14 14 14
40686 - 22 22 22 42 42 42 70 70 70 89 81 66
40687 - 80 54 7 104 69 6 124 80 6 137 92 6
40688 -134 86 6 116 81 8 100 82 52 86 86 86
40689 - 58 58 58 30 30 30 14 14 14 6 6 6
40690 - 0 0 0 0 0 0 0 0 0 0 0 0
40691 - 0 0 0 0 0 0 0 0 0 0 0 0
40692 - 0 0 0 0 0 0 0 0 0 0 0 0
40693 - 0 0 0 0 0 0 0 0 0 0 0 0
40694 - 0 0 0 0 0 0 0 0 0 0 0 0
40695 - 0 0 0 0 0 0 0 0 0 0 0 0
40696 - 0 0 0 0 0 0 0 0 0 0 0 0
40697 - 0 0 0 0 0 0 0 0 0 0 0 0
40698 - 0 0 0 6 6 6 10 10 10 14 14 14
40699 - 18 18 18 26 26 26 38 38 38 54 54 54
40700 - 70 70 70 86 86 86 94 86 76 89 81 66
40701 - 89 81 66 86 86 86 74 74 74 50 50 50
40702 - 30 30 30 14 14 14 6 6 6 0 0 0
40703 - 0 0 0 0 0 0 0 0 0 0 0 0
40704 - 0 0 0 0 0 0 0 0 0 0 0 0
40705 - 0 0 0 0 0 0 0 0 0 0 0 0
40706 - 6 6 6 18 18 18 34 34 34 58 58 58
40707 - 82 82 82 89 81 66 89 81 66 89 81 66
40708 - 94 86 66 94 86 76 74 74 74 50 50 50
40709 - 26 26 26 14 14 14 6 6 6 0 0 0
40710 - 0 0 0 0 0 0 0 0 0 0 0 0
40711 - 0 0 0 0 0 0 0 0 0 0 0 0
40712 - 0 0 0 0 0 0 0 0 0 0 0 0
40713 - 0 0 0 0 0 0 0 0 0 0 0 0
40714 - 0 0 0 0 0 0 0 0 0 0 0 0
40715 - 0 0 0 0 0 0 0 0 0 0 0 0
40716 - 0 0 0 0 0 0 0 0 0 0 0 0
40717 - 0 0 0 0 0 0 0 0 0 0 0 0
40718 - 0 0 0 0 0 0 0 0 0 0 0 0
40719 - 6 6 6 6 6 6 14 14 14 18 18 18
40720 - 30 30 30 38 38 38 46 46 46 54 54 54
40721 - 50 50 50 42 42 42 30 30 30 18 18 18
40722 - 10 10 10 0 0 0 0 0 0 0 0 0
40723 - 0 0 0 0 0 0 0 0 0 0 0 0
40724 - 0 0 0 0 0 0 0 0 0 0 0 0
40725 - 0 0 0 0 0 0 0 0 0 0 0 0
40726 - 0 0 0 6 6 6 14 14 14 26 26 26
40727 - 38 38 38 50 50 50 58 58 58 58 58 58
40728 - 54 54 54 42 42 42 30 30 30 18 18 18
40729 - 10 10 10 0 0 0 0 0 0 0 0 0
40730 - 0 0 0 0 0 0 0 0 0 0 0 0
40731 - 0 0 0 0 0 0 0 0 0 0 0 0
40732 - 0 0 0 0 0 0 0 0 0 0 0 0
40733 - 0 0 0 0 0 0 0 0 0 0 0 0
40734 - 0 0 0 0 0 0 0 0 0 0 0 0
40735 - 0 0 0 0 0 0 0 0 0 0 0 0
40736 - 0 0 0 0 0 0 0 0 0 0 0 0
40737 - 0 0 0 0 0 0 0 0 0 0 0 0
40738 - 0 0 0 0 0 0 0 0 0 0 0 0
40739 - 0 0 0 0 0 0 0 0 0 6 6 6
40740 - 6 6 6 10 10 10 14 14 14 18 18 18
40741 - 18 18 18 14 14 14 10 10 10 6 6 6
40742 - 0 0 0 0 0 0 0 0 0 0 0 0
40743 - 0 0 0 0 0 0 0 0 0 0 0 0
40744 - 0 0 0 0 0 0 0 0 0 0 0 0
40745 - 0 0 0 0 0 0 0 0 0 0 0 0
40746 - 0 0 0 0 0 0 0 0 0 6 6 6
40747 - 14 14 14 18 18 18 22 22 22 22 22 22
40748 - 18 18 18 14 14 14 10 10 10 6 6 6
40749 - 0 0 0 0 0 0 0 0 0 0 0 0
40750 - 0 0 0 0 0 0 0 0 0 0 0 0
40751 - 0 0 0 0 0 0 0 0 0 0 0 0
40752 - 0 0 0 0 0 0 0 0 0 0 0 0
40753 - 0 0 0 0 0 0 0 0 0 0 0 0
40754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40767 +4 4 4 4 4 4
40768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40781 +4 4 4 4 4 4
40782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40795 +4 4 4 4 4 4
40796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40803 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40804 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40809 +4 4 4 4 4 4
40810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40812 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40817 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40818 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40823 +4 4 4 4 4 4
40824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40831 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40837 +4 4 4 4 4 4
40838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40842 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40843 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40845 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40847 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40848 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40849 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40851 +4 4 4 4 4 4
40852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40856 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40857 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40858 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40859 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40861 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40862 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40863 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40864 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40865 +4 4 4 4 4 4
40866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40870 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40871 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40872 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40873 +4 4 4 4 4 4 4 4 4 4 4 4 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 0 0 0 4 4 4 41 54 63 125 124 125
40876 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40877 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40878 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40879 +4 4 4 4 4 4
40880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40883 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40884 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40885 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40886 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40887 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40888 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40889 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40890 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40891 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40892 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40893 +4 4 4 4 4 4
40894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40897 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40898 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40899 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40900 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40901 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40902 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40903 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40904 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40905 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40906 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40907 +4 4 4 4 4 4
40908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40911 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40912 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40913 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40914 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40915 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40916 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40917 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40918 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40919 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40920 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40921 +4 4 4 4 4 4
40922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40924 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40925 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40926 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40927 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40928 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40929 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40930 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40931 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40932 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40933 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40934 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40935 +4 4 4 4 4 4
40936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40938 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40939 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40940 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40941 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40942 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40943 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40944 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40945 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40946 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40947 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40948 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40949 +4 4 4 4 4 4
40950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40952 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40953 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40954 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40955 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40956 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40957 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40958 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40959 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40960 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40961 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40962 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40963 +4 4 4 4 4 4
40964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40966 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40967 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40968 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40969 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40970 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40971 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40972 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40973 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40974 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40975 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40976 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40977 +4 4 4 4 4 4
40978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40979 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40980 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40981 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40982 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40983 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40984 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40985 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40986 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40987 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40988 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40989 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40990 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40991 +4 4 4 4 4 4
40992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40993 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40994 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40995 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40996 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40997 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40998 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40999 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41000 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41001 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41002 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41003 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41004 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41005 +0 0 0 4 4 4
41006 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41007 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41008 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41009 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41010 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41011 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41012 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41013 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41014 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41015 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41016 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41017 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41018 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41019 +2 0 0 0 0 0
41020 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41021 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41022 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41023 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41024 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41025 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41026 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41027 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41028 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41029 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41030 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41031 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41032 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41033 +37 38 37 0 0 0
41034 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41035 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41036 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41037 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41038 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41039 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41040 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41041 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41042 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41043 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41044 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41045 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41046 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41047 +85 115 134 4 0 0
41048 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41049 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41050 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41051 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41052 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41053 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41054 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41055 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41056 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41057 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41058 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41059 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41060 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41061 +60 73 81 4 0 0
41062 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41063 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41064 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41065 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41066 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41067 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41068 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41069 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41070 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41071 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41072 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41073 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41074 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41075 +16 19 21 4 0 0
41076 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41077 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41078 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41079 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41080 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41081 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41082 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41083 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41084 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41085 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41086 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41087 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41088 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41089 +4 0 0 4 3 3
41090 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41091 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41092 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41094 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41095 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41096 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41097 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41098 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41099 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41100 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41101 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41102 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41103 +3 2 2 4 4 4
41104 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41105 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41106 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41107 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41108 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41109 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41110 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41111 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41112 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41113 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41114 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41115 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41116 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41117 +4 4 4 4 4 4
41118 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41119 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41120 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41121 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41122 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41123 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41124 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41125 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41126 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41127 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41128 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41129 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41130 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41131 +4 4 4 4 4 4
41132 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41133 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41134 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41135 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41136 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41137 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41138 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41139 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41140 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41141 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41142 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41143 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41144 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41145 +5 5 5 5 5 5
41146 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41147 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41148 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41149 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41150 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41151 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41152 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41153 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41154 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41155 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41156 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41157 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41158 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41159 +5 5 5 4 4 4
41160 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41161 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41162 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41163 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41164 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41165 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41166 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41167 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41168 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41169 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41170 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41171 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41173 +4 4 4 4 4 4
41174 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41175 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41176 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41177 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41178 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41179 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41180 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41181 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41182 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41183 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41184 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41185 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41187 +4 4 4 4 4 4
41188 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41189 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41190 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41191 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41192 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41193 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41194 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41195 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41196 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41197 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41198 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41201 +4 4 4 4 4 4
41202 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41203 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41204 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41205 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41206 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41207 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41208 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41209 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41210 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41211 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41212 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41215 +4 4 4 4 4 4
41216 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41217 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41218 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41219 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41220 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41221 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41222 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41223 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41224 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41225 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41226 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41229 +4 4 4 4 4 4
41230 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41231 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41232 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41233 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41234 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41235 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41236 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41237 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41238 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41239 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41240 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41243 +4 4 4 4 4 4
41244 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41245 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41246 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41247 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41248 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41249 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41250 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41251 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41252 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41253 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41254 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41257 +4 4 4 4 4 4
41258 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41259 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41260 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41261 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41262 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41263 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41264 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41265 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41266 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41267 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41268 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41271 +4 4 4 4 4 4
41272 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41273 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41274 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41275 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41276 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41277 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41278 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41279 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41280 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41281 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41282 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41285 +4 4 4 4 4 4
41286 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41287 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41288 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41289 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41290 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41291 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41292 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41293 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41294 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41295 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41296 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41299 +4 4 4 4 4 4
41300 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41301 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41302 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41303 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41304 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41305 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41306 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41307 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41308 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41309 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41310 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41313 +4 4 4 4 4 4
41314 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41315 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41316 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41317 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41318 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41319 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41320 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41321 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41322 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41323 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41324 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41327 +4 4 4 4 4 4
41328 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41329 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41330 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41331 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41332 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41333 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41334 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41335 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41336 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41337 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41338 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41341 +4 4 4 4 4 4
41342 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41343 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41344 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41345 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41346 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41347 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41348 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41349 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41350 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41351 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41352 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41355 +4 4 4 4 4 4
41356 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41357 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41358 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41359 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41360 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41361 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41362 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41363 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41364 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41365 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41366 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41369 +4 4 4 4 4 4
41370 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41371 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41372 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41373 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41374 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41375 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41376 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41377 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41378 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41379 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41380 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41383 +4 4 4 4 4 4
41384 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41385 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41386 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41387 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41388 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41389 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41390 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41391 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41392 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41393 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41394 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41397 +4 4 4 4 4 4
41398 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41399 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41400 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41401 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41402 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41403 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41404 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41405 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41406 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41407 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41408 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41411 +4 4 4 4 4 4
41412 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41413 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41414 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41415 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41416 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41417 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41418 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41419 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41420 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41421 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41422 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41425 +4 4 4 4 4 4
41426 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41427 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41428 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41429 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41430 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41431 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41432 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41433 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41434 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41435 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41436 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41439 +4 4 4 4 4 4
41440 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41441 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41442 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41443 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41444 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41445 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41446 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41447 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41448 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41449 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41450 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41453 +4 4 4 4 4 4
41454 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41455 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41456 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41457 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41458 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41459 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41460 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41461 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41462 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41463 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41464 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41467 +4 4 4 4 4 4
41468 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41469 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41470 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41471 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41472 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41473 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41474 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41475 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41476 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41477 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41478 +0 0 0 3 3 3 5 5 5 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
41482 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41483 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41484 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41485 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41486 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41487 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41488 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41489 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41490 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41491 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41492 +0 0 0 3 3 3 5 5 5 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
41496 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41497 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41498 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41499 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41500 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41501 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41502 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41503 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41504 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41505 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41506 +0 0 0 3 3 3 5 5 5 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
41510 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41511 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41512 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41513 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41514 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41515 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41516 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41517 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41518 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41519 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41520 +0 0 0 3 3 3 5 5 5 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
41524 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41525 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41526 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41527 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41528 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41529 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41530 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41531 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41532 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41533 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41534 +0 0 0 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
41538 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41539 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41540 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41541 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41542 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41543 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41544 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41545 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41546 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41547 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41548 +4 3 3 5 5 5 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
41552 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41553 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41554 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41555 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41556 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41557 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41558 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41559 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41560 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41561 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41562 +5 5 5 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
41566 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41567 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41568 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41569 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41570 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41571 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41572 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41573 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41574 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41575 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41579 +4 4 4 4 4 4
41580 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41581 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41582 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41583 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41584 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41585 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41586 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41587 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41588 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41589 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41593 +4 4 4 4 4 4
41594 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41595 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41596 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41597 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41598 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41599 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41600 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41601 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41602 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41603 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41607 +4 4 4 4 4 4
41608 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41609 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41610 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41611 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41612 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41613 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41614 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41615 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41616 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41617 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41621 +4 4 4 4 4 4
41622 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41623 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41624 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41625 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41626 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41627 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41628 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41629 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41630 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41635 +4 4 4 4 4 4
41636 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41637 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41638 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41639 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41640 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41641 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41642 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41643 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41644 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41649 +4 4 4 4 4 4
41650 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41651 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41652 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41653 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41654 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41655 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41656 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41657 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41658 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41663 +4 4 4 4 4 4
41664 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41665 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41666 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41667 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41668 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41669 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41670 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41671 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41677 +4 4 4 4 4 4
41678 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41679 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41680 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41681 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41682 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41683 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41684 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41685 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41691 +4 4 4 4 4 4
41692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41693 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41694 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41695 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41696 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41697 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41698 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41699 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41705 +4 4 4 4 4 4
41706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41707 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41708 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41709 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41710 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41711 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41712 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41713 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41719 +4 4 4 4 4 4
41720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41721 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41722 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41723 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41724 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41725 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41726 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41727 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41733 +4 4 4 4 4 4
41734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41736 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41737 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41738 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41739 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41740 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41741 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41747 +4 4 4 4 4 4
41748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41751 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41752 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41753 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41754 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41761 +4 4 4 4 4 4
41762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41765 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41766 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41767 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41768 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41775 +4 4 4 4 4 4
41776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41779 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41780 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41781 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41782 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41789 +4 4 4 4 4 4
41790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41793 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41794 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41795 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41796 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41803 +4 4 4 4 4 4
41804 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41808 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41809 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41810 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41812 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41817 +4 4 4 4 4 4
41818 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41822 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41823 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41824 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41831 +4 4 4 4 4 4
41832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41836 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41837 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41838 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41845 +4 4 4 4 4 4
41846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41850 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41851 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41859 +4 4 4 4 4 4
41860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41864 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41865 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41873 +4 4 4 4 4 4
41874 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41875 index a40c05e..785c583 100644
41876 --- a/drivers/video/udlfb.c
41877 +++ b/drivers/video/udlfb.c
41878 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41879 dlfb_urb_completion(urb);
41880
41881 error:
41882 - atomic_add(bytes_sent, &dev->bytes_sent);
41883 - atomic_add(bytes_identical, &dev->bytes_identical);
41884 - atomic_add(width*height*2, &dev->bytes_rendered);
41885 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41886 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41887 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41888 end_cycles = get_cycles();
41889 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41890 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41891 >> 10)), /* Kcycles */
41892 &dev->cpu_kcycles_used);
41893
41894 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41895 dlfb_urb_completion(urb);
41896
41897 error:
41898 - atomic_add(bytes_sent, &dev->bytes_sent);
41899 - atomic_add(bytes_identical, &dev->bytes_identical);
41900 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41901 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41902 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41903 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41904 end_cycles = get_cycles();
41905 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41906 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41907 >> 10)), /* Kcycles */
41908 &dev->cpu_kcycles_used);
41909 }
41910 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41911 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41912 struct dlfb_data *dev = fb_info->par;
41913 return snprintf(buf, PAGE_SIZE, "%u\n",
41914 - atomic_read(&dev->bytes_rendered));
41915 + atomic_read_unchecked(&dev->bytes_rendered));
41916 }
41917
41918 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41919 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41920 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41921 struct dlfb_data *dev = fb_info->par;
41922 return snprintf(buf, PAGE_SIZE, "%u\n",
41923 - atomic_read(&dev->bytes_identical));
41924 + atomic_read_unchecked(&dev->bytes_identical));
41925 }
41926
41927 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41928 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41929 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41930 struct dlfb_data *dev = fb_info->par;
41931 return snprintf(buf, PAGE_SIZE, "%u\n",
41932 - atomic_read(&dev->bytes_sent));
41933 + atomic_read_unchecked(&dev->bytes_sent));
41934 }
41935
41936 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41937 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41938 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41939 struct dlfb_data *dev = fb_info->par;
41940 return snprintf(buf, PAGE_SIZE, "%u\n",
41941 - atomic_read(&dev->cpu_kcycles_used));
41942 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41943 }
41944
41945 static ssize_t edid_show(
41946 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41947 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41948 struct dlfb_data *dev = fb_info->par;
41949
41950 - atomic_set(&dev->bytes_rendered, 0);
41951 - atomic_set(&dev->bytes_identical, 0);
41952 - atomic_set(&dev->bytes_sent, 0);
41953 - atomic_set(&dev->cpu_kcycles_used, 0);
41954 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41955 + atomic_set_unchecked(&dev->bytes_identical, 0);
41956 + atomic_set_unchecked(&dev->bytes_sent, 0);
41957 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41958
41959 return count;
41960 }
41961 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41962 index 8408543..357841c 100644
41963 --- a/drivers/video/uvesafb.c
41964 +++ b/drivers/video/uvesafb.c
41965 @@ -19,6 +19,7 @@
41966 #include <linux/io.h>
41967 #include <linux/mutex.h>
41968 #include <linux/slab.h>
41969 +#include <linux/moduleloader.h>
41970 #include <video/edid.h>
41971 #include <video/uvesafb.h>
41972 #ifdef CONFIG_X86
41973 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
41974 NULL,
41975 };
41976
41977 - return call_usermodehelper(v86d_path, argv, envp, 1);
41978 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
41979 }
41980
41981 /*
41982 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41983 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41984 par->pmi_setpal = par->ypan = 0;
41985 } else {
41986 +
41987 +#ifdef CONFIG_PAX_KERNEXEC
41988 +#ifdef CONFIG_MODULES
41989 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41990 +#endif
41991 + if (!par->pmi_code) {
41992 + par->pmi_setpal = par->ypan = 0;
41993 + return 0;
41994 + }
41995 +#endif
41996 +
41997 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41998 + task->t.regs.edi);
41999 +
42000 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42001 + pax_open_kernel();
42002 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42003 + pax_close_kernel();
42004 +
42005 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42006 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42007 +#else
42008 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42009 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42010 +#endif
42011 +
42012 printk(KERN_INFO "uvesafb: protected mode interface info at "
42013 "%04x:%04x\n",
42014 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42015 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42016 par->ypan = ypan;
42017
42018 if (par->pmi_setpal || par->ypan) {
42019 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42020 if (__supported_pte_mask & _PAGE_NX) {
42021 par->pmi_setpal = par->ypan = 0;
42022 printk(KERN_WARNING "uvesafb: NX protection is actively."
42023 "We have better not to use the PMI.\n");
42024 - } else {
42025 + } else
42026 +#endif
42027 uvesafb_vbe_getpmi(task, par);
42028 - }
42029 }
42030 #else
42031 /* The protected mode interface is not available on non-x86. */
42032 @@ -1828,6 +1852,11 @@ out:
42033 if (par->vbe_modes)
42034 kfree(par->vbe_modes);
42035
42036 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42037 + if (par->pmi_code)
42038 + module_free_exec(NULL, par->pmi_code);
42039 +#endif
42040 +
42041 framebuffer_release(info);
42042 return err;
42043 }
42044 @@ -1854,6 +1883,12 @@ static int uvesafb_remove(struct platform_device *dev)
42045 kfree(par->vbe_state_orig);
42046 if (par->vbe_state_saved)
42047 kfree(par->vbe_state_saved);
42048 +
42049 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42050 + if (par->pmi_code)
42051 + module_free_exec(NULL, par->pmi_code);
42052 +#endif
42053 +
42054 }
42055
42056 framebuffer_release(info);
42057 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42058 index 501b340..86bd4cf 100644
42059 --- a/drivers/video/vesafb.c
42060 +++ b/drivers/video/vesafb.c
42061 @@ -9,6 +9,7 @@
42062 */
42063
42064 #include <linux/module.h>
42065 +#include <linux/moduleloader.h>
42066 #include <linux/kernel.h>
42067 #include <linux/errno.h>
42068 #include <linux/string.h>
42069 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42070 static int vram_total __initdata; /* Set total amount of memory */
42071 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42072 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42073 -static void (*pmi_start)(void) __read_mostly;
42074 -static void (*pmi_pal) (void) __read_mostly;
42075 +static void (*pmi_start)(void) __read_only;
42076 +static void (*pmi_pal) (void) __read_only;
42077 static int depth __read_mostly;
42078 static int vga_compat __read_mostly;
42079 /* --------------------------------------------------------------------- */
42080 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42081 unsigned int size_vmode;
42082 unsigned int size_remap;
42083 unsigned int size_total;
42084 + void *pmi_code = NULL;
42085
42086 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42087 return -ENODEV;
42088 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42089 size_remap = size_total;
42090 vesafb_fix.smem_len = size_remap;
42091
42092 -#ifndef __i386__
42093 - screen_info.vesapm_seg = 0;
42094 -#endif
42095 -
42096 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42097 printk(KERN_WARNING
42098 "vesafb: cannot reserve video memory at 0x%lx\n",
42099 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42100 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42101 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42102
42103 +#ifdef __i386__
42104 +
42105 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42106 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42107 + if (!pmi_code)
42108 +#elif !defined(CONFIG_PAX_KERNEXEC)
42109 + if (0)
42110 +#endif
42111 +
42112 +#endif
42113 + screen_info.vesapm_seg = 0;
42114 +
42115 if (screen_info.vesapm_seg) {
42116 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42117 - screen_info.vesapm_seg,screen_info.vesapm_off);
42118 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42119 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42120 }
42121
42122 if (screen_info.vesapm_seg < 0xc000)
42123 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42124
42125 if (ypan || pmi_setpal) {
42126 unsigned short *pmi_base;
42127 +
42128 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42129 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42130 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42131 +
42132 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42133 + pax_open_kernel();
42134 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42135 +#else
42136 + pmi_code = pmi_base;
42137 +#endif
42138 +
42139 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42140 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42141 +
42142 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42143 + pmi_start = ktva_ktla(pmi_start);
42144 + pmi_pal = ktva_ktla(pmi_pal);
42145 + pax_close_kernel();
42146 +#endif
42147 +
42148 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42149 if (pmi_base[3]) {
42150 printk(KERN_INFO "vesafb: pmi: ports = ");
42151 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42152 info->node, info->fix.id);
42153 return 0;
42154 err:
42155 +
42156 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42157 + module_free_exec(NULL, pmi_code);
42158 +#endif
42159 +
42160 if (info->screen_base)
42161 iounmap(info->screen_base);
42162 framebuffer_release(info);
42163 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42164 index 88714ae..16c2e11 100644
42165 --- a/drivers/video/via/via_clock.h
42166 +++ b/drivers/video/via/via_clock.h
42167 @@ -56,7 +56,7 @@ struct via_clock {
42168
42169 void (*set_engine_pll_state)(u8 state);
42170 void (*set_engine_pll)(struct via_pll_config config);
42171 -};
42172 +} __no_const;
42173
42174
42175 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42176 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42177 index e56c934..fc22f4b 100644
42178 --- a/drivers/xen/xen-pciback/conf_space.h
42179 +++ b/drivers/xen/xen-pciback/conf_space.h
42180 @@ -44,15 +44,15 @@ struct config_field {
42181 struct {
42182 conf_dword_write write;
42183 conf_dword_read read;
42184 - } dw;
42185 + } __no_const dw;
42186 struct {
42187 conf_word_write write;
42188 conf_word_read read;
42189 - } w;
42190 + } __no_const w;
42191 struct {
42192 conf_byte_write write;
42193 conf_byte_read read;
42194 - } b;
42195 + } __no_const b;
42196 } u;
42197 struct list_head list;
42198 };
42199 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42200 index 014c8dd..6f3dfe6 100644
42201 --- a/fs/9p/vfs_inode.c
42202 +++ b/fs/9p/vfs_inode.c
42203 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42204 void
42205 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42206 {
42207 - char *s = nd_get_link(nd);
42208 + const char *s = nd_get_link(nd);
42209
42210 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42211 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42212 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42213 index e95d1b6..3454244 100644
42214 --- a/fs/Kconfig.binfmt
42215 +++ b/fs/Kconfig.binfmt
42216 @@ -89,7 +89,7 @@ config HAVE_AOUT
42217
42218 config BINFMT_AOUT
42219 tristate "Kernel support for a.out and ECOFF binaries"
42220 - depends on HAVE_AOUT
42221 + depends on HAVE_AOUT && BROKEN
42222 ---help---
42223 A.out (Assembler.OUTput) is a set of formats for libraries and
42224 executables used in the earliest versions of UNIX. Linux used
42225 diff --git a/fs/aio.c b/fs/aio.c
42226 index b9d64d8..86cb1d5 100644
42227 --- a/fs/aio.c
42228 +++ b/fs/aio.c
42229 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42230 size += sizeof(struct io_event) * nr_events;
42231 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42232
42233 - if (nr_pages < 0)
42234 + if (nr_pages <= 0)
42235 return -EINVAL;
42236
42237 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42238 @@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42239 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42240 {
42241 ssize_t ret;
42242 + struct iovec iovstack;
42243
42244 #ifdef CONFIG_COMPAT
42245 if (compat)
42246 ret = compat_rw_copy_check_uvector(type,
42247 (struct compat_iovec __user *)kiocb->ki_buf,
42248 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42249 + kiocb->ki_nbytes, 1, &iovstack,
42250 &kiocb->ki_iovec, 1);
42251 else
42252 #endif
42253 ret = rw_copy_check_uvector(type,
42254 (struct iovec __user *)kiocb->ki_buf,
42255 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42256 + kiocb->ki_nbytes, 1, &iovstack,
42257 &kiocb->ki_iovec, 1);
42258 if (ret < 0)
42259 goto out;
42260
42261 + if (kiocb->ki_iovec == &iovstack) {
42262 + kiocb->ki_inline_vec = iovstack;
42263 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42264 + }
42265 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42266 kiocb->ki_cur_seg = 0;
42267 /* ki_nbytes/left now reflect bytes instead of segs */
42268 diff --git a/fs/attr.c b/fs/attr.c
42269 index 95053ad..2cc93ca 100644
42270 --- a/fs/attr.c
42271 +++ b/fs/attr.c
42272 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42273 unsigned long limit;
42274
42275 limit = rlimit(RLIMIT_FSIZE);
42276 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42277 if (limit != RLIM_INFINITY && offset > limit)
42278 goto out_sig;
42279 if (offset > inode->i_sb->s_maxbytes)
42280 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42281 index f624cd0..3d9a559 100644
42282 --- a/fs/autofs4/waitq.c
42283 +++ b/fs/autofs4/waitq.c
42284 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42285 {
42286 unsigned long sigpipe, flags;
42287 mm_segment_t fs;
42288 - const char *data = (const char *)addr;
42289 + const char __user *data = (const char __force_user *)addr;
42290 ssize_t wr = 0;
42291
42292 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42293 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42294 index 6e6d536..457113a 100644
42295 --- a/fs/befs/linuxvfs.c
42296 +++ b/fs/befs/linuxvfs.c
42297 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42298 {
42299 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42300 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42301 - char *link = nd_get_link(nd);
42302 + const char *link = nd_get_link(nd);
42303 if (!IS_ERR(link))
42304 kfree(link);
42305 }
42306 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42307 index 1ff9405..f1e376a 100644
42308 --- a/fs/binfmt_aout.c
42309 +++ b/fs/binfmt_aout.c
42310 @@ -16,6 +16,7 @@
42311 #include <linux/string.h>
42312 #include <linux/fs.h>
42313 #include <linux/file.h>
42314 +#include <linux/security.h>
42315 #include <linux/stat.h>
42316 #include <linux/fcntl.h>
42317 #include <linux/ptrace.h>
42318 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42319 #endif
42320 # define START_STACK(u) ((void __user *)u.start_stack)
42321
42322 + memset(&dump, 0, sizeof(dump));
42323 +
42324 fs = get_fs();
42325 set_fs(KERNEL_DS);
42326 has_dumped = 1;
42327 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42328
42329 /* If the size of the dump file exceeds the rlimit, then see what would happen
42330 if we wrote the stack, but not the data area. */
42331 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42332 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42333 dump.u_dsize = 0;
42334
42335 /* Make sure we have enough room to write the stack and data areas. */
42336 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42337 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42338 dump.u_ssize = 0;
42339
42340 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42341 rlim = rlimit(RLIMIT_DATA);
42342 if (rlim >= RLIM_INFINITY)
42343 rlim = ~0;
42344 +
42345 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42346 if (ex.a_data + ex.a_bss > rlim)
42347 return -ENOMEM;
42348
42349 @@ -269,6 +276,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42350 install_exec_creds(bprm);
42351 current->flags &= ~PF_FORKNOEXEC;
42352
42353 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42354 + current->mm->pax_flags = 0UL;
42355 +#endif
42356 +
42357 +#ifdef CONFIG_PAX_PAGEEXEC
42358 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42359 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42360 +
42361 +#ifdef CONFIG_PAX_EMUTRAMP
42362 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42363 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42364 +#endif
42365 +
42366 +#ifdef CONFIG_PAX_MPROTECT
42367 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42368 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42369 +#endif
42370 +
42371 + }
42372 +#endif
42373 +
42374 if (N_MAGIC(ex) == OMAGIC) {
42375 unsigned long text_addr, map_size;
42376 loff_t pos;
42377 @@ -341,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42378
42379 down_write(&current->mm->mmap_sem);
42380 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42381 - PROT_READ | PROT_WRITE | PROT_EXEC,
42382 + PROT_READ | PROT_WRITE,
42383 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42384 fd_offset + ex.a_text);
42385 up_write(&current->mm->mmap_sem);
42386 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42387 index 07d096c..25762af 100644
42388 --- a/fs/binfmt_elf.c
42389 +++ b/fs/binfmt_elf.c
42390 @@ -32,6 +32,7 @@
42391 #include <linux/elf.h>
42392 #include <linux/utsname.h>
42393 #include <linux/coredump.h>
42394 +#include <linux/xattr.h>
42395 #include <asm/uaccess.h>
42396 #include <asm/param.h>
42397 #include <asm/page.h>
42398 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42399 #define elf_core_dump NULL
42400 #endif
42401
42402 +#ifdef CONFIG_PAX_MPROTECT
42403 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42404 +#endif
42405 +
42406 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42407 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42408 #else
42409 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
42410 .load_binary = load_elf_binary,
42411 .load_shlib = load_elf_library,
42412 .core_dump = elf_core_dump,
42413 +
42414 +#ifdef CONFIG_PAX_MPROTECT
42415 + .handle_mprotect= elf_handle_mprotect,
42416 +#endif
42417 +
42418 .min_coredump = ELF_EXEC_PAGESIZE,
42419 };
42420
42421 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
42422
42423 static int set_brk(unsigned long start, unsigned long end)
42424 {
42425 + unsigned long e = end;
42426 +
42427 start = ELF_PAGEALIGN(start);
42428 end = ELF_PAGEALIGN(end);
42429 if (end > start) {
42430 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
42431 if (BAD_ADDR(addr))
42432 return addr;
42433 }
42434 - current->mm->start_brk = current->mm->brk = end;
42435 + current->mm->start_brk = current->mm->brk = e;
42436 return 0;
42437 }
42438
42439 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42440 elf_addr_t __user *u_rand_bytes;
42441 const char *k_platform = ELF_PLATFORM;
42442 const char *k_base_platform = ELF_BASE_PLATFORM;
42443 - unsigned char k_rand_bytes[16];
42444 + u32 k_rand_bytes[4];
42445 int items;
42446 elf_addr_t *elf_info;
42447 int ei_index = 0;
42448 const struct cred *cred = current_cred();
42449 struct vm_area_struct *vma;
42450 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42451
42452 /*
42453 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42454 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42455 * Generate 16 random bytes for userspace PRNG seeding.
42456 */
42457 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42458 - u_rand_bytes = (elf_addr_t __user *)
42459 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42460 + srandom32(k_rand_bytes[0] ^ random32());
42461 + srandom32(k_rand_bytes[1] ^ random32());
42462 + srandom32(k_rand_bytes[2] ^ random32());
42463 + srandom32(k_rand_bytes[3] ^ random32());
42464 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42465 + u_rand_bytes = (elf_addr_t __user *) p;
42466 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42467 return -EFAULT;
42468
42469 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42470 return -EFAULT;
42471 current->mm->env_end = p;
42472
42473 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42474 +
42475 /* Put the elf_info on the stack in the right place. */
42476 sp = (elf_addr_t __user *)envp + 1;
42477 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42478 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42479 return -EFAULT;
42480 return 0;
42481 }
42482 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42483 {
42484 struct elf_phdr *elf_phdata;
42485 struct elf_phdr *eppnt;
42486 - unsigned long load_addr = 0;
42487 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42488 int load_addr_set = 0;
42489 unsigned long last_bss = 0, elf_bss = 0;
42490 - unsigned long error = ~0UL;
42491 + unsigned long error = -EINVAL;
42492 unsigned long total_size;
42493 int retval, i, size;
42494
42495 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42496 goto out_close;
42497 }
42498
42499 +#ifdef CONFIG_PAX_SEGMEXEC
42500 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42501 + pax_task_size = SEGMEXEC_TASK_SIZE;
42502 +#endif
42503 +
42504 eppnt = elf_phdata;
42505 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42506 if (eppnt->p_type == PT_LOAD) {
42507 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42508 k = load_addr + eppnt->p_vaddr;
42509 if (BAD_ADDR(k) ||
42510 eppnt->p_filesz > eppnt->p_memsz ||
42511 - eppnt->p_memsz > TASK_SIZE ||
42512 - TASK_SIZE - eppnt->p_memsz < k) {
42513 + eppnt->p_memsz > pax_task_size ||
42514 + pax_task_size - eppnt->p_memsz < k) {
42515 error = -ENOMEM;
42516 goto out_close;
42517 }
42518 @@ -528,6 +552,351 @@ out:
42519 return error;
42520 }
42521
42522 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42523 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42524 +{
42525 + unsigned long pax_flags = 0UL;
42526 +
42527 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42528 +
42529 +#ifdef CONFIG_PAX_PAGEEXEC
42530 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42531 + pax_flags |= MF_PAX_PAGEEXEC;
42532 +#endif
42533 +
42534 +#ifdef CONFIG_PAX_SEGMEXEC
42535 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42536 + pax_flags |= MF_PAX_SEGMEXEC;
42537 +#endif
42538 +
42539 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42540 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42541 + if ((__supported_pte_mask & _PAGE_NX))
42542 + pax_flags &= ~MF_PAX_SEGMEXEC;
42543 + else
42544 + pax_flags &= ~MF_PAX_PAGEEXEC;
42545 + }
42546 +#endif
42547 +
42548 +#ifdef CONFIG_PAX_EMUTRAMP
42549 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42550 + pax_flags |= MF_PAX_EMUTRAMP;
42551 +#endif
42552 +
42553 +#ifdef CONFIG_PAX_MPROTECT
42554 + if (elf_phdata->p_flags & PF_MPROTECT)
42555 + pax_flags |= MF_PAX_MPROTECT;
42556 +#endif
42557 +
42558 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42559 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42560 + pax_flags |= MF_PAX_RANDMMAP;
42561 +#endif
42562 +
42563 +#endif
42564 +
42565 + return pax_flags;
42566 +}
42567 +
42568 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42569 +{
42570 + unsigned long pax_flags = 0UL;
42571 +
42572 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42573 +
42574 +#ifdef CONFIG_PAX_PAGEEXEC
42575 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42576 + pax_flags |= MF_PAX_PAGEEXEC;
42577 +#endif
42578 +
42579 +#ifdef CONFIG_PAX_SEGMEXEC
42580 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42581 + pax_flags |= MF_PAX_SEGMEXEC;
42582 +#endif
42583 +
42584 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42585 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42586 + if ((__supported_pte_mask & _PAGE_NX))
42587 + pax_flags &= ~MF_PAX_SEGMEXEC;
42588 + else
42589 + pax_flags &= ~MF_PAX_PAGEEXEC;
42590 + }
42591 +#endif
42592 +
42593 +#ifdef CONFIG_PAX_EMUTRAMP
42594 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42595 + pax_flags |= MF_PAX_EMUTRAMP;
42596 +#endif
42597 +
42598 +#ifdef CONFIG_PAX_MPROTECT
42599 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42600 + pax_flags |= MF_PAX_MPROTECT;
42601 +#endif
42602 +
42603 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42604 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42605 + pax_flags |= MF_PAX_RANDMMAP;
42606 +#endif
42607 +
42608 +#endif
42609 +
42610 + return pax_flags;
42611 +}
42612 +
42613 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42614 +{
42615 + unsigned long pax_flags = 0UL;
42616 +
42617 +#ifdef CONFIG_PAX_EI_PAX
42618 +
42619 +#ifdef CONFIG_PAX_PAGEEXEC
42620 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42621 + pax_flags |= MF_PAX_PAGEEXEC;
42622 +#endif
42623 +
42624 +#ifdef CONFIG_PAX_SEGMEXEC
42625 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42626 + pax_flags |= MF_PAX_SEGMEXEC;
42627 +#endif
42628 +
42629 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42630 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42631 + if ((__supported_pte_mask & _PAGE_NX))
42632 + pax_flags &= ~MF_PAX_SEGMEXEC;
42633 + else
42634 + pax_flags &= ~MF_PAX_PAGEEXEC;
42635 + }
42636 +#endif
42637 +
42638 +#ifdef CONFIG_PAX_EMUTRAMP
42639 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42640 + pax_flags |= MF_PAX_EMUTRAMP;
42641 +#endif
42642 +
42643 +#ifdef CONFIG_PAX_MPROTECT
42644 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42645 + pax_flags |= MF_PAX_MPROTECT;
42646 +#endif
42647 +
42648 +#ifdef CONFIG_PAX_ASLR
42649 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42650 + pax_flags |= MF_PAX_RANDMMAP;
42651 +#endif
42652 +
42653 +#else
42654 +
42655 +#ifdef CONFIG_PAX_PAGEEXEC
42656 + pax_flags |= MF_PAX_PAGEEXEC;
42657 +#endif
42658 +
42659 +#ifdef CONFIG_PAX_MPROTECT
42660 + pax_flags |= MF_PAX_MPROTECT;
42661 +#endif
42662 +
42663 +#ifdef CONFIG_PAX_RANDMMAP
42664 + pax_flags |= MF_PAX_RANDMMAP;
42665 +#endif
42666 +
42667 +#ifdef CONFIG_PAX_SEGMEXEC
42668 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
42669 + pax_flags &= ~MF_PAX_PAGEEXEC;
42670 + pax_flags |= MF_PAX_SEGMEXEC;
42671 + }
42672 +#endif
42673 +
42674 +#endif
42675 +
42676 + return pax_flags;
42677 +}
42678 +
42679 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42680 +{
42681 +
42682 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42683 + unsigned long i;
42684 +
42685 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42686 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42687 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42688 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42689 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42690 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42691 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42692 + return ~0UL;
42693 +
42694 +#ifdef CONFIG_PAX_SOFTMODE
42695 + if (pax_softmode)
42696 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42697 + else
42698 +#endif
42699 +
42700 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42701 + break;
42702 + }
42703 +#endif
42704 +
42705 + return ~0UL;
42706 +}
42707 +
42708 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42709 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42710 +{
42711 + unsigned long pax_flags = 0UL;
42712 +
42713 +#ifdef CONFIG_PAX_PAGEEXEC
42714 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42715 + pax_flags |= MF_PAX_PAGEEXEC;
42716 +#endif
42717 +
42718 +#ifdef CONFIG_PAX_SEGMEXEC
42719 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42720 + pax_flags |= MF_PAX_SEGMEXEC;
42721 +#endif
42722 +
42723 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42724 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42725 + if ((__supported_pte_mask & _PAGE_NX))
42726 + pax_flags &= ~MF_PAX_SEGMEXEC;
42727 + else
42728 + pax_flags &= ~MF_PAX_PAGEEXEC;
42729 + }
42730 +#endif
42731 +
42732 +#ifdef CONFIG_PAX_EMUTRAMP
42733 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42734 + pax_flags |= MF_PAX_EMUTRAMP;
42735 +#endif
42736 +
42737 +#ifdef CONFIG_PAX_MPROTECT
42738 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42739 + pax_flags |= MF_PAX_MPROTECT;
42740 +#endif
42741 +
42742 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42743 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42744 + pax_flags |= MF_PAX_RANDMMAP;
42745 +#endif
42746 +
42747 + return pax_flags;
42748 +}
42749 +
42750 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42751 +{
42752 + unsigned long pax_flags = 0UL;
42753 +
42754 +#ifdef CONFIG_PAX_PAGEEXEC
42755 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42756 + pax_flags |= MF_PAX_PAGEEXEC;
42757 +#endif
42758 +
42759 +#ifdef CONFIG_PAX_SEGMEXEC
42760 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42761 + pax_flags |= MF_PAX_SEGMEXEC;
42762 +#endif
42763 +
42764 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42765 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42766 + if ((__supported_pte_mask & _PAGE_NX))
42767 + pax_flags &= ~MF_PAX_SEGMEXEC;
42768 + else
42769 + pax_flags &= ~MF_PAX_PAGEEXEC;
42770 + }
42771 +#endif
42772 +
42773 +#ifdef CONFIG_PAX_EMUTRAMP
42774 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42775 + pax_flags |= MF_PAX_EMUTRAMP;
42776 +#endif
42777 +
42778 +#ifdef CONFIG_PAX_MPROTECT
42779 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42780 + pax_flags |= MF_PAX_MPROTECT;
42781 +#endif
42782 +
42783 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42784 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42785 + pax_flags |= MF_PAX_RANDMMAP;
42786 +#endif
42787 +
42788 + return pax_flags;
42789 +}
42790 +#endif
42791 +
42792 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42793 +{
42794 +
42795 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42796 + ssize_t xattr_size, i;
42797 + unsigned char xattr_value[5];
42798 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42799 +
42800 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42801 + if (xattr_size <= 0)
42802 + return ~0UL;
42803 +
42804 + for (i = 0; i < xattr_size; i++)
42805 + switch (xattr_value[i]) {
42806 + default:
42807 + return ~0UL;
42808 +
42809 +#define parse_flag(option1, option2, flag) \
42810 + case option1: \
42811 + pax_flags_hardmode |= MF_PAX_##flag; \
42812 + break; \
42813 + case option2: \
42814 + pax_flags_softmode |= MF_PAX_##flag; \
42815 + break;
42816 +
42817 + parse_flag('p', 'P', PAGEEXEC);
42818 + parse_flag('e', 'E', EMUTRAMP);
42819 + parse_flag('m', 'M', MPROTECT);
42820 + parse_flag('r', 'R', RANDMMAP);
42821 + parse_flag('s', 'S', SEGMEXEC);
42822 +
42823 +#undef parse_flag
42824 + }
42825 +
42826 + if (pax_flags_hardmode & pax_flags_softmode)
42827 + return ~0UL;
42828 +
42829 +#ifdef CONFIG_PAX_SOFTMODE
42830 + if (pax_softmode)
42831 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42832 + else
42833 +#endif
42834 +
42835 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42836 +#else
42837 + return ~0UL;
42838 +#endif
42839 +
42840 +}
42841 +
42842 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42843 +{
42844 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42845 +
42846 + pax_flags = pax_parse_ei_pax(elf_ex);
42847 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42848 + xattr_pax_flags = pax_parse_xattr_pax(file);
42849 +
42850 + if (pt_pax_flags == ~0UL)
42851 + pt_pax_flags = xattr_pax_flags;
42852 + else if (xattr_pax_flags == ~0UL)
42853 + xattr_pax_flags = pt_pax_flags;
42854 + if (pt_pax_flags != xattr_pax_flags)
42855 + return -EINVAL;
42856 + if (pt_pax_flags != ~0UL)
42857 + pax_flags = pt_pax_flags;
42858 +
42859 + if (0 > pax_check_flags(&pax_flags))
42860 + return -EINVAL;
42861 +
42862 + current->mm->pax_flags = pax_flags;
42863 + return 0;
42864 +}
42865 +#endif
42866 +
42867 /*
42868 * These are the functions used to load ELF style executables and shared
42869 * libraries. There is no binary dependent code anywhere else.
42870 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42871 {
42872 unsigned int random_variable = 0;
42873
42874 +#ifdef CONFIG_PAX_RANDUSTACK
42875 + if (randomize_va_space)
42876 + return stack_top - current->mm->delta_stack;
42877 +#endif
42878 +
42879 if ((current->flags & PF_RANDOMIZE) &&
42880 !(current->personality & ADDR_NO_RANDOMIZE)) {
42881 random_variable = get_random_int() & STACK_RND_MASK;
42882 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42883 unsigned long load_addr = 0, load_bias = 0;
42884 int load_addr_set = 0;
42885 char * elf_interpreter = NULL;
42886 - unsigned long error;
42887 + unsigned long error = 0;
42888 struct elf_phdr *elf_ppnt, *elf_phdata;
42889 unsigned long elf_bss, elf_brk;
42890 int retval, i;
42891 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42892 unsigned long start_code, end_code, start_data, end_data;
42893 unsigned long reloc_func_desc __maybe_unused = 0;
42894 int executable_stack = EXSTACK_DEFAULT;
42895 - unsigned long def_flags = 0;
42896 struct {
42897 struct elfhdr elf_ex;
42898 struct elfhdr interp_elf_ex;
42899 } *loc;
42900 + unsigned long pax_task_size = TASK_SIZE;
42901
42902 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42903 if (!loc) {
42904 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42905
42906 /* OK, This is the point of no return */
42907 current->flags &= ~PF_FORKNOEXEC;
42908 - current->mm->def_flags = def_flags;
42909 +
42910 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42911 + current->mm->pax_flags = 0UL;
42912 +#endif
42913 +
42914 +#ifdef CONFIG_PAX_DLRESOLVE
42915 + current->mm->call_dl_resolve = 0UL;
42916 +#endif
42917 +
42918 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42919 + current->mm->call_syscall = 0UL;
42920 +#endif
42921 +
42922 +#ifdef CONFIG_PAX_ASLR
42923 + current->mm->delta_mmap = 0UL;
42924 + current->mm->delta_stack = 0UL;
42925 +#endif
42926 +
42927 + current->mm->def_flags = 0;
42928 +
42929 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42930 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42931 + send_sig(SIGKILL, current, 0);
42932 + goto out_free_dentry;
42933 + }
42934 +#endif
42935 +
42936 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42937 + pax_set_initial_flags(bprm);
42938 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42939 + if (pax_set_initial_flags_func)
42940 + (pax_set_initial_flags_func)(bprm);
42941 +#endif
42942 +
42943 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42944 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42945 + current->mm->context.user_cs_limit = PAGE_SIZE;
42946 + current->mm->def_flags |= VM_PAGEEXEC;
42947 + }
42948 +#endif
42949 +
42950 +#ifdef CONFIG_PAX_SEGMEXEC
42951 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42952 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42953 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42954 + pax_task_size = SEGMEXEC_TASK_SIZE;
42955 + current->mm->def_flags |= VM_NOHUGEPAGE;
42956 + }
42957 +#endif
42958 +
42959 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42960 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42961 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42962 + put_cpu();
42963 + }
42964 +#endif
42965
42966 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42967 may depend on the personality. */
42968 SET_PERSONALITY(loc->elf_ex);
42969 +
42970 +#ifdef CONFIG_PAX_ASLR
42971 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42972 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42973 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42974 + }
42975 +#endif
42976 +
42977 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42978 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42979 + executable_stack = EXSTACK_DISABLE_X;
42980 + current->personality &= ~READ_IMPLIES_EXEC;
42981 + } else
42982 +#endif
42983 +
42984 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42985 current->personality |= READ_IMPLIES_EXEC;
42986
42987 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42988 #else
42989 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42990 #endif
42991 +
42992 +#ifdef CONFIG_PAX_RANDMMAP
42993 + /* PaX: randomize base address at the default exe base if requested */
42994 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42995 +#ifdef CONFIG_SPARC64
42996 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42997 +#else
42998 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42999 +#endif
43000 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43001 + elf_flags |= MAP_FIXED;
43002 + }
43003 +#endif
43004 +
43005 }
43006
43007 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43008 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43009 * allowed task size. Note that p_filesz must always be
43010 * <= p_memsz so it is only necessary to check p_memsz.
43011 */
43012 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43013 - elf_ppnt->p_memsz > TASK_SIZE ||
43014 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43015 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43016 + elf_ppnt->p_memsz > pax_task_size ||
43017 + pax_task_size - elf_ppnt->p_memsz < k) {
43018 /* set_brk can never work. Avoid overflows. */
43019 send_sig(SIGKILL, current, 0);
43020 retval = -EINVAL;
43021 @@ -881,11 +1339,40 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43022 goto out_free_dentry;
43023 }
43024 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43025 - send_sig(SIGSEGV, current, 0);
43026 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43027 - goto out_free_dentry;
43028 + /*
43029 + * This bss-zeroing can fail if the ELF
43030 + * file specifies odd protections. So
43031 + * we don't check the return value
43032 + */
43033 }
43034
43035 +#ifdef CONFIG_PAX_RANDMMAP
43036 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43037 + unsigned long start, size;
43038 +
43039 + start = ELF_PAGEALIGN(elf_brk);
43040 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43041 + down_write(&current->mm->mmap_sem);
43042 + retval = -ENOMEM;
43043 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43044 + unsigned long prot = PROT_NONE;
43045 +
43046 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43047 +// if (current->personality & ADDR_NO_RANDOMIZE)
43048 +// prot = PROT_READ;
43049 + start = do_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43050 + retval = IS_ERR_VALUE(start) ? start : 0;
43051 + }
43052 + up_write(&current->mm->mmap_sem);
43053 + if (retval == 0)
43054 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43055 + if (retval < 0) {
43056 + send_sig(SIGKILL, current, 0);
43057 + goto out_free_dentry;
43058 + }
43059 + }
43060 +#endif
43061 +
43062 if (elf_interpreter) {
43063 unsigned long uninitialized_var(interp_map_addr);
43064
43065 @@ -1098,7 +1585,7 @@ out:
43066 * Decide what to dump of a segment, part, all or none.
43067 */
43068 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43069 - unsigned long mm_flags)
43070 + unsigned long mm_flags, long signr)
43071 {
43072 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43073
43074 @@ -1132,7 +1619,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43075 if (vma->vm_file == NULL)
43076 return 0;
43077
43078 - if (FILTER(MAPPED_PRIVATE))
43079 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43080 goto whole;
43081
43082 /*
43083 @@ -1354,9 +1841,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43084 {
43085 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43086 int i = 0;
43087 - do
43088 + do {
43089 i += 2;
43090 - while (auxv[i - 2] != AT_NULL);
43091 + } while (auxv[i - 2] != AT_NULL);
43092 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43093 }
43094
43095 @@ -1862,14 +2349,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43096 }
43097
43098 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43099 - unsigned long mm_flags)
43100 + struct coredump_params *cprm)
43101 {
43102 struct vm_area_struct *vma;
43103 size_t size = 0;
43104
43105 for (vma = first_vma(current, gate_vma); vma != NULL;
43106 vma = next_vma(vma, gate_vma))
43107 - size += vma_dump_size(vma, mm_flags);
43108 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43109 return size;
43110 }
43111
43112 @@ -1963,7 +2450,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43113
43114 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43115
43116 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43117 + offset += elf_core_vma_data_size(gate_vma, cprm);
43118 offset += elf_core_extra_data_size();
43119 e_shoff = offset;
43120
43121 @@ -1977,10 +2464,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43122 offset = dataoff;
43123
43124 size += sizeof(*elf);
43125 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43126 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43127 goto end_coredump;
43128
43129 size += sizeof(*phdr4note);
43130 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43131 if (size > cprm->limit
43132 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43133 goto end_coredump;
43134 @@ -1994,7 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43135 phdr.p_offset = offset;
43136 phdr.p_vaddr = vma->vm_start;
43137 phdr.p_paddr = 0;
43138 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43139 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43140 phdr.p_memsz = vma->vm_end - vma->vm_start;
43141 offset += phdr.p_filesz;
43142 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43143 @@ -2005,6 +2494,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43144 phdr.p_align = ELF_EXEC_PAGESIZE;
43145
43146 size += sizeof(phdr);
43147 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43148 if (size > cprm->limit
43149 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43150 goto end_coredump;
43151 @@ -2029,7 +2519,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43152 unsigned long addr;
43153 unsigned long end;
43154
43155 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43156 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43157
43158 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43159 struct page *page;
43160 @@ -2038,6 +2528,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43161 page = get_dump_page(addr);
43162 if (page) {
43163 void *kaddr = kmap(page);
43164 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43165 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43166 !dump_write(cprm->file, kaddr,
43167 PAGE_SIZE);
43168 @@ -2055,6 +2546,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43169
43170 if (e_phnum == PN_XNUM) {
43171 size += sizeof(*shdr4extnum);
43172 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43173 if (size > cprm->limit
43174 || !dump_write(cprm->file, shdr4extnum,
43175 sizeof(*shdr4extnum)))
43176 @@ -2075,6 +2567,97 @@ out:
43177
43178 #endif /* CONFIG_ELF_CORE */
43179
43180 +#ifdef CONFIG_PAX_MPROTECT
43181 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43182 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43183 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43184 + *
43185 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43186 + * basis because we want to allow the common case and not the special ones.
43187 + */
43188 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43189 +{
43190 + struct elfhdr elf_h;
43191 + struct elf_phdr elf_p;
43192 + unsigned long i;
43193 + unsigned long oldflags;
43194 + bool is_textrel_rw, is_textrel_rx, is_relro;
43195 +
43196 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43197 + return;
43198 +
43199 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43200 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43201 +
43202 +#ifdef CONFIG_PAX_ELFRELOCS
43203 + /* possible TEXTREL */
43204 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43205 + 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);
43206 +#else
43207 + is_textrel_rw = false;
43208 + is_textrel_rx = false;
43209 +#endif
43210 +
43211 + /* possible RELRO */
43212 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43213 +
43214 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43215 + return;
43216 +
43217 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43218 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43219 +
43220 +#ifdef CONFIG_PAX_ETEXECRELOCS
43221 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43222 +#else
43223 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43224 +#endif
43225 +
43226 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43227 + !elf_check_arch(&elf_h) ||
43228 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43229 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43230 + return;
43231 +
43232 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43233 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43234 + return;
43235 + switch (elf_p.p_type) {
43236 + case PT_DYNAMIC:
43237 + if (!is_textrel_rw && !is_textrel_rx)
43238 + continue;
43239 + i = 0UL;
43240 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43241 + elf_dyn dyn;
43242 +
43243 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43244 + return;
43245 + if (dyn.d_tag == DT_NULL)
43246 + return;
43247 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43248 + gr_log_textrel(vma);
43249 + if (is_textrel_rw)
43250 + vma->vm_flags |= VM_MAYWRITE;
43251 + else
43252 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43253 + vma->vm_flags &= ~VM_MAYWRITE;
43254 + return;
43255 + }
43256 + i++;
43257 + }
43258 + return;
43259 +
43260 + case PT_GNU_RELRO:
43261 + if (!is_relro)
43262 + continue;
43263 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43264 + vma->vm_flags &= ~VM_MAYWRITE;
43265 + return;
43266 + }
43267 + }
43268 +}
43269 +#endif
43270 +
43271 static int __init init_elf_binfmt(void)
43272 {
43273 return register_binfmt(&elf_format);
43274 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43275 index 1bffbe0..c8c283e 100644
43276 --- a/fs/binfmt_flat.c
43277 +++ b/fs/binfmt_flat.c
43278 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43279 realdatastart = (unsigned long) -ENOMEM;
43280 printk("Unable to allocate RAM for process data, errno %d\n",
43281 (int)-realdatastart);
43282 + down_write(&current->mm->mmap_sem);
43283 do_munmap(current->mm, textpos, text_len);
43284 + up_write(&current->mm->mmap_sem);
43285 ret = realdatastart;
43286 goto err;
43287 }
43288 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43289 }
43290 if (IS_ERR_VALUE(result)) {
43291 printk("Unable to read data+bss, errno %d\n", (int)-result);
43292 + down_write(&current->mm->mmap_sem);
43293 do_munmap(current->mm, textpos, text_len);
43294 do_munmap(current->mm, realdatastart, len);
43295 + up_write(&current->mm->mmap_sem);
43296 ret = result;
43297 goto err;
43298 }
43299 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43300 }
43301 if (IS_ERR_VALUE(result)) {
43302 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43303 + down_write(&current->mm->mmap_sem);
43304 do_munmap(current->mm, textpos, text_len + data_len + extra +
43305 MAX_SHARED_LIBS * sizeof(unsigned long));
43306 + up_write(&current->mm->mmap_sem);
43307 ret = result;
43308 goto err;
43309 }
43310 diff --git a/fs/bio.c b/fs/bio.c
43311 index b980ecd..74800bf 100644
43312 --- a/fs/bio.c
43313 +++ b/fs/bio.c
43314 @@ -833,7 +833,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43315 /*
43316 * Overflow, abort
43317 */
43318 - if (end < start)
43319 + if (end < start || end - start > INT_MAX - nr_pages)
43320 return ERR_PTR(-EINVAL);
43321
43322 nr_pages += end - start;
43323 @@ -1229,7 +1229,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43324 const int read = bio_data_dir(bio) == READ;
43325 struct bio_map_data *bmd = bio->bi_private;
43326 int i;
43327 - char *p = bmd->sgvecs[0].iov_base;
43328 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43329
43330 __bio_for_each_segment(bvec, bio, i, 0) {
43331 char *addr = page_address(bvec->bv_page);
43332 diff --git a/fs/block_dev.c b/fs/block_dev.c
43333 index 5e9f198..6bf9b1c 100644
43334 --- a/fs/block_dev.c
43335 +++ b/fs/block_dev.c
43336 @@ -703,7 +703,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43337 else if (bdev->bd_contains == bdev)
43338 return true; /* is a whole device which isn't held */
43339
43340 - else if (whole->bd_holder == bd_may_claim)
43341 + else if (whole->bd_holder == (void *)bd_may_claim)
43342 return true; /* is a partition of a device that is being partitioned */
43343 else if (whole->bd_holder != NULL)
43344 return false; /* is a partition of a held device */
43345 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43346 index d986824..af1befd 100644
43347 --- a/fs/btrfs/check-integrity.c
43348 +++ b/fs/btrfs/check-integrity.c
43349 @@ -157,7 +157,7 @@ struct btrfsic_block {
43350 union {
43351 bio_end_io_t *bio;
43352 bh_end_io_t *bh;
43353 - } orig_bio_bh_end_io;
43354 + } __no_const orig_bio_bh_end_io;
43355 int submit_bio_bh_rw;
43356 u64 flush_gen; /* only valid if !never_written */
43357 };
43358 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43359 index 0639a55..7d9e07f 100644
43360 --- a/fs/btrfs/ctree.c
43361 +++ b/fs/btrfs/ctree.c
43362 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43363 free_extent_buffer(buf);
43364 add_root_to_dirty_list(root);
43365 } else {
43366 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43367 - parent_start = parent->start;
43368 - else
43369 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43370 + if (parent)
43371 + parent_start = parent->start;
43372 + else
43373 + parent_start = 0;
43374 + } else
43375 parent_start = 0;
43376
43377 WARN_ON(trans->transid != btrfs_header_generation(parent));
43378 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43379 index 892b347..b3db246 100644
43380 --- a/fs/btrfs/inode.c
43381 +++ b/fs/btrfs/inode.c
43382 @@ -6930,7 +6930,7 @@ fail:
43383 return -ENOMEM;
43384 }
43385
43386 -static int btrfs_getattr(struct vfsmount *mnt,
43387 +int btrfs_getattr(struct vfsmount *mnt,
43388 struct dentry *dentry, struct kstat *stat)
43389 {
43390 struct inode *inode = dentry->d_inode;
43391 @@ -6944,6 +6944,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43392 return 0;
43393 }
43394
43395 +EXPORT_SYMBOL(btrfs_getattr);
43396 +
43397 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43398 +{
43399 + return BTRFS_I(inode)->root->anon_dev;
43400 +}
43401 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43402 +
43403 /*
43404 * If a file is moved, it will inherit the cow and compression flags of the new
43405 * directory.
43406 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43407 index 1b36f19..5ac7360 100644
43408 --- a/fs/btrfs/ioctl.c
43409 +++ b/fs/btrfs/ioctl.c
43410 @@ -2783,9 +2783,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43411 for (i = 0; i < num_types; i++) {
43412 struct btrfs_space_info *tmp;
43413
43414 + /* Don't copy in more than we allocated */
43415 if (!slot_count)
43416 break;
43417
43418 + slot_count--;
43419 +
43420 info = NULL;
43421 rcu_read_lock();
43422 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43423 @@ -2807,15 +2810,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43424 memcpy(dest, &space, sizeof(space));
43425 dest++;
43426 space_args.total_spaces++;
43427 - slot_count--;
43428 }
43429 - if (!slot_count)
43430 - break;
43431 }
43432 up_read(&info->groups_sem);
43433 }
43434
43435 - user_dest = (struct btrfs_ioctl_space_info *)
43436 + user_dest = (struct btrfs_ioctl_space_info __user *)
43437 (arg + sizeof(struct btrfs_ioctl_space_args));
43438
43439 if (copy_to_user(user_dest, dest_orig, alloc_size))
43440 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43441 index 8c1aae2..1e46446 100644
43442 --- a/fs/btrfs/relocation.c
43443 +++ b/fs/btrfs/relocation.c
43444 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43445 }
43446 spin_unlock(&rc->reloc_root_tree.lock);
43447
43448 - BUG_ON((struct btrfs_root *)node->data != root);
43449 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43450
43451 if (!del) {
43452 spin_lock(&rc->reloc_root_tree.lock);
43453 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43454 index 622f469..e8d2d55 100644
43455 --- a/fs/cachefiles/bind.c
43456 +++ b/fs/cachefiles/bind.c
43457 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43458 args);
43459
43460 /* start by checking things over */
43461 - ASSERT(cache->fstop_percent >= 0 &&
43462 - cache->fstop_percent < cache->fcull_percent &&
43463 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43464 cache->fcull_percent < cache->frun_percent &&
43465 cache->frun_percent < 100);
43466
43467 - ASSERT(cache->bstop_percent >= 0 &&
43468 - cache->bstop_percent < cache->bcull_percent &&
43469 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43470 cache->bcull_percent < cache->brun_percent &&
43471 cache->brun_percent < 100);
43472
43473 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43474 index 0a1467b..6a53245 100644
43475 --- a/fs/cachefiles/daemon.c
43476 +++ b/fs/cachefiles/daemon.c
43477 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43478 if (n > buflen)
43479 return -EMSGSIZE;
43480
43481 - if (copy_to_user(_buffer, buffer, n) != 0)
43482 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43483 return -EFAULT;
43484
43485 return n;
43486 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43487 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43488 return -EIO;
43489
43490 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43491 + if (datalen > PAGE_SIZE - 1)
43492 return -EOPNOTSUPP;
43493
43494 /* drag the command string into the kernel so we can parse it */
43495 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43496 if (args[0] != '%' || args[1] != '\0')
43497 return -EINVAL;
43498
43499 - if (fstop < 0 || fstop >= cache->fcull_percent)
43500 + if (fstop >= cache->fcull_percent)
43501 return cachefiles_daemon_range_error(cache, args);
43502
43503 cache->fstop_percent = fstop;
43504 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43505 if (args[0] != '%' || args[1] != '\0')
43506 return -EINVAL;
43507
43508 - if (bstop < 0 || bstop >= cache->bcull_percent)
43509 + if (bstop >= cache->bcull_percent)
43510 return cachefiles_daemon_range_error(cache, args);
43511
43512 cache->bstop_percent = bstop;
43513 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43514 index bd6bc1b..b627b53 100644
43515 --- a/fs/cachefiles/internal.h
43516 +++ b/fs/cachefiles/internal.h
43517 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43518 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43519 struct rb_root active_nodes; /* active nodes (can't be culled) */
43520 rwlock_t active_lock; /* lock for active_nodes */
43521 - atomic_t gravecounter; /* graveyard uniquifier */
43522 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43523 unsigned frun_percent; /* when to stop culling (% files) */
43524 unsigned fcull_percent; /* when to start culling (% files) */
43525 unsigned fstop_percent; /* when to stop allocating (% files) */
43526 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43527 * proc.c
43528 */
43529 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43530 -extern atomic_t cachefiles_lookup_histogram[HZ];
43531 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43532 -extern atomic_t cachefiles_create_histogram[HZ];
43533 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43534 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43535 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43536
43537 extern int __init cachefiles_proc_init(void);
43538 extern void cachefiles_proc_cleanup(void);
43539 static inline
43540 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43541 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43542 {
43543 unsigned long jif = jiffies - start_jif;
43544 if (jif >= HZ)
43545 jif = HZ - 1;
43546 - atomic_inc(&histogram[jif]);
43547 + atomic_inc_unchecked(&histogram[jif]);
43548 }
43549
43550 #else
43551 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43552 index a0358c2..d6137f2 100644
43553 --- a/fs/cachefiles/namei.c
43554 +++ b/fs/cachefiles/namei.c
43555 @@ -318,7 +318,7 @@ try_again:
43556 /* first step is to make up a grave dentry in the graveyard */
43557 sprintf(nbuffer, "%08x%08x",
43558 (uint32_t) get_seconds(),
43559 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43560 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43561
43562 /* do the multiway lock magic */
43563 trap = lock_rename(cache->graveyard, dir);
43564 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43565 index eccd339..4c1d995 100644
43566 --- a/fs/cachefiles/proc.c
43567 +++ b/fs/cachefiles/proc.c
43568 @@ -14,9 +14,9 @@
43569 #include <linux/seq_file.h>
43570 #include "internal.h"
43571
43572 -atomic_t cachefiles_lookup_histogram[HZ];
43573 -atomic_t cachefiles_mkdir_histogram[HZ];
43574 -atomic_t cachefiles_create_histogram[HZ];
43575 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43576 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43577 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43578
43579 /*
43580 * display the latency histogram
43581 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43582 return 0;
43583 default:
43584 index = (unsigned long) v - 3;
43585 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43586 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43587 - z = atomic_read(&cachefiles_create_histogram[index]);
43588 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43589 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43590 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43591 if (x == 0 && y == 0 && z == 0)
43592 return 0;
43593
43594 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43595 index 0e3c092..818480e 100644
43596 --- a/fs/cachefiles/rdwr.c
43597 +++ b/fs/cachefiles/rdwr.c
43598 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43599 old_fs = get_fs();
43600 set_fs(KERNEL_DS);
43601 ret = file->f_op->write(
43602 - file, (const void __user *) data, len, &pos);
43603 + file, (const void __force_user *) data, len, &pos);
43604 set_fs(old_fs);
43605 kunmap(page);
43606 if (ret != len)
43607 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43608 index 3e8094b..cb3ff3d 100644
43609 --- a/fs/ceph/dir.c
43610 +++ b/fs/ceph/dir.c
43611 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43612 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43613 struct ceph_mds_client *mdsc = fsc->mdsc;
43614 unsigned frag = fpos_frag(filp->f_pos);
43615 - int off = fpos_off(filp->f_pos);
43616 + unsigned int off = fpos_off(filp->f_pos);
43617 int err;
43618 u32 ftype;
43619 struct ceph_mds_reply_info_parsed *rinfo;
43620 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43621 if (nd &&
43622 (nd->flags & LOOKUP_OPEN) &&
43623 !(nd->intent.open.flags & O_CREAT)) {
43624 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
43625 + int mode = nd->intent.open.create_mode & ~current_umask();
43626 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43627 }
43628
43629 diff --git a/fs/cifs/asn1.c b/fs/cifs/asn1.c
43630 index cfd1ce3..6b13a74 100644
43631 --- a/fs/cifs/asn1.c
43632 +++ b/fs/cifs/asn1.c
43633 @@ -416,6 +416,9 @@ asn1_subid_decode(struct asn1_ctx *ctx, unsigned long *subid)
43634
43635 static int
43636 asn1_oid_decode(struct asn1_ctx *ctx,
43637 + unsigned char *eoc, unsigned long **oid, unsigned int *len) __size_overflow(2);
43638 +static int
43639 +asn1_oid_decode(struct asn1_ctx *ctx,
43640 unsigned char *eoc, unsigned long **oid, unsigned int *len)
43641 {
43642 unsigned long subid;
43643 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43644 index 24b3dfc..3cd5454 100644
43645 --- a/fs/cifs/cifs_debug.c
43646 +++ b/fs/cifs/cifs_debug.c
43647 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43648
43649 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43650 #ifdef CONFIG_CIFS_STATS2
43651 - atomic_set(&totBufAllocCount, 0);
43652 - atomic_set(&totSmBufAllocCount, 0);
43653 + atomic_set_unchecked(&totBufAllocCount, 0);
43654 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43655 #endif /* CONFIG_CIFS_STATS2 */
43656 spin_lock(&cifs_tcp_ses_lock);
43657 list_for_each(tmp1, &cifs_tcp_ses_list) {
43658 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43659 tcon = list_entry(tmp3,
43660 struct cifs_tcon,
43661 tcon_list);
43662 - atomic_set(&tcon->num_smbs_sent, 0);
43663 - atomic_set(&tcon->num_writes, 0);
43664 - atomic_set(&tcon->num_reads, 0);
43665 - atomic_set(&tcon->num_oplock_brks, 0);
43666 - atomic_set(&tcon->num_opens, 0);
43667 - atomic_set(&tcon->num_posixopens, 0);
43668 - atomic_set(&tcon->num_posixmkdirs, 0);
43669 - atomic_set(&tcon->num_closes, 0);
43670 - atomic_set(&tcon->num_deletes, 0);
43671 - atomic_set(&tcon->num_mkdirs, 0);
43672 - atomic_set(&tcon->num_rmdirs, 0);
43673 - atomic_set(&tcon->num_renames, 0);
43674 - atomic_set(&tcon->num_t2renames, 0);
43675 - atomic_set(&tcon->num_ffirst, 0);
43676 - atomic_set(&tcon->num_fnext, 0);
43677 - atomic_set(&tcon->num_fclose, 0);
43678 - atomic_set(&tcon->num_hardlinks, 0);
43679 - atomic_set(&tcon->num_symlinks, 0);
43680 - atomic_set(&tcon->num_locks, 0);
43681 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43682 + atomic_set_unchecked(&tcon->num_writes, 0);
43683 + atomic_set_unchecked(&tcon->num_reads, 0);
43684 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43685 + atomic_set_unchecked(&tcon->num_opens, 0);
43686 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43687 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43688 + atomic_set_unchecked(&tcon->num_closes, 0);
43689 + atomic_set_unchecked(&tcon->num_deletes, 0);
43690 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43691 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43692 + atomic_set_unchecked(&tcon->num_renames, 0);
43693 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43694 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43695 + atomic_set_unchecked(&tcon->num_fnext, 0);
43696 + atomic_set_unchecked(&tcon->num_fclose, 0);
43697 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43698 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43699 + atomic_set_unchecked(&tcon->num_locks, 0);
43700 }
43701 }
43702 }
43703 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43704 smBufAllocCount.counter, cifs_min_small);
43705 #ifdef CONFIG_CIFS_STATS2
43706 seq_printf(m, "Total Large %d Small %d Allocations\n",
43707 - atomic_read(&totBufAllocCount),
43708 - atomic_read(&totSmBufAllocCount));
43709 + atomic_read_unchecked(&totBufAllocCount),
43710 + atomic_read_unchecked(&totSmBufAllocCount));
43711 #endif /* CONFIG_CIFS_STATS2 */
43712
43713 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43714 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43715 if (tcon->need_reconnect)
43716 seq_puts(m, "\tDISCONNECTED ");
43717 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43718 - atomic_read(&tcon->num_smbs_sent),
43719 - atomic_read(&tcon->num_oplock_brks));
43720 + atomic_read_unchecked(&tcon->num_smbs_sent),
43721 + atomic_read_unchecked(&tcon->num_oplock_brks));
43722 seq_printf(m, "\nReads: %d Bytes: %lld",
43723 - atomic_read(&tcon->num_reads),
43724 + atomic_read_unchecked(&tcon->num_reads),
43725 (long long)(tcon->bytes_read));
43726 seq_printf(m, "\nWrites: %d Bytes: %lld",
43727 - atomic_read(&tcon->num_writes),
43728 + atomic_read_unchecked(&tcon->num_writes),
43729 (long long)(tcon->bytes_written));
43730 seq_printf(m, "\nFlushes: %d",
43731 - atomic_read(&tcon->num_flushes));
43732 + atomic_read_unchecked(&tcon->num_flushes));
43733 seq_printf(m, "\nLocks: %d HardLinks: %d "
43734 "Symlinks: %d",
43735 - atomic_read(&tcon->num_locks),
43736 - atomic_read(&tcon->num_hardlinks),
43737 - atomic_read(&tcon->num_symlinks));
43738 + atomic_read_unchecked(&tcon->num_locks),
43739 + atomic_read_unchecked(&tcon->num_hardlinks),
43740 + atomic_read_unchecked(&tcon->num_symlinks));
43741 seq_printf(m, "\nOpens: %d Closes: %d "
43742 "Deletes: %d",
43743 - atomic_read(&tcon->num_opens),
43744 - atomic_read(&tcon->num_closes),
43745 - atomic_read(&tcon->num_deletes));
43746 + atomic_read_unchecked(&tcon->num_opens),
43747 + atomic_read_unchecked(&tcon->num_closes),
43748 + atomic_read_unchecked(&tcon->num_deletes));
43749 seq_printf(m, "\nPosix Opens: %d "
43750 "Posix Mkdirs: %d",
43751 - atomic_read(&tcon->num_posixopens),
43752 - atomic_read(&tcon->num_posixmkdirs));
43753 + atomic_read_unchecked(&tcon->num_posixopens),
43754 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43755 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43756 - atomic_read(&tcon->num_mkdirs),
43757 - atomic_read(&tcon->num_rmdirs));
43758 + atomic_read_unchecked(&tcon->num_mkdirs),
43759 + atomic_read_unchecked(&tcon->num_rmdirs));
43760 seq_printf(m, "\nRenames: %d T2 Renames %d",
43761 - atomic_read(&tcon->num_renames),
43762 - atomic_read(&tcon->num_t2renames));
43763 + atomic_read_unchecked(&tcon->num_renames),
43764 + atomic_read_unchecked(&tcon->num_t2renames));
43765 seq_printf(m, "\nFindFirst: %d FNext %d "
43766 "FClose %d",
43767 - atomic_read(&tcon->num_ffirst),
43768 - atomic_read(&tcon->num_fnext),
43769 - atomic_read(&tcon->num_fclose));
43770 + atomic_read_unchecked(&tcon->num_ffirst),
43771 + atomic_read_unchecked(&tcon->num_fnext),
43772 + atomic_read_unchecked(&tcon->num_fclose));
43773 }
43774 }
43775 }
43776 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43777 index 6ee1cb4..8443157 100644
43778 --- a/fs/cifs/cifsfs.c
43779 +++ b/fs/cifs/cifsfs.c
43780 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
43781 cifs_req_cachep = kmem_cache_create("cifs_request",
43782 CIFSMaxBufSize +
43783 MAX_CIFS_HDR_SIZE, 0,
43784 - SLAB_HWCACHE_ALIGN, NULL);
43785 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43786 if (cifs_req_cachep == NULL)
43787 return -ENOMEM;
43788
43789 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
43790 efficient to alloc 1 per page off the slab compared to 17K (5page)
43791 alloc of large cifs buffers even when page debugging is on */
43792 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43793 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43794 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43795 NULL);
43796 if (cifs_sm_req_cachep == NULL) {
43797 mempool_destroy(cifs_req_poolp);
43798 @@ -1101,8 +1101,8 @@ init_cifs(void)
43799 atomic_set(&bufAllocCount, 0);
43800 atomic_set(&smBufAllocCount, 0);
43801 #ifdef CONFIG_CIFS_STATS2
43802 - atomic_set(&totBufAllocCount, 0);
43803 - atomic_set(&totSmBufAllocCount, 0);
43804 + atomic_set_unchecked(&totBufAllocCount, 0);
43805 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43806 #endif /* CONFIG_CIFS_STATS2 */
43807
43808 atomic_set(&midCount, 0);
43809 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43810 index d47d20a..77e8b33 100644
43811 --- a/fs/cifs/cifsglob.h
43812 +++ b/fs/cifs/cifsglob.h
43813 @@ -388,28 +388,28 @@ struct cifs_tcon {
43814 __u16 Flags; /* optional support bits */
43815 enum statusEnum tidStatus;
43816 #ifdef CONFIG_CIFS_STATS
43817 - atomic_t num_smbs_sent;
43818 - atomic_t num_writes;
43819 - atomic_t num_reads;
43820 - atomic_t num_flushes;
43821 - atomic_t num_oplock_brks;
43822 - atomic_t num_opens;
43823 - atomic_t num_closes;
43824 - atomic_t num_deletes;
43825 - atomic_t num_mkdirs;
43826 - atomic_t num_posixopens;
43827 - atomic_t num_posixmkdirs;
43828 - atomic_t num_rmdirs;
43829 - atomic_t num_renames;
43830 - atomic_t num_t2renames;
43831 - atomic_t num_ffirst;
43832 - atomic_t num_fnext;
43833 - atomic_t num_fclose;
43834 - atomic_t num_hardlinks;
43835 - atomic_t num_symlinks;
43836 - atomic_t num_locks;
43837 - atomic_t num_acl_get;
43838 - atomic_t num_acl_set;
43839 + atomic_unchecked_t num_smbs_sent;
43840 + atomic_unchecked_t num_writes;
43841 + atomic_unchecked_t num_reads;
43842 + atomic_unchecked_t num_flushes;
43843 + atomic_unchecked_t num_oplock_brks;
43844 + atomic_unchecked_t num_opens;
43845 + atomic_unchecked_t num_closes;
43846 + atomic_unchecked_t num_deletes;
43847 + atomic_unchecked_t num_mkdirs;
43848 + atomic_unchecked_t num_posixopens;
43849 + atomic_unchecked_t num_posixmkdirs;
43850 + atomic_unchecked_t num_rmdirs;
43851 + atomic_unchecked_t num_renames;
43852 + atomic_unchecked_t num_t2renames;
43853 + atomic_unchecked_t num_ffirst;
43854 + atomic_unchecked_t num_fnext;
43855 + atomic_unchecked_t num_fclose;
43856 + atomic_unchecked_t num_hardlinks;
43857 + atomic_unchecked_t num_symlinks;
43858 + atomic_unchecked_t num_locks;
43859 + atomic_unchecked_t num_acl_get;
43860 + atomic_unchecked_t num_acl_set;
43861 #ifdef CONFIG_CIFS_STATS2
43862 unsigned long long time_writes;
43863 unsigned long long time_reads;
43864 @@ -624,7 +624,7 @@ convert_delimiter(char *path, char delim)
43865 }
43866
43867 #ifdef CONFIG_CIFS_STATS
43868 -#define cifs_stats_inc atomic_inc
43869 +#define cifs_stats_inc atomic_inc_unchecked
43870
43871 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43872 unsigned int bytes)
43873 @@ -983,8 +983,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43874 /* Various Debug counters */
43875 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43876 #ifdef CONFIG_CIFS_STATS2
43877 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43878 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43879 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43880 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43881 #endif
43882 GLOBAL_EXTERN atomic_t smBufAllocCount;
43883 GLOBAL_EXTERN atomic_t midCount;
43884 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43885 index 6b0e064..94e6c3c 100644
43886 --- a/fs/cifs/link.c
43887 +++ b/fs/cifs/link.c
43888 @@ -600,7 +600,7 @@ symlink_exit:
43889
43890 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43891 {
43892 - char *p = nd_get_link(nd);
43893 + const char *p = nd_get_link(nd);
43894 if (!IS_ERR(p))
43895 kfree(p);
43896 }
43897 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43898 index 703ef5c..2a44ed5 100644
43899 --- a/fs/cifs/misc.c
43900 +++ b/fs/cifs/misc.c
43901 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43902 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43903 atomic_inc(&bufAllocCount);
43904 #ifdef CONFIG_CIFS_STATS2
43905 - atomic_inc(&totBufAllocCount);
43906 + atomic_inc_unchecked(&totBufAllocCount);
43907 #endif /* CONFIG_CIFS_STATS2 */
43908 }
43909
43910 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43911 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43912 atomic_inc(&smBufAllocCount);
43913 #ifdef CONFIG_CIFS_STATS2
43914 - atomic_inc(&totSmBufAllocCount);
43915 + atomic_inc_unchecked(&totSmBufAllocCount);
43916 #endif /* CONFIG_CIFS_STATS2 */
43917
43918 }
43919 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43920 index 6901578..d402eb5 100644
43921 --- a/fs/coda/cache.c
43922 +++ b/fs/coda/cache.c
43923 @@ -24,7 +24,7 @@
43924 #include "coda_linux.h"
43925 #include "coda_cache.h"
43926
43927 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43928 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43929
43930 /* replace or extend an acl cache hit */
43931 void coda_cache_enter(struct inode *inode, int mask)
43932 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43933 struct coda_inode_info *cii = ITOC(inode);
43934
43935 spin_lock(&cii->c_lock);
43936 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43937 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43938 if (cii->c_uid != current_fsuid()) {
43939 cii->c_uid = current_fsuid();
43940 cii->c_cached_perm = mask;
43941 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43942 {
43943 struct coda_inode_info *cii = ITOC(inode);
43944 spin_lock(&cii->c_lock);
43945 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43946 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43947 spin_unlock(&cii->c_lock);
43948 }
43949
43950 /* remove all acl caches */
43951 void coda_cache_clear_all(struct super_block *sb)
43952 {
43953 - atomic_inc(&permission_epoch);
43954 + atomic_inc_unchecked(&permission_epoch);
43955 }
43956
43957
43958 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43959 spin_lock(&cii->c_lock);
43960 hit = (mask & cii->c_cached_perm) == mask &&
43961 cii->c_uid == current_fsuid() &&
43962 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43963 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43964 spin_unlock(&cii->c_lock);
43965
43966 return hit;
43967 diff --git a/fs/compat.c b/fs/compat.c
43968 index 07880ba..3fb2862 100644
43969 --- a/fs/compat.c
43970 +++ b/fs/compat.c
43971 @@ -491,7 +491,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43972
43973 set_fs(KERNEL_DS);
43974 /* The __user pointer cast is valid because of the set_fs() */
43975 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43976 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43977 set_fs(oldfs);
43978 /* truncating is ok because it's a user address */
43979 if (!ret)
43980 @@ -549,7 +549,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43981 goto out;
43982
43983 ret = -EINVAL;
43984 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43985 + if (nr_segs > UIO_MAXIOV)
43986 goto out;
43987 if (nr_segs > fast_segs) {
43988 ret = -ENOMEM;
43989 @@ -832,6 +832,7 @@ struct compat_old_linux_dirent {
43990
43991 struct compat_readdir_callback {
43992 struct compat_old_linux_dirent __user *dirent;
43993 + struct file * file;
43994 int result;
43995 };
43996
43997 @@ -849,6 +850,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43998 buf->result = -EOVERFLOW;
43999 return -EOVERFLOW;
44000 }
44001 +
44002 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44003 + return 0;
44004 +
44005 buf->result++;
44006 dirent = buf->dirent;
44007 if (!access_ok(VERIFY_WRITE, dirent,
44008 @@ -881,6 +886,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44009
44010 buf.result = 0;
44011 buf.dirent = dirent;
44012 + buf.file = file;
44013
44014 error = vfs_readdir(file, compat_fillonedir, &buf);
44015 if (buf.result)
44016 @@ -901,6 +907,7 @@ struct compat_linux_dirent {
44017 struct compat_getdents_callback {
44018 struct compat_linux_dirent __user *current_dir;
44019 struct compat_linux_dirent __user *previous;
44020 + struct file * file;
44021 int count;
44022 int error;
44023 };
44024 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44025 buf->error = -EOVERFLOW;
44026 return -EOVERFLOW;
44027 }
44028 +
44029 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44030 + return 0;
44031 +
44032 dirent = buf->previous;
44033 if (dirent) {
44034 if (__put_user(offset, &dirent->d_off))
44035 @@ -969,6 +980,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44036 buf.previous = NULL;
44037 buf.count = count;
44038 buf.error = 0;
44039 + buf.file = file;
44040
44041 error = vfs_readdir(file, compat_filldir, &buf);
44042 if (error >= 0)
44043 @@ -990,6 +1002,7 @@ out:
44044 struct compat_getdents_callback64 {
44045 struct linux_dirent64 __user *current_dir;
44046 struct linux_dirent64 __user *previous;
44047 + struct file * file;
44048 int count;
44049 int error;
44050 };
44051 @@ -1006,6 +1019,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44052 buf->error = -EINVAL; /* only used if we fail.. */
44053 if (reclen > buf->count)
44054 return -EINVAL;
44055 +
44056 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44057 + return 0;
44058 +
44059 dirent = buf->previous;
44060
44061 if (dirent) {
44062 @@ -1057,13 +1074,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44063 buf.previous = NULL;
44064 buf.count = count;
44065 buf.error = 0;
44066 + buf.file = file;
44067
44068 error = vfs_readdir(file, compat_filldir64, &buf);
44069 if (error >= 0)
44070 error = buf.error;
44071 lastdirent = buf.previous;
44072 if (lastdirent) {
44073 - typeof(lastdirent->d_off) d_off = file->f_pos;
44074 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44075 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44076 error = -EFAULT;
44077 else
44078 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44079 index 112e45a..b59845b 100644
44080 --- a/fs/compat_binfmt_elf.c
44081 +++ b/fs/compat_binfmt_elf.c
44082 @@ -30,11 +30,13 @@
44083 #undef elf_phdr
44084 #undef elf_shdr
44085 #undef elf_note
44086 +#undef elf_dyn
44087 #undef elf_addr_t
44088 #define elfhdr elf32_hdr
44089 #define elf_phdr elf32_phdr
44090 #define elf_shdr elf32_shdr
44091 #define elf_note elf32_note
44092 +#define elf_dyn Elf32_Dyn
44093 #define elf_addr_t Elf32_Addr
44094
44095 /*
44096 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44097 index a26bea1..ae23e72 100644
44098 --- a/fs/compat_ioctl.c
44099 +++ b/fs/compat_ioctl.c
44100 @@ -211,6 +211,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44101
44102 err = get_user(palp, &up->palette);
44103 err |= get_user(length, &up->length);
44104 + if (err)
44105 + return -EFAULT;
44106
44107 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44108 err = put_user(compat_ptr(palp), &up_native->palette);
44109 @@ -622,7 +624,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44110 return -EFAULT;
44111 if (__get_user(udata, &ss32->iomem_base))
44112 return -EFAULT;
44113 - ss.iomem_base = compat_ptr(udata);
44114 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44115 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44116 __get_user(ss.port_high, &ss32->port_high))
44117 return -EFAULT;
44118 @@ -797,7 +799,7 @@ static int compat_ioctl_preallocate(struct file *file,
44119 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44120 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44121 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44122 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44123 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44124 return -EFAULT;
44125
44126 return ioctl_preallocate(file, p);
44127 @@ -1611,8 +1613,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44128 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44129 {
44130 unsigned int a, b;
44131 - a = *(unsigned int *)p;
44132 - b = *(unsigned int *)q;
44133 + a = *(const unsigned int *)p;
44134 + b = *(const unsigned int *)q;
44135 if (a > b)
44136 return 1;
44137 if (a < b)
44138 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44139 index 5ddd7eb..c18bf04 100644
44140 --- a/fs/configfs/dir.c
44141 +++ b/fs/configfs/dir.c
44142 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44143 }
44144 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44145 struct configfs_dirent *next;
44146 - const char * name;
44147 + const unsigned char * name;
44148 + char d_name[sizeof(next->s_dentry->d_iname)];
44149 int len;
44150 struct inode *inode = NULL;
44151
44152 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44153 continue;
44154
44155 name = configfs_get_name(next);
44156 - len = strlen(name);
44157 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44158 + len = next->s_dentry->d_name.len;
44159 + memcpy(d_name, name, len);
44160 + name = d_name;
44161 + } else
44162 + len = strlen(name);
44163
44164 /*
44165 * We'll have a dentry and an inode for
44166 diff --git a/fs/configfs/file.c b/fs/configfs/file.c
44167 index 2b6cb23..d76e879 100644
44168 --- a/fs/configfs/file.c
44169 +++ b/fs/configfs/file.c
44170 @@ -135,6 +135,8 @@ out:
44171 */
44172
44173 static int
44174 +fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size_t count) __size_overflow(3);
44175 +static int
44176 fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size_t count)
44177 {
44178 int error;
44179 diff --git a/fs/dcache.c b/fs/dcache.c
44180 index 2576d14..0cec38d 100644
44181 --- a/fs/dcache.c
44182 +++ b/fs/dcache.c
44183 @@ -105,10 +105,10 @@ static unsigned int d_hash_shift __read_mostly;
44184 static struct hlist_bl_head *dentry_hashtable __read_mostly;
44185
44186 static inline struct hlist_bl_head *d_hash(const struct dentry *parent,
44187 - unsigned long hash)
44188 + unsigned int hash)
44189 {
44190 - hash += ((unsigned long) parent ^ GOLDEN_RATIO_PRIME) / L1_CACHE_BYTES;
44191 - hash = hash ^ ((hash ^ GOLDEN_RATIO_PRIME) >> D_HASHBITS);
44192 + hash += (unsigned long) parent / L1_CACHE_BYTES;
44193 + hash = hash + (hash >> D_HASHBITS);
44194 return dentry_hashtable + (hash & D_HASHMASK);
44195 }
44196
44197 @@ -3067,7 +3067,7 @@ void __init vfs_caches_init(unsigned long mempages)
44198 mempages -= reserve;
44199
44200 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44201 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44202 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44203
44204 dcache_init();
44205 inode_init();
44206 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44207 index 956d5dd..e755e04 100644
44208 --- a/fs/debugfs/inode.c
44209 +++ b/fs/debugfs/inode.c
44210 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44211 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44212 {
44213 return debugfs_create_file(name,
44214 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44215 + S_IFDIR | S_IRWXU,
44216 +#else
44217 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44218 +#endif
44219 parent, NULL, NULL);
44220 }
44221 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44222 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44223 index ab35b11..b30af66 100644
44224 --- a/fs/ecryptfs/inode.c
44225 +++ b/fs/ecryptfs/inode.c
44226 @@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44227 old_fs = get_fs();
44228 set_fs(get_ds());
44229 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44230 - (char __user *)lower_buf,
44231 + (char __force_user *)lower_buf,
44232 lower_bufsiz);
44233 set_fs(old_fs);
44234 if (rc < 0)
44235 @@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
44236 }
44237 old_fs = get_fs();
44238 set_fs(get_ds());
44239 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
44240 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
44241 set_fs(old_fs);
44242 if (rc < 0) {
44243 kfree(buf);
44244 @@ -733,7 +733,7 @@ out:
44245 static void
44246 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44247 {
44248 - char *buf = nd_get_link(nd);
44249 + const char *buf = nd_get_link(nd);
44250 if (!IS_ERR(buf)) {
44251 /* Free the char* */
44252 kfree(buf);
44253 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44254 index 3a06f40..f7af544 100644
44255 --- a/fs/ecryptfs/miscdev.c
44256 +++ b/fs/ecryptfs/miscdev.c
44257 @@ -345,7 +345,7 @@ check_list:
44258 goto out_unlock_msg_ctx;
44259 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44260 if (msg_ctx->msg) {
44261 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44262 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44263 goto out_unlock_msg_ctx;
44264 i += packet_length_size;
44265 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44266 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44267 index b2a34a1..162fa69 100644
44268 --- a/fs/ecryptfs/read_write.c
44269 +++ b/fs/ecryptfs/read_write.c
44270 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44271 return -EIO;
44272 fs_save = get_fs();
44273 set_fs(get_ds());
44274 - rc = vfs_write(lower_file, data, size, &offset);
44275 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44276 set_fs(fs_save);
44277 mark_inode_dirty_sync(ecryptfs_inode);
44278 return rc;
44279 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44280 return -EIO;
44281 fs_save = get_fs();
44282 set_fs(get_ds());
44283 - rc = vfs_read(lower_file, data, size, &offset);
44284 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44285 set_fs(fs_save);
44286 return rc;
44287 }
44288 diff --git a/fs/exec.c b/fs/exec.c
44289 index ae42277..32c9035 100644
44290 --- a/fs/exec.c
44291 +++ b/fs/exec.c
44292 @@ -55,6 +55,13 @@
44293 #include <linux/pipe_fs_i.h>
44294 #include <linux/oom.h>
44295 #include <linux/compat.h>
44296 +#include <linux/random.h>
44297 +#include <linux/seq_file.h>
44298 +
44299 +#ifdef CONFIG_PAX_REFCOUNT
44300 +#include <linux/kallsyms.h>
44301 +#include <linux/kdebug.h>
44302 +#endif
44303
44304 #include <asm/uaccess.h>
44305 #include <asm/mmu_context.h>
44306 @@ -63,6 +70,15 @@
44307 #include <trace/events/task.h>
44308 #include "internal.h"
44309
44310 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
44311 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
44312 +#endif
44313 +
44314 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44315 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44316 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44317 +#endif
44318 +
44319 int core_uses_pid;
44320 char core_pattern[CORENAME_MAX_SIZE] = "core";
44321 unsigned int core_pipe_limit;
44322 @@ -72,7 +88,7 @@ struct core_name {
44323 char *corename;
44324 int used, size;
44325 };
44326 -static atomic_t call_count = ATOMIC_INIT(1);
44327 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44328
44329 /* The maximal length of core_pattern is also specified in sysctl.c */
44330
44331 @@ -190,18 +206,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44332 int write)
44333 {
44334 struct page *page;
44335 - int ret;
44336
44337 -#ifdef CONFIG_STACK_GROWSUP
44338 - if (write) {
44339 - ret = expand_downwards(bprm->vma, pos);
44340 - if (ret < 0)
44341 - return NULL;
44342 - }
44343 -#endif
44344 - ret = get_user_pages(current, bprm->mm, pos,
44345 - 1, write, 1, &page, NULL);
44346 - if (ret <= 0)
44347 + if (0 > expand_downwards(bprm->vma, pos))
44348 + return NULL;
44349 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44350 return NULL;
44351
44352 if (write) {
44353 @@ -217,6 +225,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44354 if (size <= ARG_MAX)
44355 return page;
44356
44357 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44358 + // only allow 512KB for argv+env on suid/sgid binaries
44359 + // to prevent easy ASLR exhaustion
44360 + if (((bprm->cred->euid != current_euid()) ||
44361 + (bprm->cred->egid != current_egid())) &&
44362 + (size > (512 * 1024))) {
44363 + put_page(page);
44364 + return NULL;
44365 + }
44366 +#endif
44367 +
44368 /*
44369 * Limit to 1/4-th the stack size for the argv+env strings.
44370 * This ensures that:
44371 @@ -276,6 +295,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44372 vma->vm_end = STACK_TOP_MAX;
44373 vma->vm_start = vma->vm_end - PAGE_SIZE;
44374 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44375 +
44376 +#ifdef CONFIG_PAX_SEGMEXEC
44377 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44378 +#endif
44379 +
44380 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44381 INIT_LIST_HEAD(&vma->anon_vma_chain);
44382
44383 @@ -290,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44384 mm->stack_vm = mm->total_vm = 1;
44385 up_write(&mm->mmap_sem);
44386 bprm->p = vma->vm_end - sizeof(void *);
44387 +
44388 +#ifdef CONFIG_PAX_RANDUSTACK
44389 + if (randomize_va_space)
44390 + bprm->p ^= random32() & ~PAGE_MASK;
44391 +#endif
44392 +
44393 return 0;
44394 err:
44395 up_write(&mm->mmap_sem);
44396 @@ -398,19 +428,7 @@ err:
44397 return err;
44398 }
44399
44400 -struct user_arg_ptr {
44401 -#ifdef CONFIG_COMPAT
44402 - bool is_compat;
44403 -#endif
44404 - union {
44405 - const char __user *const __user *native;
44406 -#ifdef CONFIG_COMPAT
44407 - compat_uptr_t __user *compat;
44408 -#endif
44409 - } ptr;
44410 -};
44411 -
44412 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44413 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44414 {
44415 const char __user *native;
44416
44417 @@ -419,14 +437,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44418 compat_uptr_t compat;
44419
44420 if (get_user(compat, argv.ptr.compat + nr))
44421 - return ERR_PTR(-EFAULT);
44422 + return (const char __force_user *)ERR_PTR(-EFAULT);
44423
44424 return compat_ptr(compat);
44425 }
44426 #endif
44427
44428 if (get_user(native, argv.ptr.native + nr))
44429 - return ERR_PTR(-EFAULT);
44430 + return (const char __force_user *)ERR_PTR(-EFAULT);
44431
44432 return native;
44433 }
44434 @@ -445,7 +463,7 @@ static int count(struct user_arg_ptr argv, int max)
44435 if (!p)
44436 break;
44437
44438 - if (IS_ERR(p))
44439 + if (IS_ERR((const char __force_kernel *)p))
44440 return -EFAULT;
44441
44442 if (i++ >= max)
44443 @@ -479,7 +497,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44444
44445 ret = -EFAULT;
44446 str = get_user_arg_ptr(argv, argc);
44447 - if (IS_ERR(str))
44448 + if (IS_ERR((const char __force_kernel *)str))
44449 goto out;
44450
44451 len = strnlen_user(str, MAX_ARG_STRLEN);
44452 @@ -561,7 +579,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44453 int r;
44454 mm_segment_t oldfs = get_fs();
44455 struct user_arg_ptr argv = {
44456 - .ptr.native = (const char __user *const __user *)__argv,
44457 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44458 };
44459
44460 set_fs(KERNEL_DS);
44461 @@ -596,7 +614,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44462 unsigned long new_end = old_end - shift;
44463 struct mmu_gather tlb;
44464
44465 - BUG_ON(new_start > new_end);
44466 + if (new_start >= new_end || new_start < mmap_min_addr)
44467 + return -ENOMEM;
44468
44469 /*
44470 * ensure there are no vmas between where we want to go
44471 @@ -605,6 +624,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44472 if (vma != find_vma(mm, new_start))
44473 return -EFAULT;
44474
44475 +#ifdef CONFIG_PAX_SEGMEXEC
44476 + BUG_ON(pax_find_mirror_vma(vma));
44477 +#endif
44478 +
44479 /*
44480 * cover the whole range: [new_start, old_end)
44481 */
44482 @@ -685,10 +708,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44483 stack_top = arch_align_stack(stack_top);
44484 stack_top = PAGE_ALIGN(stack_top);
44485
44486 - if (unlikely(stack_top < mmap_min_addr) ||
44487 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44488 - return -ENOMEM;
44489 -
44490 stack_shift = vma->vm_end - stack_top;
44491
44492 bprm->p -= stack_shift;
44493 @@ -700,8 +719,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44494 bprm->exec -= stack_shift;
44495
44496 down_write(&mm->mmap_sem);
44497 +
44498 + /* Move stack pages down in memory. */
44499 + if (stack_shift) {
44500 + ret = shift_arg_pages(vma, stack_shift);
44501 + if (ret)
44502 + goto out_unlock;
44503 + }
44504 +
44505 vm_flags = VM_STACK_FLAGS;
44506
44507 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44508 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44509 + vm_flags &= ~VM_EXEC;
44510 +
44511 +#ifdef CONFIG_PAX_MPROTECT
44512 + if (mm->pax_flags & MF_PAX_MPROTECT)
44513 + vm_flags &= ~VM_MAYEXEC;
44514 +#endif
44515 +
44516 + }
44517 +#endif
44518 +
44519 /*
44520 * Adjust stack execute permissions; explicitly enable for
44521 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44522 @@ -720,13 +759,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44523 goto out_unlock;
44524 BUG_ON(prev != vma);
44525
44526 - /* Move stack pages down in memory. */
44527 - if (stack_shift) {
44528 - ret = shift_arg_pages(vma, stack_shift);
44529 - if (ret)
44530 - goto out_unlock;
44531 - }
44532 -
44533 /* mprotect_fixup is overkill to remove the temporary stack flags */
44534 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44535
44536 @@ -807,7 +839,7 @@ int kernel_read(struct file *file, loff_t offset,
44537 old_fs = get_fs();
44538 set_fs(get_ds());
44539 /* The cast to a user pointer is valid due to the set_fs() */
44540 - result = vfs_read(file, (void __user *)addr, count, &pos);
44541 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44542 set_fs(old_fs);
44543 return result;
44544 }
44545 @@ -1255,7 +1287,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44546 }
44547 rcu_read_unlock();
44548
44549 - if (p->fs->users > n_fs) {
44550 + if (atomic_read(&p->fs->users) > n_fs) {
44551 bprm->unsafe |= LSM_UNSAFE_SHARE;
44552 } else {
44553 res = -EAGAIN;
44554 @@ -1450,6 +1482,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44555
44556 EXPORT_SYMBOL(search_binary_handler);
44557
44558 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44559 +static DEFINE_PER_CPU(u64, exec_counter);
44560 +static int __init init_exec_counters(void)
44561 +{
44562 + unsigned int cpu;
44563 +
44564 + for_each_possible_cpu(cpu) {
44565 + per_cpu(exec_counter, cpu) = (u64)cpu;
44566 + }
44567 +
44568 + return 0;
44569 +}
44570 +early_initcall(init_exec_counters);
44571 +static inline void increment_exec_counter(void)
44572 +{
44573 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
44574 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44575 +}
44576 +#else
44577 +static inline void increment_exec_counter(void) {}
44578 +#endif
44579 +
44580 /*
44581 * sys_execve() executes a new program.
44582 */
44583 @@ -1458,6 +1512,11 @@ static int do_execve_common(const char *filename,
44584 struct user_arg_ptr envp,
44585 struct pt_regs *regs)
44586 {
44587 +#ifdef CONFIG_GRKERNSEC
44588 + struct file *old_exec_file;
44589 + struct acl_subject_label *old_acl;
44590 + struct rlimit old_rlim[RLIM_NLIMITS];
44591 +#endif
44592 struct linux_binprm *bprm;
44593 struct file *file;
44594 struct files_struct *displaced;
44595 @@ -1465,6 +1524,8 @@ static int do_execve_common(const char *filename,
44596 int retval;
44597 const struct cred *cred = current_cred();
44598
44599 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44600 +
44601 /*
44602 * We move the actual failure in case of RLIMIT_NPROC excess from
44603 * set*uid() to execve() because too many poorly written programs
44604 @@ -1505,12 +1566,27 @@ static int do_execve_common(const char *filename,
44605 if (IS_ERR(file))
44606 goto out_unmark;
44607
44608 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
44609 + retval = -EPERM;
44610 + goto out_file;
44611 + }
44612 +
44613 sched_exec();
44614
44615 bprm->file = file;
44616 bprm->filename = filename;
44617 bprm->interp = filename;
44618
44619 + if (gr_process_user_ban()) {
44620 + retval = -EPERM;
44621 + goto out_file;
44622 + }
44623 +
44624 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44625 + retval = -EACCES;
44626 + goto out_file;
44627 + }
44628 +
44629 retval = bprm_mm_init(bprm);
44630 if (retval)
44631 goto out_file;
44632 @@ -1527,24 +1603,65 @@ static int do_execve_common(const char *filename,
44633 if (retval < 0)
44634 goto out;
44635
44636 +#ifdef CONFIG_GRKERNSEC
44637 + old_acl = current->acl;
44638 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44639 + old_exec_file = current->exec_file;
44640 + get_file(file);
44641 + current->exec_file = file;
44642 +#endif
44643 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44644 + /* limit suid stack to 8MB
44645 + we saved the old limits above and will restore them if this exec fails
44646 + */
44647 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44648 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44649 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44650 +#endif
44651 +
44652 + if (!gr_tpe_allow(file)) {
44653 + retval = -EACCES;
44654 + goto out_fail;
44655 + }
44656 +
44657 + if (gr_check_crash_exec(file)) {
44658 + retval = -EACCES;
44659 + goto out_fail;
44660 + }
44661 +
44662 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44663 + bprm->unsafe);
44664 + if (retval < 0)
44665 + goto out_fail;
44666 +
44667 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44668 if (retval < 0)
44669 - goto out;
44670 + goto out_fail;
44671
44672 bprm->exec = bprm->p;
44673 retval = copy_strings(bprm->envc, envp, bprm);
44674 if (retval < 0)
44675 - goto out;
44676 + goto out_fail;
44677
44678 retval = copy_strings(bprm->argc, argv, bprm);
44679 if (retval < 0)
44680 - goto out;
44681 + goto out_fail;
44682 +
44683 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44684 +
44685 + gr_handle_exec_args(bprm, argv);
44686
44687 retval = search_binary_handler(bprm,regs);
44688 if (retval < 0)
44689 - goto out;
44690 + goto out_fail;
44691 +#ifdef CONFIG_GRKERNSEC
44692 + if (old_exec_file)
44693 + fput(old_exec_file);
44694 +#endif
44695
44696 /* execve succeeded */
44697 +
44698 + increment_exec_counter();
44699 current->fs->in_exec = 0;
44700 current->in_execve = 0;
44701 acct_update_integrals(current);
44702 @@ -1553,6 +1670,14 @@ static int do_execve_common(const char *filename,
44703 put_files_struct(displaced);
44704 return retval;
44705
44706 +out_fail:
44707 +#ifdef CONFIG_GRKERNSEC
44708 + current->acl = old_acl;
44709 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44710 + fput(current->exec_file);
44711 + current->exec_file = old_exec_file;
44712 +#endif
44713 +
44714 out:
44715 if (bprm->mm) {
44716 acct_arg_size(bprm, 0);
44717 @@ -1626,7 +1751,7 @@ static int expand_corename(struct core_name *cn)
44718 {
44719 char *old_corename = cn->corename;
44720
44721 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44722 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44723 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44724
44725 if (!cn->corename) {
44726 @@ -1723,7 +1848,7 @@ static int format_corename(struct core_name *cn, long signr)
44727 int pid_in_pattern = 0;
44728 int err = 0;
44729
44730 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44731 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44732 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44733 cn->used = 0;
44734
44735 @@ -1820,6 +1945,228 @@ out:
44736 return ispipe;
44737 }
44738
44739 +int pax_check_flags(unsigned long *flags)
44740 +{
44741 + int retval = 0;
44742 +
44743 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44744 + if (*flags & MF_PAX_SEGMEXEC)
44745 + {
44746 + *flags &= ~MF_PAX_SEGMEXEC;
44747 + retval = -EINVAL;
44748 + }
44749 +#endif
44750 +
44751 + if ((*flags & MF_PAX_PAGEEXEC)
44752 +
44753 +#ifdef CONFIG_PAX_PAGEEXEC
44754 + && (*flags & MF_PAX_SEGMEXEC)
44755 +#endif
44756 +
44757 + )
44758 + {
44759 + *flags &= ~MF_PAX_PAGEEXEC;
44760 + retval = -EINVAL;
44761 + }
44762 +
44763 + if ((*flags & MF_PAX_MPROTECT)
44764 +
44765 +#ifdef CONFIG_PAX_MPROTECT
44766 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44767 +#endif
44768 +
44769 + )
44770 + {
44771 + *flags &= ~MF_PAX_MPROTECT;
44772 + retval = -EINVAL;
44773 + }
44774 +
44775 + if ((*flags & MF_PAX_EMUTRAMP)
44776 +
44777 +#ifdef CONFIG_PAX_EMUTRAMP
44778 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44779 +#endif
44780 +
44781 + )
44782 + {
44783 + *flags &= ~MF_PAX_EMUTRAMP;
44784 + retval = -EINVAL;
44785 + }
44786 +
44787 + return retval;
44788 +}
44789 +
44790 +EXPORT_SYMBOL(pax_check_flags);
44791 +
44792 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44793 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44794 +{
44795 + struct task_struct *tsk = current;
44796 + struct mm_struct *mm = current->mm;
44797 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44798 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44799 + char *path_exec = NULL;
44800 + char *path_fault = NULL;
44801 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44802 +
44803 + if (buffer_exec && buffer_fault) {
44804 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44805 +
44806 + down_read(&mm->mmap_sem);
44807 + vma = mm->mmap;
44808 + while (vma && (!vma_exec || !vma_fault)) {
44809 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44810 + vma_exec = vma;
44811 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44812 + vma_fault = vma;
44813 + vma = vma->vm_next;
44814 + }
44815 + if (vma_exec) {
44816 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44817 + if (IS_ERR(path_exec))
44818 + path_exec = "<path too long>";
44819 + else {
44820 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44821 + if (path_exec) {
44822 + *path_exec = 0;
44823 + path_exec = buffer_exec;
44824 + } else
44825 + path_exec = "<path too long>";
44826 + }
44827 + }
44828 + if (vma_fault) {
44829 + start = vma_fault->vm_start;
44830 + end = vma_fault->vm_end;
44831 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44832 + if (vma_fault->vm_file) {
44833 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44834 + if (IS_ERR(path_fault))
44835 + path_fault = "<path too long>";
44836 + else {
44837 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44838 + if (path_fault) {
44839 + *path_fault = 0;
44840 + path_fault = buffer_fault;
44841 + } else
44842 + path_fault = "<path too long>";
44843 + }
44844 + } else
44845 + path_fault = "<anonymous mapping>";
44846 + }
44847 + up_read(&mm->mmap_sem);
44848 + }
44849 + if (tsk->signal->curr_ip)
44850 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44851 + else
44852 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44853 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44854 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44855 + task_uid(tsk), task_euid(tsk), pc, sp);
44856 + free_page((unsigned long)buffer_exec);
44857 + free_page((unsigned long)buffer_fault);
44858 + pax_report_insns(regs, pc, sp);
44859 + do_coredump(SIGKILL, SIGKILL, regs);
44860 +}
44861 +#endif
44862 +
44863 +#ifdef CONFIG_PAX_REFCOUNT
44864 +void pax_report_refcount_overflow(struct pt_regs *regs)
44865 +{
44866 + if (current->signal->curr_ip)
44867 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44868 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44869 + else
44870 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44871 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44872 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44873 + show_regs(regs);
44874 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44875 +}
44876 +#endif
44877 +
44878 +#ifdef CONFIG_PAX_USERCOPY
44879 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44880 +int object_is_on_stack(const void *obj, unsigned long len)
44881 +{
44882 + const void * const stack = task_stack_page(current);
44883 + const void * const stackend = stack + THREAD_SIZE;
44884 +
44885 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44886 + const void *frame = NULL;
44887 + const void *oldframe;
44888 +#endif
44889 +
44890 + if (obj + len < obj)
44891 + return -1;
44892 +
44893 + if (obj + len <= stack || stackend <= obj)
44894 + return 0;
44895 +
44896 + if (obj < stack || stackend < obj + len)
44897 + return -1;
44898 +
44899 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44900 + oldframe = __builtin_frame_address(1);
44901 + if (oldframe)
44902 + frame = __builtin_frame_address(2);
44903 + /*
44904 + low ----------------------------------------------> high
44905 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44906 + ^----------------^
44907 + allow copies only within here
44908 + */
44909 + while (stack <= frame && frame < stackend) {
44910 + /* if obj + len extends past the last frame, this
44911 + check won't pass and the next frame will be 0,
44912 + causing us to bail out and correctly report
44913 + the copy as invalid
44914 + */
44915 + if (obj + len <= frame)
44916 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44917 + oldframe = frame;
44918 + frame = *(const void * const *)frame;
44919 + }
44920 + return -1;
44921 +#else
44922 + return 1;
44923 +#endif
44924 +}
44925 +
44926 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44927 +{
44928 + if (current->signal->curr_ip)
44929 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44930 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44931 + else
44932 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44933 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44934 + dump_stack();
44935 + gr_handle_kernel_exploit();
44936 + do_group_exit(SIGKILL);
44937 +}
44938 +#endif
44939 +
44940 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44941 +void pax_track_stack(void)
44942 +{
44943 + unsigned long sp = (unsigned long)&sp;
44944 + if (sp < current_thread_info()->lowest_stack &&
44945 + sp > (unsigned long)task_stack_page(current))
44946 + current_thread_info()->lowest_stack = sp;
44947 +}
44948 +EXPORT_SYMBOL(pax_track_stack);
44949 +#endif
44950 +
44951 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
44952 +void report_size_overflow(const char *file, unsigned int line, const char *func)
44953 +{
44954 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44955 + dump_stack();
44956 + do_group_exit(SIGKILL);
44957 +}
44958 +EXPORT_SYMBOL(report_size_overflow);
44959 +#endif
44960 +
44961 static int zap_process(struct task_struct *start, int exit_code)
44962 {
44963 struct task_struct *t;
44964 @@ -2017,17 +2364,17 @@ static void wait_for_dump_helpers(struct file *file)
44965 pipe = file->f_path.dentry->d_inode->i_pipe;
44966
44967 pipe_lock(pipe);
44968 - pipe->readers++;
44969 - pipe->writers--;
44970 + atomic_inc(&pipe->readers);
44971 + atomic_dec(&pipe->writers);
44972
44973 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44974 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44975 wake_up_interruptible_sync(&pipe->wait);
44976 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44977 pipe_wait(pipe);
44978 }
44979
44980 - pipe->readers--;
44981 - pipe->writers++;
44982 + atomic_dec(&pipe->readers);
44983 + atomic_inc(&pipe->writers);
44984 pipe_unlock(pipe);
44985
44986 }
44987 @@ -2088,7 +2435,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44988 int retval = 0;
44989 int flag = 0;
44990 int ispipe;
44991 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44992 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44993 struct coredump_params cprm = {
44994 .signr = signr,
44995 .regs = regs,
44996 @@ -2103,6 +2450,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44997
44998 audit_core_dumps(signr);
44999
45000 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45001 + gr_handle_brute_attach(current, cprm.mm_flags);
45002 +
45003 binfmt = mm->binfmt;
45004 if (!binfmt || !binfmt->core_dump)
45005 goto fail;
45006 @@ -2170,7 +2520,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45007 }
45008 cprm.limit = RLIM_INFINITY;
45009
45010 - dump_count = atomic_inc_return(&core_dump_count);
45011 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45012 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45013 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45014 task_tgid_vnr(current), current->comm);
45015 @@ -2197,6 +2547,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45016 } else {
45017 struct inode *inode;
45018
45019 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45020 +
45021 if (cprm.limit < binfmt->min_coredump)
45022 goto fail_unlock;
45023
45024 @@ -2240,7 +2592,7 @@ close_fail:
45025 filp_close(cprm.file, NULL);
45026 fail_dropcount:
45027 if (ispipe)
45028 - atomic_dec(&core_dump_count);
45029 + atomic_dec_unchecked(&core_dump_count);
45030 fail_unlock:
45031 kfree(cn.corename);
45032 fail_corename:
45033 @@ -2259,7 +2611,7 @@ fail:
45034 */
45035 int dump_write(struct file *file, const void *addr, int nr)
45036 {
45037 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45038 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45039 }
45040 EXPORT_SYMBOL(dump_write);
45041
45042 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45043 index a8cbe1b..fed04cb 100644
45044 --- a/fs/ext2/balloc.c
45045 +++ b/fs/ext2/balloc.c
45046 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45047
45048 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45049 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45050 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45051 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45052 sbi->s_resuid != current_fsuid() &&
45053 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45054 return 0;
45055 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45056 index a203892..4e64db5 100644
45057 --- a/fs/ext3/balloc.c
45058 +++ b/fs/ext3/balloc.c
45059 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45060
45061 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45062 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45063 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45064 + if (free_blocks < root_blocks + 1 &&
45065 !use_reservation && sbi->s_resuid != current_fsuid() &&
45066 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45067 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
45068 + !capable_nolog(CAP_SYS_RESOURCE)) {
45069 return 0;
45070 }
45071 return 1;
45072 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45073 index f9e2cd8..bfdc476 100644
45074 --- a/fs/ext4/balloc.c
45075 +++ b/fs/ext4/balloc.c
45076 @@ -438,8 +438,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45077 /* Hm, nope. Are (enough) root reserved clusters available? */
45078 if (sbi->s_resuid == current_fsuid() ||
45079 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
45080 - capable(CAP_SYS_RESOURCE) ||
45081 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45082 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45083 + capable_nolog(CAP_SYS_RESOURCE)) {
45084
45085 if (free_clusters >= (nclusters + dirty_clusters))
45086 return 1;
45087 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45088 index 9983ba8..2a5272c 100644
45089 --- a/fs/ext4/ext4.h
45090 +++ b/fs/ext4/ext4.h
45091 @@ -1217,19 +1217,19 @@ struct ext4_sb_info {
45092 unsigned long s_mb_last_start;
45093
45094 /* stats for buddy allocator */
45095 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45096 - atomic_t s_bal_success; /* we found long enough chunks */
45097 - atomic_t s_bal_allocated; /* in blocks */
45098 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45099 - atomic_t s_bal_goals; /* goal hits */
45100 - atomic_t s_bal_breaks; /* too long searches */
45101 - atomic_t s_bal_2orders; /* 2^order hits */
45102 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45103 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45104 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45105 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45106 + atomic_unchecked_t s_bal_goals; /* goal hits */
45107 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45108 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45109 spinlock_t s_bal_lock;
45110 unsigned long s_mb_buddies_generated;
45111 unsigned long long s_mb_generation_time;
45112 - atomic_t s_mb_lost_chunks;
45113 - atomic_t s_mb_preallocated;
45114 - atomic_t s_mb_discarded;
45115 + atomic_unchecked_t s_mb_lost_chunks;
45116 + atomic_unchecked_t s_mb_preallocated;
45117 + atomic_unchecked_t s_mb_discarded;
45118 atomic_t s_lock_busy;
45119
45120 /* locality groups */
45121 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45122 index cb990b2..4820141 100644
45123 --- a/fs/ext4/mballoc.c
45124 +++ b/fs/ext4/mballoc.c
45125 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45126 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45127
45128 if (EXT4_SB(sb)->s_mb_stats)
45129 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45130 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45131
45132 break;
45133 }
45134 @@ -2088,7 +2088,7 @@ repeat:
45135 ac->ac_status = AC_STATUS_CONTINUE;
45136 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45137 cr = 3;
45138 - atomic_inc(&sbi->s_mb_lost_chunks);
45139 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45140 goto repeat;
45141 }
45142 }
45143 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
45144 if (sbi->s_mb_stats) {
45145 ext4_msg(sb, KERN_INFO,
45146 "mballoc: %u blocks %u reqs (%u success)",
45147 - atomic_read(&sbi->s_bal_allocated),
45148 - atomic_read(&sbi->s_bal_reqs),
45149 - atomic_read(&sbi->s_bal_success));
45150 + atomic_read_unchecked(&sbi->s_bal_allocated),
45151 + atomic_read_unchecked(&sbi->s_bal_reqs),
45152 + atomic_read_unchecked(&sbi->s_bal_success));
45153 ext4_msg(sb, KERN_INFO,
45154 "mballoc: %u extents scanned, %u goal hits, "
45155 "%u 2^N hits, %u breaks, %u lost",
45156 - atomic_read(&sbi->s_bal_ex_scanned),
45157 - atomic_read(&sbi->s_bal_goals),
45158 - atomic_read(&sbi->s_bal_2orders),
45159 - atomic_read(&sbi->s_bal_breaks),
45160 - atomic_read(&sbi->s_mb_lost_chunks));
45161 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45162 + atomic_read_unchecked(&sbi->s_bal_goals),
45163 + atomic_read_unchecked(&sbi->s_bal_2orders),
45164 + atomic_read_unchecked(&sbi->s_bal_breaks),
45165 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45166 ext4_msg(sb, KERN_INFO,
45167 "mballoc: %lu generated and it took %Lu",
45168 sbi->s_mb_buddies_generated,
45169 sbi->s_mb_generation_time);
45170 ext4_msg(sb, KERN_INFO,
45171 "mballoc: %u preallocated, %u discarded",
45172 - atomic_read(&sbi->s_mb_preallocated),
45173 - atomic_read(&sbi->s_mb_discarded));
45174 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45175 + atomic_read_unchecked(&sbi->s_mb_discarded));
45176 }
45177
45178 free_percpu(sbi->s_locality_groups);
45179 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45180 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45181
45182 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45183 - atomic_inc(&sbi->s_bal_reqs);
45184 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45185 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45186 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45187 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45188 - atomic_inc(&sbi->s_bal_success);
45189 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45190 + atomic_inc_unchecked(&sbi->s_bal_success);
45191 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45192 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45193 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45194 - atomic_inc(&sbi->s_bal_goals);
45195 + atomic_inc_unchecked(&sbi->s_bal_goals);
45196 if (ac->ac_found > sbi->s_mb_max_to_scan)
45197 - atomic_inc(&sbi->s_bal_breaks);
45198 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45199 }
45200
45201 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45202 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45203 trace_ext4_mb_new_inode_pa(ac, pa);
45204
45205 ext4_mb_use_inode_pa(ac, pa);
45206 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45207 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45208
45209 ei = EXT4_I(ac->ac_inode);
45210 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45211 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45212 trace_ext4_mb_new_group_pa(ac, pa);
45213
45214 ext4_mb_use_group_pa(ac, pa);
45215 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45216 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45217
45218 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45219 lg = ac->ac_lg;
45220 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45221 * from the bitmap and continue.
45222 */
45223 }
45224 - atomic_add(free, &sbi->s_mb_discarded);
45225 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45226
45227 return err;
45228 }
45229 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45230 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45231 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45232 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45233 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45234 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45235 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45236
45237 return 0;
45238 diff --git a/fs/fcntl.c b/fs/fcntl.c
45239 index 22764c7..86372c9 100644
45240 --- a/fs/fcntl.c
45241 +++ b/fs/fcntl.c
45242 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45243 if (err)
45244 return err;
45245
45246 + if (gr_handle_chroot_fowner(pid, type))
45247 + return -ENOENT;
45248 + if (gr_check_protected_task_fowner(pid, type))
45249 + return -EACCES;
45250 +
45251 f_modown(filp, pid, type, force);
45252 return 0;
45253 }
45254 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45255
45256 static int f_setown_ex(struct file *filp, unsigned long arg)
45257 {
45258 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45259 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45260 struct f_owner_ex owner;
45261 struct pid *pid;
45262 int type;
45263 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45264
45265 static int f_getown_ex(struct file *filp, unsigned long arg)
45266 {
45267 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45268 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45269 struct f_owner_ex owner;
45270 int ret = 0;
45271
45272 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45273 switch (cmd) {
45274 case F_DUPFD:
45275 case F_DUPFD_CLOEXEC:
45276 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45277 if (arg >= rlimit(RLIMIT_NOFILE))
45278 break;
45279 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45280 diff --git a/fs/fifo.c b/fs/fifo.c
45281 index b1a524d..4ee270e 100644
45282 --- a/fs/fifo.c
45283 +++ b/fs/fifo.c
45284 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45285 */
45286 filp->f_op = &read_pipefifo_fops;
45287 pipe->r_counter++;
45288 - if (pipe->readers++ == 0)
45289 + if (atomic_inc_return(&pipe->readers) == 1)
45290 wake_up_partner(inode);
45291
45292 - if (!pipe->writers) {
45293 + if (!atomic_read(&pipe->writers)) {
45294 if ((filp->f_flags & O_NONBLOCK)) {
45295 /* suppress POLLHUP until we have
45296 * seen a writer */
45297 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45298 * errno=ENXIO when there is no process reading the FIFO.
45299 */
45300 ret = -ENXIO;
45301 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45302 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45303 goto err;
45304
45305 filp->f_op = &write_pipefifo_fops;
45306 pipe->w_counter++;
45307 - if (!pipe->writers++)
45308 + if (atomic_inc_return(&pipe->writers) == 1)
45309 wake_up_partner(inode);
45310
45311 - if (!pipe->readers) {
45312 + if (!atomic_read(&pipe->readers)) {
45313 wait_for_partner(inode, &pipe->r_counter);
45314 if (signal_pending(current))
45315 goto err_wr;
45316 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45317 */
45318 filp->f_op = &rdwr_pipefifo_fops;
45319
45320 - pipe->readers++;
45321 - pipe->writers++;
45322 + atomic_inc(&pipe->readers);
45323 + atomic_inc(&pipe->writers);
45324 pipe->r_counter++;
45325 pipe->w_counter++;
45326 - if (pipe->readers == 1 || pipe->writers == 1)
45327 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45328 wake_up_partner(inode);
45329 break;
45330
45331 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45332 return 0;
45333
45334 err_rd:
45335 - if (!--pipe->readers)
45336 + if (atomic_dec_and_test(&pipe->readers))
45337 wake_up_interruptible(&pipe->wait);
45338 ret = -ERESTARTSYS;
45339 goto err;
45340
45341 err_wr:
45342 - if (!--pipe->writers)
45343 + if (atomic_dec_and_test(&pipe->writers))
45344 wake_up_interruptible(&pipe->wait);
45345 ret = -ERESTARTSYS;
45346 goto err;
45347
45348 err:
45349 - if (!pipe->readers && !pipe->writers)
45350 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45351 free_pipe_info(inode);
45352
45353 err_nocleanup:
45354 diff --git a/fs/file.c b/fs/file.c
45355 index 4c6992d..104cdea 100644
45356 --- a/fs/file.c
45357 +++ b/fs/file.c
45358 @@ -15,6 +15,7 @@
45359 #include <linux/slab.h>
45360 #include <linux/vmalloc.h>
45361 #include <linux/file.h>
45362 +#include <linux/security.h>
45363 #include <linux/fdtable.h>
45364 #include <linux/bitops.h>
45365 #include <linux/interrupt.h>
45366 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
45367 * N.B. For clone tasks sharing a files structure, this test
45368 * will limit the total number of files that can be opened.
45369 */
45370 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45371 if (nr >= rlimit(RLIMIT_NOFILE))
45372 return -EMFILE;
45373
45374 diff --git a/fs/filesystems.c b/fs/filesystems.c
45375 index 96f2428..f5eeb8e 100644
45376 --- a/fs/filesystems.c
45377 +++ b/fs/filesystems.c
45378 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45379 int len = dot ? dot - name : strlen(name);
45380
45381 fs = __get_fs_type(name, len);
45382 +
45383 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45384 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45385 +#else
45386 if (!fs && (request_module("%.*s", len, name) == 0))
45387 +#endif
45388 fs = __get_fs_type(name, len);
45389
45390 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45391 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45392 index 78b519c..a8b4979 100644
45393 --- a/fs/fs_struct.c
45394 +++ b/fs/fs_struct.c
45395 @@ -4,6 +4,7 @@
45396 #include <linux/path.h>
45397 #include <linux/slab.h>
45398 #include <linux/fs_struct.h>
45399 +#include <linux/grsecurity.h>
45400 #include "internal.h"
45401
45402 static inline void path_get_longterm(struct path *path)
45403 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45404 old_root = fs->root;
45405 fs->root = *path;
45406 path_get_longterm(path);
45407 + gr_set_chroot_entries(current, path);
45408 write_seqcount_end(&fs->seq);
45409 spin_unlock(&fs->lock);
45410 if (old_root.dentry)
45411 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45412 && fs->root.mnt == old_root->mnt) {
45413 path_get_longterm(new_root);
45414 fs->root = *new_root;
45415 + gr_set_chroot_entries(p, new_root);
45416 count++;
45417 }
45418 if (fs->pwd.dentry == old_root->dentry
45419 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
45420 spin_lock(&fs->lock);
45421 write_seqcount_begin(&fs->seq);
45422 tsk->fs = NULL;
45423 - kill = !--fs->users;
45424 + gr_clear_chroot_entries(tsk);
45425 + kill = !atomic_dec_return(&fs->users);
45426 write_seqcount_end(&fs->seq);
45427 spin_unlock(&fs->lock);
45428 task_unlock(tsk);
45429 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45430 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45431 /* We don't need to lock fs - think why ;-) */
45432 if (fs) {
45433 - fs->users = 1;
45434 + atomic_set(&fs->users, 1);
45435 fs->in_exec = 0;
45436 spin_lock_init(&fs->lock);
45437 seqcount_init(&fs->seq);
45438 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45439 spin_lock(&old->lock);
45440 fs->root = old->root;
45441 path_get_longterm(&fs->root);
45442 + /* instead of calling gr_set_chroot_entries here,
45443 + we call it from every caller of this function
45444 + */
45445 fs->pwd = old->pwd;
45446 path_get_longterm(&fs->pwd);
45447 spin_unlock(&old->lock);
45448 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
45449
45450 task_lock(current);
45451 spin_lock(&fs->lock);
45452 - kill = !--fs->users;
45453 + kill = !atomic_dec_return(&fs->users);
45454 current->fs = new_fs;
45455 + gr_set_chroot_entries(current, &new_fs->root);
45456 spin_unlock(&fs->lock);
45457 task_unlock(current);
45458
45459 @@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45460
45461 int current_umask(void)
45462 {
45463 - return current->fs->umask;
45464 + return current->fs->umask | gr_acl_umask();
45465 }
45466 EXPORT_SYMBOL(current_umask);
45467
45468 /* to be mentioned only in INIT_TASK */
45469 struct fs_struct init_fs = {
45470 - .users = 1,
45471 + .users = ATOMIC_INIT(1),
45472 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45473 .seq = SEQCNT_ZERO,
45474 .umask = 0022,
45475 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
45476 task_lock(current);
45477
45478 spin_lock(&init_fs.lock);
45479 - init_fs.users++;
45480 + atomic_inc(&init_fs.users);
45481 spin_unlock(&init_fs.lock);
45482
45483 spin_lock(&fs->lock);
45484 current->fs = &init_fs;
45485 - kill = !--fs->users;
45486 + gr_set_chroot_entries(current, &current->fs->root);
45487 + kill = !atomic_dec_return(&fs->users);
45488 spin_unlock(&fs->lock);
45489
45490 task_unlock(current);
45491 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45492 index 9905350..02eaec4 100644
45493 --- a/fs/fscache/cookie.c
45494 +++ b/fs/fscache/cookie.c
45495 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45496 parent ? (char *) parent->def->name : "<no-parent>",
45497 def->name, netfs_data);
45498
45499 - fscache_stat(&fscache_n_acquires);
45500 + fscache_stat_unchecked(&fscache_n_acquires);
45501
45502 /* if there's no parent cookie, then we don't create one here either */
45503 if (!parent) {
45504 - fscache_stat(&fscache_n_acquires_null);
45505 + fscache_stat_unchecked(&fscache_n_acquires_null);
45506 _leave(" [no parent]");
45507 return NULL;
45508 }
45509 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45510 /* allocate and initialise a cookie */
45511 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45512 if (!cookie) {
45513 - fscache_stat(&fscache_n_acquires_oom);
45514 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45515 _leave(" [ENOMEM]");
45516 return NULL;
45517 }
45518 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45519
45520 switch (cookie->def->type) {
45521 case FSCACHE_COOKIE_TYPE_INDEX:
45522 - fscache_stat(&fscache_n_cookie_index);
45523 + fscache_stat_unchecked(&fscache_n_cookie_index);
45524 break;
45525 case FSCACHE_COOKIE_TYPE_DATAFILE:
45526 - fscache_stat(&fscache_n_cookie_data);
45527 + fscache_stat_unchecked(&fscache_n_cookie_data);
45528 break;
45529 default:
45530 - fscache_stat(&fscache_n_cookie_special);
45531 + fscache_stat_unchecked(&fscache_n_cookie_special);
45532 break;
45533 }
45534
45535 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45536 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45537 atomic_dec(&parent->n_children);
45538 __fscache_cookie_put(cookie);
45539 - fscache_stat(&fscache_n_acquires_nobufs);
45540 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45541 _leave(" = NULL");
45542 return NULL;
45543 }
45544 }
45545
45546 - fscache_stat(&fscache_n_acquires_ok);
45547 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45548 _leave(" = %p", cookie);
45549 return cookie;
45550 }
45551 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45552 cache = fscache_select_cache_for_object(cookie->parent);
45553 if (!cache) {
45554 up_read(&fscache_addremove_sem);
45555 - fscache_stat(&fscache_n_acquires_no_cache);
45556 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45557 _leave(" = -ENOMEDIUM [no cache]");
45558 return -ENOMEDIUM;
45559 }
45560 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45561 object = cache->ops->alloc_object(cache, cookie);
45562 fscache_stat_d(&fscache_n_cop_alloc_object);
45563 if (IS_ERR(object)) {
45564 - fscache_stat(&fscache_n_object_no_alloc);
45565 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45566 ret = PTR_ERR(object);
45567 goto error;
45568 }
45569
45570 - fscache_stat(&fscache_n_object_alloc);
45571 + fscache_stat_unchecked(&fscache_n_object_alloc);
45572
45573 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45574
45575 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45576 struct fscache_object *object;
45577 struct hlist_node *_p;
45578
45579 - fscache_stat(&fscache_n_updates);
45580 + fscache_stat_unchecked(&fscache_n_updates);
45581
45582 if (!cookie) {
45583 - fscache_stat(&fscache_n_updates_null);
45584 + fscache_stat_unchecked(&fscache_n_updates_null);
45585 _leave(" [no cookie]");
45586 return;
45587 }
45588 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45589 struct fscache_object *object;
45590 unsigned long event;
45591
45592 - fscache_stat(&fscache_n_relinquishes);
45593 + fscache_stat_unchecked(&fscache_n_relinquishes);
45594 if (retire)
45595 - fscache_stat(&fscache_n_relinquishes_retire);
45596 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45597
45598 if (!cookie) {
45599 - fscache_stat(&fscache_n_relinquishes_null);
45600 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45601 _leave(" [no cookie]");
45602 return;
45603 }
45604 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45605
45606 /* wait for the cookie to finish being instantiated (or to fail) */
45607 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45608 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45609 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45610 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45611 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45612 }
45613 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45614 index f6aad48..88dcf26 100644
45615 --- a/fs/fscache/internal.h
45616 +++ b/fs/fscache/internal.h
45617 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45618 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45619 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45620
45621 -extern atomic_t fscache_n_op_pend;
45622 -extern atomic_t fscache_n_op_run;
45623 -extern atomic_t fscache_n_op_enqueue;
45624 -extern atomic_t fscache_n_op_deferred_release;
45625 -extern atomic_t fscache_n_op_release;
45626 -extern atomic_t fscache_n_op_gc;
45627 -extern atomic_t fscache_n_op_cancelled;
45628 -extern atomic_t fscache_n_op_rejected;
45629 +extern atomic_unchecked_t fscache_n_op_pend;
45630 +extern atomic_unchecked_t fscache_n_op_run;
45631 +extern atomic_unchecked_t fscache_n_op_enqueue;
45632 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45633 +extern atomic_unchecked_t fscache_n_op_release;
45634 +extern atomic_unchecked_t fscache_n_op_gc;
45635 +extern atomic_unchecked_t fscache_n_op_cancelled;
45636 +extern atomic_unchecked_t fscache_n_op_rejected;
45637
45638 -extern atomic_t fscache_n_attr_changed;
45639 -extern atomic_t fscache_n_attr_changed_ok;
45640 -extern atomic_t fscache_n_attr_changed_nobufs;
45641 -extern atomic_t fscache_n_attr_changed_nomem;
45642 -extern atomic_t fscache_n_attr_changed_calls;
45643 +extern atomic_unchecked_t fscache_n_attr_changed;
45644 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45645 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45646 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45647 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45648
45649 -extern atomic_t fscache_n_allocs;
45650 -extern atomic_t fscache_n_allocs_ok;
45651 -extern atomic_t fscache_n_allocs_wait;
45652 -extern atomic_t fscache_n_allocs_nobufs;
45653 -extern atomic_t fscache_n_allocs_intr;
45654 -extern atomic_t fscache_n_allocs_object_dead;
45655 -extern atomic_t fscache_n_alloc_ops;
45656 -extern atomic_t fscache_n_alloc_op_waits;
45657 +extern atomic_unchecked_t fscache_n_allocs;
45658 +extern atomic_unchecked_t fscache_n_allocs_ok;
45659 +extern atomic_unchecked_t fscache_n_allocs_wait;
45660 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45661 +extern atomic_unchecked_t fscache_n_allocs_intr;
45662 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45663 +extern atomic_unchecked_t fscache_n_alloc_ops;
45664 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45665
45666 -extern atomic_t fscache_n_retrievals;
45667 -extern atomic_t fscache_n_retrievals_ok;
45668 -extern atomic_t fscache_n_retrievals_wait;
45669 -extern atomic_t fscache_n_retrievals_nodata;
45670 -extern atomic_t fscache_n_retrievals_nobufs;
45671 -extern atomic_t fscache_n_retrievals_intr;
45672 -extern atomic_t fscache_n_retrievals_nomem;
45673 -extern atomic_t fscache_n_retrievals_object_dead;
45674 -extern atomic_t fscache_n_retrieval_ops;
45675 -extern atomic_t fscache_n_retrieval_op_waits;
45676 +extern atomic_unchecked_t fscache_n_retrievals;
45677 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45678 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45679 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45680 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45681 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45682 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45683 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45684 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45685 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45686
45687 -extern atomic_t fscache_n_stores;
45688 -extern atomic_t fscache_n_stores_ok;
45689 -extern atomic_t fscache_n_stores_again;
45690 -extern atomic_t fscache_n_stores_nobufs;
45691 -extern atomic_t fscache_n_stores_oom;
45692 -extern atomic_t fscache_n_store_ops;
45693 -extern atomic_t fscache_n_store_calls;
45694 -extern atomic_t fscache_n_store_pages;
45695 -extern atomic_t fscache_n_store_radix_deletes;
45696 -extern atomic_t fscache_n_store_pages_over_limit;
45697 +extern atomic_unchecked_t fscache_n_stores;
45698 +extern atomic_unchecked_t fscache_n_stores_ok;
45699 +extern atomic_unchecked_t fscache_n_stores_again;
45700 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45701 +extern atomic_unchecked_t fscache_n_stores_oom;
45702 +extern atomic_unchecked_t fscache_n_store_ops;
45703 +extern atomic_unchecked_t fscache_n_store_calls;
45704 +extern atomic_unchecked_t fscache_n_store_pages;
45705 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45706 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45707
45708 -extern atomic_t fscache_n_store_vmscan_not_storing;
45709 -extern atomic_t fscache_n_store_vmscan_gone;
45710 -extern atomic_t fscache_n_store_vmscan_busy;
45711 -extern atomic_t fscache_n_store_vmscan_cancelled;
45712 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45713 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45714 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45715 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45716
45717 -extern atomic_t fscache_n_marks;
45718 -extern atomic_t fscache_n_uncaches;
45719 +extern atomic_unchecked_t fscache_n_marks;
45720 +extern atomic_unchecked_t fscache_n_uncaches;
45721
45722 -extern atomic_t fscache_n_acquires;
45723 -extern atomic_t fscache_n_acquires_null;
45724 -extern atomic_t fscache_n_acquires_no_cache;
45725 -extern atomic_t fscache_n_acquires_ok;
45726 -extern atomic_t fscache_n_acquires_nobufs;
45727 -extern atomic_t fscache_n_acquires_oom;
45728 +extern atomic_unchecked_t fscache_n_acquires;
45729 +extern atomic_unchecked_t fscache_n_acquires_null;
45730 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45731 +extern atomic_unchecked_t fscache_n_acquires_ok;
45732 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45733 +extern atomic_unchecked_t fscache_n_acquires_oom;
45734
45735 -extern atomic_t fscache_n_updates;
45736 -extern atomic_t fscache_n_updates_null;
45737 -extern atomic_t fscache_n_updates_run;
45738 +extern atomic_unchecked_t fscache_n_updates;
45739 +extern atomic_unchecked_t fscache_n_updates_null;
45740 +extern atomic_unchecked_t fscache_n_updates_run;
45741
45742 -extern atomic_t fscache_n_relinquishes;
45743 -extern atomic_t fscache_n_relinquishes_null;
45744 -extern atomic_t fscache_n_relinquishes_waitcrt;
45745 -extern atomic_t fscache_n_relinquishes_retire;
45746 +extern atomic_unchecked_t fscache_n_relinquishes;
45747 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45748 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45749 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45750
45751 -extern atomic_t fscache_n_cookie_index;
45752 -extern atomic_t fscache_n_cookie_data;
45753 -extern atomic_t fscache_n_cookie_special;
45754 +extern atomic_unchecked_t fscache_n_cookie_index;
45755 +extern atomic_unchecked_t fscache_n_cookie_data;
45756 +extern atomic_unchecked_t fscache_n_cookie_special;
45757
45758 -extern atomic_t fscache_n_object_alloc;
45759 -extern atomic_t fscache_n_object_no_alloc;
45760 -extern atomic_t fscache_n_object_lookups;
45761 -extern atomic_t fscache_n_object_lookups_negative;
45762 -extern atomic_t fscache_n_object_lookups_positive;
45763 -extern atomic_t fscache_n_object_lookups_timed_out;
45764 -extern atomic_t fscache_n_object_created;
45765 -extern atomic_t fscache_n_object_avail;
45766 -extern atomic_t fscache_n_object_dead;
45767 +extern atomic_unchecked_t fscache_n_object_alloc;
45768 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45769 +extern atomic_unchecked_t fscache_n_object_lookups;
45770 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45771 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45772 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45773 +extern atomic_unchecked_t fscache_n_object_created;
45774 +extern atomic_unchecked_t fscache_n_object_avail;
45775 +extern atomic_unchecked_t fscache_n_object_dead;
45776
45777 -extern atomic_t fscache_n_checkaux_none;
45778 -extern atomic_t fscache_n_checkaux_okay;
45779 -extern atomic_t fscache_n_checkaux_update;
45780 -extern atomic_t fscache_n_checkaux_obsolete;
45781 +extern atomic_unchecked_t fscache_n_checkaux_none;
45782 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45783 +extern atomic_unchecked_t fscache_n_checkaux_update;
45784 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45785
45786 extern atomic_t fscache_n_cop_alloc_object;
45787 extern atomic_t fscache_n_cop_lookup_object;
45788 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45789 atomic_inc(stat);
45790 }
45791
45792 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45793 +{
45794 + atomic_inc_unchecked(stat);
45795 +}
45796 +
45797 static inline void fscache_stat_d(atomic_t *stat)
45798 {
45799 atomic_dec(stat);
45800 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45801
45802 #define __fscache_stat(stat) (NULL)
45803 #define fscache_stat(stat) do {} while (0)
45804 +#define fscache_stat_unchecked(stat) do {} while (0)
45805 #define fscache_stat_d(stat) do {} while (0)
45806 #endif
45807
45808 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45809 index b6b897c..0ffff9c 100644
45810 --- a/fs/fscache/object.c
45811 +++ b/fs/fscache/object.c
45812 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45813 /* update the object metadata on disk */
45814 case FSCACHE_OBJECT_UPDATING:
45815 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45816 - fscache_stat(&fscache_n_updates_run);
45817 + fscache_stat_unchecked(&fscache_n_updates_run);
45818 fscache_stat(&fscache_n_cop_update_object);
45819 object->cache->ops->update_object(object);
45820 fscache_stat_d(&fscache_n_cop_update_object);
45821 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45822 spin_lock(&object->lock);
45823 object->state = FSCACHE_OBJECT_DEAD;
45824 spin_unlock(&object->lock);
45825 - fscache_stat(&fscache_n_object_dead);
45826 + fscache_stat_unchecked(&fscache_n_object_dead);
45827 goto terminal_transit;
45828
45829 /* handle the parent cache of this object being withdrawn from
45830 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45831 spin_lock(&object->lock);
45832 object->state = FSCACHE_OBJECT_DEAD;
45833 spin_unlock(&object->lock);
45834 - fscache_stat(&fscache_n_object_dead);
45835 + fscache_stat_unchecked(&fscache_n_object_dead);
45836 goto terminal_transit;
45837
45838 /* complain about the object being woken up once it is
45839 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45840 parent->cookie->def->name, cookie->def->name,
45841 object->cache->tag->name);
45842
45843 - fscache_stat(&fscache_n_object_lookups);
45844 + fscache_stat_unchecked(&fscache_n_object_lookups);
45845 fscache_stat(&fscache_n_cop_lookup_object);
45846 ret = object->cache->ops->lookup_object(object);
45847 fscache_stat_d(&fscache_n_cop_lookup_object);
45848 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45849 if (ret == -ETIMEDOUT) {
45850 /* probably stuck behind another object, so move this one to
45851 * the back of the queue */
45852 - fscache_stat(&fscache_n_object_lookups_timed_out);
45853 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45854 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45855 }
45856
45857 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45858
45859 spin_lock(&object->lock);
45860 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45861 - fscache_stat(&fscache_n_object_lookups_negative);
45862 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45863
45864 /* transit here to allow write requests to begin stacking up
45865 * and read requests to begin returning ENODATA */
45866 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45867 * result, in which case there may be data available */
45868 spin_lock(&object->lock);
45869 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45870 - fscache_stat(&fscache_n_object_lookups_positive);
45871 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45872
45873 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45874
45875 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45876 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45877 } else {
45878 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45879 - fscache_stat(&fscache_n_object_created);
45880 + fscache_stat_unchecked(&fscache_n_object_created);
45881
45882 object->state = FSCACHE_OBJECT_AVAILABLE;
45883 spin_unlock(&object->lock);
45884 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45885 fscache_enqueue_dependents(object);
45886
45887 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45888 - fscache_stat(&fscache_n_object_avail);
45889 + fscache_stat_unchecked(&fscache_n_object_avail);
45890
45891 _leave("");
45892 }
45893 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45894 enum fscache_checkaux result;
45895
45896 if (!object->cookie->def->check_aux) {
45897 - fscache_stat(&fscache_n_checkaux_none);
45898 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45899 return FSCACHE_CHECKAUX_OKAY;
45900 }
45901
45902 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45903 switch (result) {
45904 /* entry okay as is */
45905 case FSCACHE_CHECKAUX_OKAY:
45906 - fscache_stat(&fscache_n_checkaux_okay);
45907 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45908 break;
45909
45910 /* entry requires update */
45911 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45912 - fscache_stat(&fscache_n_checkaux_update);
45913 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45914 break;
45915
45916 /* entry requires deletion */
45917 case FSCACHE_CHECKAUX_OBSOLETE:
45918 - fscache_stat(&fscache_n_checkaux_obsolete);
45919 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45920 break;
45921
45922 default:
45923 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45924 index 30afdfa..2256596 100644
45925 --- a/fs/fscache/operation.c
45926 +++ b/fs/fscache/operation.c
45927 @@ -17,7 +17,7 @@
45928 #include <linux/slab.h>
45929 #include "internal.h"
45930
45931 -atomic_t fscache_op_debug_id;
45932 +atomic_unchecked_t fscache_op_debug_id;
45933 EXPORT_SYMBOL(fscache_op_debug_id);
45934
45935 /**
45936 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45937 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45938 ASSERTCMP(atomic_read(&op->usage), >, 0);
45939
45940 - fscache_stat(&fscache_n_op_enqueue);
45941 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45942 switch (op->flags & FSCACHE_OP_TYPE) {
45943 case FSCACHE_OP_ASYNC:
45944 _debug("queue async");
45945 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45946 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45947 if (op->processor)
45948 fscache_enqueue_operation(op);
45949 - fscache_stat(&fscache_n_op_run);
45950 + fscache_stat_unchecked(&fscache_n_op_run);
45951 }
45952
45953 /*
45954 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45955 if (object->n_ops > 1) {
45956 atomic_inc(&op->usage);
45957 list_add_tail(&op->pend_link, &object->pending_ops);
45958 - fscache_stat(&fscache_n_op_pend);
45959 + fscache_stat_unchecked(&fscache_n_op_pend);
45960 } else if (!list_empty(&object->pending_ops)) {
45961 atomic_inc(&op->usage);
45962 list_add_tail(&op->pend_link, &object->pending_ops);
45963 - fscache_stat(&fscache_n_op_pend);
45964 + fscache_stat_unchecked(&fscache_n_op_pend);
45965 fscache_start_operations(object);
45966 } else {
45967 ASSERTCMP(object->n_in_progress, ==, 0);
45968 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45969 object->n_exclusive++; /* reads and writes must wait */
45970 atomic_inc(&op->usage);
45971 list_add_tail(&op->pend_link, &object->pending_ops);
45972 - fscache_stat(&fscache_n_op_pend);
45973 + fscache_stat_unchecked(&fscache_n_op_pend);
45974 ret = 0;
45975 } else {
45976 /* not allowed to submit ops in any other state */
45977 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45978 if (object->n_exclusive > 0) {
45979 atomic_inc(&op->usage);
45980 list_add_tail(&op->pend_link, &object->pending_ops);
45981 - fscache_stat(&fscache_n_op_pend);
45982 + fscache_stat_unchecked(&fscache_n_op_pend);
45983 } else if (!list_empty(&object->pending_ops)) {
45984 atomic_inc(&op->usage);
45985 list_add_tail(&op->pend_link, &object->pending_ops);
45986 - fscache_stat(&fscache_n_op_pend);
45987 + fscache_stat_unchecked(&fscache_n_op_pend);
45988 fscache_start_operations(object);
45989 } else {
45990 ASSERTCMP(object->n_exclusive, ==, 0);
45991 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45992 object->n_ops++;
45993 atomic_inc(&op->usage);
45994 list_add_tail(&op->pend_link, &object->pending_ops);
45995 - fscache_stat(&fscache_n_op_pend);
45996 + fscache_stat_unchecked(&fscache_n_op_pend);
45997 ret = 0;
45998 } else if (object->state == FSCACHE_OBJECT_DYING ||
45999 object->state == FSCACHE_OBJECT_LC_DYING ||
46000 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46001 - fscache_stat(&fscache_n_op_rejected);
46002 + fscache_stat_unchecked(&fscache_n_op_rejected);
46003 ret = -ENOBUFS;
46004 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46005 fscache_report_unexpected_submission(object, op, ostate);
46006 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46007
46008 ret = -EBUSY;
46009 if (!list_empty(&op->pend_link)) {
46010 - fscache_stat(&fscache_n_op_cancelled);
46011 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46012 list_del_init(&op->pend_link);
46013 object->n_ops--;
46014 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46015 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46016 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46017 BUG();
46018
46019 - fscache_stat(&fscache_n_op_release);
46020 + fscache_stat_unchecked(&fscache_n_op_release);
46021
46022 if (op->release) {
46023 op->release(op);
46024 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46025 * lock, and defer it otherwise */
46026 if (!spin_trylock(&object->lock)) {
46027 _debug("defer put");
46028 - fscache_stat(&fscache_n_op_deferred_release);
46029 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46030
46031 cache = object->cache;
46032 spin_lock(&cache->op_gc_list_lock);
46033 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46034
46035 _debug("GC DEFERRED REL OBJ%x OP%x",
46036 object->debug_id, op->debug_id);
46037 - fscache_stat(&fscache_n_op_gc);
46038 + fscache_stat_unchecked(&fscache_n_op_gc);
46039
46040 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46041
46042 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46043 index 3f7a59b..cf196cc 100644
46044 --- a/fs/fscache/page.c
46045 +++ b/fs/fscache/page.c
46046 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46047 val = radix_tree_lookup(&cookie->stores, page->index);
46048 if (!val) {
46049 rcu_read_unlock();
46050 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46051 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46052 __fscache_uncache_page(cookie, page);
46053 return true;
46054 }
46055 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46056 spin_unlock(&cookie->stores_lock);
46057
46058 if (xpage) {
46059 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46060 - fscache_stat(&fscache_n_store_radix_deletes);
46061 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46062 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46063 ASSERTCMP(xpage, ==, page);
46064 } else {
46065 - fscache_stat(&fscache_n_store_vmscan_gone);
46066 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46067 }
46068
46069 wake_up_bit(&cookie->flags, 0);
46070 @@ -107,7 +107,7 @@ page_busy:
46071 /* we might want to wait here, but that could deadlock the allocator as
46072 * the work threads writing to the cache may all end up sleeping
46073 * on memory allocation */
46074 - fscache_stat(&fscache_n_store_vmscan_busy);
46075 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46076 return false;
46077 }
46078 EXPORT_SYMBOL(__fscache_maybe_release_page);
46079 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46080 FSCACHE_COOKIE_STORING_TAG);
46081 if (!radix_tree_tag_get(&cookie->stores, page->index,
46082 FSCACHE_COOKIE_PENDING_TAG)) {
46083 - fscache_stat(&fscache_n_store_radix_deletes);
46084 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46085 xpage = radix_tree_delete(&cookie->stores, page->index);
46086 }
46087 spin_unlock(&cookie->stores_lock);
46088 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46089
46090 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46091
46092 - fscache_stat(&fscache_n_attr_changed_calls);
46093 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46094
46095 if (fscache_object_is_active(object)) {
46096 fscache_stat(&fscache_n_cop_attr_changed);
46097 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46098
46099 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46100
46101 - fscache_stat(&fscache_n_attr_changed);
46102 + fscache_stat_unchecked(&fscache_n_attr_changed);
46103
46104 op = kzalloc(sizeof(*op), GFP_KERNEL);
46105 if (!op) {
46106 - fscache_stat(&fscache_n_attr_changed_nomem);
46107 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46108 _leave(" = -ENOMEM");
46109 return -ENOMEM;
46110 }
46111 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46112 if (fscache_submit_exclusive_op(object, op) < 0)
46113 goto nobufs;
46114 spin_unlock(&cookie->lock);
46115 - fscache_stat(&fscache_n_attr_changed_ok);
46116 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46117 fscache_put_operation(op);
46118 _leave(" = 0");
46119 return 0;
46120 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46121 nobufs:
46122 spin_unlock(&cookie->lock);
46123 kfree(op);
46124 - fscache_stat(&fscache_n_attr_changed_nobufs);
46125 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46126 _leave(" = %d", -ENOBUFS);
46127 return -ENOBUFS;
46128 }
46129 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46130 /* allocate a retrieval operation and attempt to submit it */
46131 op = kzalloc(sizeof(*op), GFP_NOIO);
46132 if (!op) {
46133 - fscache_stat(&fscache_n_retrievals_nomem);
46134 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46135 return NULL;
46136 }
46137
46138 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46139 return 0;
46140 }
46141
46142 - fscache_stat(&fscache_n_retrievals_wait);
46143 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46144
46145 jif = jiffies;
46146 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46147 fscache_wait_bit_interruptible,
46148 TASK_INTERRUPTIBLE) != 0) {
46149 - fscache_stat(&fscache_n_retrievals_intr);
46150 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46151 _leave(" = -ERESTARTSYS");
46152 return -ERESTARTSYS;
46153 }
46154 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46155 */
46156 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46157 struct fscache_retrieval *op,
46158 - atomic_t *stat_op_waits,
46159 - atomic_t *stat_object_dead)
46160 + atomic_unchecked_t *stat_op_waits,
46161 + atomic_unchecked_t *stat_object_dead)
46162 {
46163 int ret;
46164
46165 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46166 goto check_if_dead;
46167
46168 _debug(">>> WT");
46169 - fscache_stat(stat_op_waits);
46170 + fscache_stat_unchecked(stat_op_waits);
46171 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46172 fscache_wait_bit_interruptible,
46173 TASK_INTERRUPTIBLE) < 0) {
46174 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46175
46176 check_if_dead:
46177 if (unlikely(fscache_object_is_dead(object))) {
46178 - fscache_stat(stat_object_dead);
46179 + fscache_stat_unchecked(stat_object_dead);
46180 return -ENOBUFS;
46181 }
46182 return 0;
46183 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46184
46185 _enter("%p,%p,,,", cookie, page);
46186
46187 - fscache_stat(&fscache_n_retrievals);
46188 + fscache_stat_unchecked(&fscache_n_retrievals);
46189
46190 if (hlist_empty(&cookie->backing_objects))
46191 goto nobufs;
46192 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46193 goto nobufs_unlock;
46194 spin_unlock(&cookie->lock);
46195
46196 - fscache_stat(&fscache_n_retrieval_ops);
46197 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46198
46199 /* pin the netfs read context in case we need to do the actual netfs
46200 * read because we've encountered a cache read failure */
46201 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46202
46203 error:
46204 if (ret == -ENOMEM)
46205 - fscache_stat(&fscache_n_retrievals_nomem);
46206 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46207 else if (ret == -ERESTARTSYS)
46208 - fscache_stat(&fscache_n_retrievals_intr);
46209 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46210 else if (ret == -ENODATA)
46211 - fscache_stat(&fscache_n_retrievals_nodata);
46212 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46213 else if (ret < 0)
46214 - fscache_stat(&fscache_n_retrievals_nobufs);
46215 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46216 else
46217 - fscache_stat(&fscache_n_retrievals_ok);
46218 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46219
46220 fscache_put_retrieval(op);
46221 _leave(" = %d", ret);
46222 @@ -429,7 +429,7 @@ nobufs_unlock:
46223 spin_unlock(&cookie->lock);
46224 kfree(op);
46225 nobufs:
46226 - fscache_stat(&fscache_n_retrievals_nobufs);
46227 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46228 _leave(" = -ENOBUFS");
46229 return -ENOBUFS;
46230 }
46231 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46232
46233 _enter("%p,,%d,,,", cookie, *nr_pages);
46234
46235 - fscache_stat(&fscache_n_retrievals);
46236 + fscache_stat_unchecked(&fscache_n_retrievals);
46237
46238 if (hlist_empty(&cookie->backing_objects))
46239 goto nobufs;
46240 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46241 goto nobufs_unlock;
46242 spin_unlock(&cookie->lock);
46243
46244 - fscache_stat(&fscache_n_retrieval_ops);
46245 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46246
46247 /* pin the netfs read context in case we need to do the actual netfs
46248 * read because we've encountered a cache read failure */
46249 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46250
46251 error:
46252 if (ret == -ENOMEM)
46253 - fscache_stat(&fscache_n_retrievals_nomem);
46254 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46255 else if (ret == -ERESTARTSYS)
46256 - fscache_stat(&fscache_n_retrievals_intr);
46257 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46258 else if (ret == -ENODATA)
46259 - fscache_stat(&fscache_n_retrievals_nodata);
46260 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46261 else if (ret < 0)
46262 - fscache_stat(&fscache_n_retrievals_nobufs);
46263 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46264 else
46265 - fscache_stat(&fscache_n_retrievals_ok);
46266 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46267
46268 fscache_put_retrieval(op);
46269 _leave(" = %d", ret);
46270 @@ -545,7 +545,7 @@ nobufs_unlock:
46271 spin_unlock(&cookie->lock);
46272 kfree(op);
46273 nobufs:
46274 - fscache_stat(&fscache_n_retrievals_nobufs);
46275 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46276 _leave(" = -ENOBUFS");
46277 return -ENOBUFS;
46278 }
46279 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46280
46281 _enter("%p,%p,,,", cookie, page);
46282
46283 - fscache_stat(&fscache_n_allocs);
46284 + fscache_stat_unchecked(&fscache_n_allocs);
46285
46286 if (hlist_empty(&cookie->backing_objects))
46287 goto nobufs;
46288 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46289 goto nobufs_unlock;
46290 spin_unlock(&cookie->lock);
46291
46292 - fscache_stat(&fscache_n_alloc_ops);
46293 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46294
46295 ret = fscache_wait_for_retrieval_activation(
46296 object, op,
46297 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46298
46299 error:
46300 if (ret == -ERESTARTSYS)
46301 - fscache_stat(&fscache_n_allocs_intr);
46302 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46303 else if (ret < 0)
46304 - fscache_stat(&fscache_n_allocs_nobufs);
46305 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46306 else
46307 - fscache_stat(&fscache_n_allocs_ok);
46308 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46309
46310 fscache_put_retrieval(op);
46311 _leave(" = %d", ret);
46312 @@ -625,7 +625,7 @@ nobufs_unlock:
46313 spin_unlock(&cookie->lock);
46314 kfree(op);
46315 nobufs:
46316 - fscache_stat(&fscache_n_allocs_nobufs);
46317 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46318 _leave(" = -ENOBUFS");
46319 return -ENOBUFS;
46320 }
46321 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46322
46323 spin_lock(&cookie->stores_lock);
46324
46325 - fscache_stat(&fscache_n_store_calls);
46326 + fscache_stat_unchecked(&fscache_n_store_calls);
46327
46328 /* find a page to store */
46329 page = NULL;
46330 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46331 page = results[0];
46332 _debug("gang %d [%lx]", n, page->index);
46333 if (page->index > op->store_limit) {
46334 - fscache_stat(&fscache_n_store_pages_over_limit);
46335 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46336 goto superseded;
46337 }
46338
46339 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46340 spin_unlock(&cookie->stores_lock);
46341 spin_unlock(&object->lock);
46342
46343 - fscache_stat(&fscache_n_store_pages);
46344 + fscache_stat_unchecked(&fscache_n_store_pages);
46345 fscache_stat(&fscache_n_cop_write_page);
46346 ret = object->cache->ops->write_page(op, page);
46347 fscache_stat_d(&fscache_n_cop_write_page);
46348 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46349 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46350 ASSERT(PageFsCache(page));
46351
46352 - fscache_stat(&fscache_n_stores);
46353 + fscache_stat_unchecked(&fscache_n_stores);
46354
46355 op = kzalloc(sizeof(*op), GFP_NOIO);
46356 if (!op)
46357 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46358 spin_unlock(&cookie->stores_lock);
46359 spin_unlock(&object->lock);
46360
46361 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46362 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46363 op->store_limit = object->store_limit;
46364
46365 if (fscache_submit_op(object, &op->op) < 0)
46366 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46367
46368 spin_unlock(&cookie->lock);
46369 radix_tree_preload_end();
46370 - fscache_stat(&fscache_n_store_ops);
46371 - fscache_stat(&fscache_n_stores_ok);
46372 + fscache_stat_unchecked(&fscache_n_store_ops);
46373 + fscache_stat_unchecked(&fscache_n_stores_ok);
46374
46375 /* the work queue now carries its own ref on the object */
46376 fscache_put_operation(&op->op);
46377 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46378 return 0;
46379
46380 already_queued:
46381 - fscache_stat(&fscache_n_stores_again);
46382 + fscache_stat_unchecked(&fscache_n_stores_again);
46383 already_pending:
46384 spin_unlock(&cookie->stores_lock);
46385 spin_unlock(&object->lock);
46386 spin_unlock(&cookie->lock);
46387 radix_tree_preload_end();
46388 kfree(op);
46389 - fscache_stat(&fscache_n_stores_ok);
46390 + fscache_stat_unchecked(&fscache_n_stores_ok);
46391 _leave(" = 0");
46392 return 0;
46393
46394 @@ -851,14 +851,14 @@ nobufs:
46395 spin_unlock(&cookie->lock);
46396 radix_tree_preload_end();
46397 kfree(op);
46398 - fscache_stat(&fscache_n_stores_nobufs);
46399 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46400 _leave(" = -ENOBUFS");
46401 return -ENOBUFS;
46402
46403 nomem_free:
46404 kfree(op);
46405 nomem:
46406 - fscache_stat(&fscache_n_stores_oom);
46407 + fscache_stat_unchecked(&fscache_n_stores_oom);
46408 _leave(" = -ENOMEM");
46409 return -ENOMEM;
46410 }
46411 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46412 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46413 ASSERTCMP(page, !=, NULL);
46414
46415 - fscache_stat(&fscache_n_uncaches);
46416 + fscache_stat_unchecked(&fscache_n_uncaches);
46417
46418 /* cache withdrawal may beat us to it */
46419 if (!PageFsCache(page))
46420 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46421 unsigned long loop;
46422
46423 #ifdef CONFIG_FSCACHE_STATS
46424 - atomic_add(pagevec->nr, &fscache_n_marks);
46425 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46426 #endif
46427
46428 for (loop = 0; loop < pagevec->nr; loop++) {
46429 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46430 index 4765190..2a067f2 100644
46431 --- a/fs/fscache/stats.c
46432 +++ b/fs/fscache/stats.c
46433 @@ -18,95 +18,95 @@
46434 /*
46435 * operation counters
46436 */
46437 -atomic_t fscache_n_op_pend;
46438 -atomic_t fscache_n_op_run;
46439 -atomic_t fscache_n_op_enqueue;
46440 -atomic_t fscache_n_op_requeue;
46441 -atomic_t fscache_n_op_deferred_release;
46442 -atomic_t fscache_n_op_release;
46443 -atomic_t fscache_n_op_gc;
46444 -atomic_t fscache_n_op_cancelled;
46445 -atomic_t fscache_n_op_rejected;
46446 +atomic_unchecked_t fscache_n_op_pend;
46447 +atomic_unchecked_t fscache_n_op_run;
46448 +atomic_unchecked_t fscache_n_op_enqueue;
46449 +atomic_unchecked_t fscache_n_op_requeue;
46450 +atomic_unchecked_t fscache_n_op_deferred_release;
46451 +atomic_unchecked_t fscache_n_op_release;
46452 +atomic_unchecked_t fscache_n_op_gc;
46453 +atomic_unchecked_t fscache_n_op_cancelled;
46454 +atomic_unchecked_t fscache_n_op_rejected;
46455
46456 -atomic_t fscache_n_attr_changed;
46457 -atomic_t fscache_n_attr_changed_ok;
46458 -atomic_t fscache_n_attr_changed_nobufs;
46459 -atomic_t fscache_n_attr_changed_nomem;
46460 -atomic_t fscache_n_attr_changed_calls;
46461 +atomic_unchecked_t fscache_n_attr_changed;
46462 +atomic_unchecked_t fscache_n_attr_changed_ok;
46463 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46464 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46465 +atomic_unchecked_t fscache_n_attr_changed_calls;
46466
46467 -atomic_t fscache_n_allocs;
46468 -atomic_t fscache_n_allocs_ok;
46469 -atomic_t fscache_n_allocs_wait;
46470 -atomic_t fscache_n_allocs_nobufs;
46471 -atomic_t fscache_n_allocs_intr;
46472 -atomic_t fscache_n_allocs_object_dead;
46473 -atomic_t fscache_n_alloc_ops;
46474 -atomic_t fscache_n_alloc_op_waits;
46475 +atomic_unchecked_t fscache_n_allocs;
46476 +atomic_unchecked_t fscache_n_allocs_ok;
46477 +atomic_unchecked_t fscache_n_allocs_wait;
46478 +atomic_unchecked_t fscache_n_allocs_nobufs;
46479 +atomic_unchecked_t fscache_n_allocs_intr;
46480 +atomic_unchecked_t fscache_n_allocs_object_dead;
46481 +atomic_unchecked_t fscache_n_alloc_ops;
46482 +atomic_unchecked_t fscache_n_alloc_op_waits;
46483
46484 -atomic_t fscache_n_retrievals;
46485 -atomic_t fscache_n_retrievals_ok;
46486 -atomic_t fscache_n_retrievals_wait;
46487 -atomic_t fscache_n_retrievals_nodata;
46488 -atomic_t fscache_n_retrievals_nobufs;
46489 -atomic_t fscache_n_retrievals_intr;
46490 -atomic_t fscache_n_retrievals_nomem;
46491 -atomic_t fscache_n_retrievals_object_dead;
46492 -atomic_t fscache_n_retrieval_ops;
46493 -atomic_t fscache_n_retrieval_op_waits;
46494 +atomic_unchecked_t fscache_n_retrievals;
46495 +atomic_unchecked_t fscache_n_retrievals_ok;
46496 +atomic_unchecked_t fscache_n_retrievals_wait;
46497 +atomic_unchecked_t fscache_n_retrievals_nodata;
46498 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46499 +atomic_unchecked_t fscache_n_retrievals_intr;
46500 +atomic_unchecked_t fscache_n_retrievals_nomem;
46501 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46502 +atomic_unchecked_t fscache_n_retrieval_ops;
46503 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46504
46505 -atomic_t fscache_n_stores;
46506 -atomic_t fscache_n_stores_ok;
46507 -atomic_t fscache_n_stores_again;
46508 -atomic_t fscache_n_stores_nobufs;
46509 -atomic_t fscache_n_stores_oom;
46510 -atomic_t fscache_n_store_ops;
46511 -atomic_t fscache_n_store_calls;
46512 -atomic_t fscache_n_store_pages;
46513 -atomic_t fscache_n_store_radix_deletes;
46514 -atomic_t fscache_n_store_pages_over_limit;
46515 +atomic_unchecked_t fscache_n_stores;
46516 +atomic_unchecked_t fscache_n_stores_ok;
46517 +atomic_unchecked_t fscache_n_stores_again;
46518 +atomic_unchecked_t fscache_n_stores_nobufs;
46519 +atomic_unchecked_t fscache_n_stores_oom;
46520 +atomic_unchecked_t fscache_n_store_ops;
46521 +atomic_unchecked_t fscache_n_store_calls;
46522 +atomic_unchecked_t fscache_n_store_pages;
46523 +atomic_unchecked_t fscache_n_store_radix_deletes;
46524 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46525
46526 -atomic_t fscache_n_store_vmscan_not_storing;
46527 -atomic_t fscache_n_store_vmscan_gone;
46528 -atomic_t fscache_n_store_vmscan_busy;
46529 -atomic_t fscache_n_store_vmscan_cancelled;
46530 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46531 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46532 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46533 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46534
46535 -atomic_t fscache_n_marks;
46536 -atomic_t fscache_n_uncaches;
46537 +atomic_unchecked_t fscache_n_marks;
46538 +atomic_unchecked_t fscache_n_uncaches;
46539
46540 -atomic_t fscache_n_acquires;
46541 -atomic_t fscache_n_acquires_null;
46542 -atomic_t fscache_n_acquires_no_cache;
46543 -atomic_t fscache_n_acquires_ok;
46544 -atomic_t fscache_n_acquires_nobufs;
46545 -atomic_t fscache_n_acquires_oom;
46546 +atomic_unchecked_t fscache_n_acquires;
46547 +atomic_unchecked_t fscache_n_acquires_null;
46548 +atomic_unchecked_t fscache_n_acquires_no_cache;
46549 +atomic_unchecked_t fscache_n_acquires_ok;
46550 +atomic_unchecked_t fscache_n_acquires_nobufs;
46551 +atomic_unchecked_t fscache_n_acquires_oom;
46552
46553 -atomic_t fscache_n_updates;
46554 -atomic_t fscache_n_updates_null;
46555 -atomic_t fscache_n_updates_run;
46556 +atomic_unchecked_t fscache_n_updates;
46557 +atomic_unchecked_t fscache_n_updates_null;
46558 +atomic_unchecked_t fscache_n_updates_run;
46559
46560 -atomic_t fscache_n_relinquishes;
46561 -atomic_t fscache_n_relinquishes_null;
46562 -atomic_t fscache_n_relinquishes_waitcrt;
46563 -atomic_t fscache_n_relinquishes_retire;
46564 +atomic_unchecked_t fscache_n_relinquishes;
46565 +atomic_unchecked_t fscache_n_relinquishes_null;
46566 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46567 +atomic_unchecked_t fscache_n_relinquishes_retire;
46568
46569 -atomic_t fscache_n_cookie_index;
46570 -atomic_t fscache_n_cookie_data;
46571 -atomic_t fscache_n_cookie_special;
46572 +atomic_unchecked_t fscache_n_cookie_index;
46573 +atomic_unchecked_t fscache_n_cookie_data;
46574 +atomic_unchecked_t fscache_n_cookie_special;
46575
46576 -atomic_t fscache_n_object_alloc;
46577 -atomic_t fscache_n_object_no_alloc;
46578 -atomic_t fscache_n_object_lookups;
46579 -atomic_t fscache_n_object_lookups_negative;
46580 -atomic_t fscache_n_object_lookups_positive;
46581 -atomic_t fscache_n_object_lookups_timed_out;
46582 -atomic_t fscache_n_object_created;
46583 -atomic_t fscache_n_object_avail;
46584 -atomic_t fscache_n_object_dead;
46585 +atomic_unchecked_t fscache_n_object_alloc;
46586 +atomic_unchecked_t fscache_n_object_no_alloc;
46587 +atomic_unchecked_t fscache_n_object_lookups;
46588 +atomic_unchecked_t fscache_n_object_lookups_negative;
46589 +atomic_unchecked_t fscache_n_object_lookups_positive;
46590 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46591 +atomic_unchecked_t fscache_n_object_created;
46592 +atomic_unchecked_t fscache_n_object_avail;
46593 +atomic_unchecked_t fscache_n_object_dead;
46594
46595 -atomic_t fscache_n_checkaux_none;
46596 -atomic_t fscache_n_checkaux_okay;
46597 -atomic_t fscache_n_checkaux_update;
46598 -atomic_t fscache_n_checkaux_obsolete;
46599 +atomic_unchecked_t fscache_n_checkaux_none;
46600 +atomic_unchecked_t fscache_n_checkaux_okay;
46601 +atomic_unchecked_t fscache_n_checkaux_update;
46602 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46603
46604 atomic_t fscache_n_cop_alloc_object;
46605 atomic_t fscache_n_cop_lookup_object;
46606 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46607 seq_puts(m, "FS-Cache statistics\n");
46608
46609 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46610 - atomic_read(&fscache_n_cookie_index),
46611 - atomic_read(&fscache_n_cookie_data),
46612 - atomic_read(&fscache_n_cookie_special));
46613 + atomic_read_unchecked(&fscache_n_cookie_index),
46614 + atomic_read_unchecked(&fscache_n_cookie_data),
46615 + atomic_read_unchecked(&fscache_n_cookie_special));
46616
46617 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46618 - atomic_read(&fscache_n_object_alloc),
46619 - atomic_read(&fscache_n_object_no_alloc),
46620 - atomic_read(&fscache_n_object_avail),
46621 - atomic_read(&fscache_n_object_dead));
46622 + atomic_read_unchecked(&fscache_n_object_alloc),
46623 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46624 + atomic_read_unchecked(&fscache_n_object_avail),
46625 + atomic_read_unchecked(&fscache_n_object_dead));
46626 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46627 - atomic_read(&fscache_n_checkaux_none),
46628 - atomic_read(&fscache_n_checkaux_okay),
46629 - atomic_read(&fscache_n_checkaux_update),
46630 - atomic_read(&fscache_n_checkaux_obsolete));
46631 + atomic_read_unchecked(&fscache_n_checkaux_none),
46632 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46633 + atomic_read_unchecked(&fscache_n_checkaux_update),
46634 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46635
46636 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46637 - atomic_read(&fscache_n_marks),
46638 - atomic_read(&fscache_n_uncaches));
46639 + atomic_read_unchecked(&fscache_n_marks),
46640 + atomic_read_unchecked(&fscache_n_uncaches));
46641
46642 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46643 " oom=%u\n",
46644 - atomic_read(&fscache_n_acquires),
46645 - atomic_read(&fscache_n_acquires_null),
46646 - atomic_read(&fscache_n_acquires_no_cache),
46647 - atomic_read(&fscache_n_acquires_ok),
46648 - atomic_read(&fscache_n_acquires_nobufs),
46649 - atomic_read(&fscache_n_acquires_oom));
46650 + atomic_read_unchecked(&fscache_n_acquires),
46651 + atomic_read_unchecked(&fscache_n_acquires_null),
46652 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46653 + atomic_read_unchecked(&fscache_n_acquires_ok),
46654 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46655 + atomic_read_unchecked(&fscache_n_acquires_oom));
46656
46657 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46658 - atomic_read(&fscache_n_object_lookups),
46659 - atomic_read(&fscache_n_object_lookups_negative),
46660 - atomic_read(&fscache_n_object_lookups_positive),
46661 - atomic_read(&fscache_n_object_created),
46662 - atomic_read(&fscache_n_object_lookups_timed_out));
46663 + atomic_read_unchecked(&fscache_n_object_lookups),
46664 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46665 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46666 + atomic_read_unchecked(&fscache_n_object_created),
46667 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46668
46669 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46670 - atomic_read(&fscache_n_updates),
46671 - atomic_read(&fscache_n_updates_null),
46672 - atomic_read(&fscache_n_updates_run));
46673 + atomic_read_unchecked(&fscache_n_updates),
46674 + atomic_read_unchecked(&fscache_n_updates_null),
46675 + atomic_read_unchecked(&fscache_n_updates_run));
46676
46677 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46678 - atomic_read(&fscache_n_relinquishes),
46679 - atomic_read(&fscache_n_relinquishes_null),
46680 - atomic_read(&fscache_n_relinquishes_waitcrt),
46681 - atomic_read(&fscache_n_relinquishes_retire));
46682 + atomic_read_unchecked(&fscache_n_relinquishes),
46683 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46684 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46685 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46686
46687 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46688 - atomic_read(&fscache_n_attr_changed),
46689 - atomic_read(&fscache_n_attr_changed_ok),
46690 - atomic_read(&fscache_n_attr_changed_nobufs),
46691 - atomic_read(&fscache_n_attr_changed_nomem),
46692 - atomic_read(&fscache_n_attr_changed_calls));
46693 + atomic_read_unchecked(&fscache_n_attr_changed),
46694 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46695 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46696 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46697 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46698
46699 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46700 - atomic_read(&fscache_n_allocs),
46701 - atomic_read(&fscache_n_allocs_ok),
46702 - atomic_read(&fscache_n_allocs_wait),
46703 - atomic_read(&fscache_n_allocs_nobufs),
46704 - atomic_read(&fscache_n_allocs_intr));
46705 + atomic_read_unchecked(&fscache_n_allocs),
46706 + atomic_read_unchecked(&fscache_n_allocs_ok),
46707 + atomic_read_unchecked(&fscache_n_allocs_wait),
46708 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46709 + atomic_read_unchecked(&fscache_n_allocs_intr));
46710 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46711 - atomic_read(&fscache_n_alloc_ops),
46712 - atomic_read(&fscache_n_alloc_op_waits),
46713 - atomic_read(&fscache_n_allocs_object_dead));
46714 + atomic_read_unchecked(&fscache_n_alloc_ops),
46715 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46716 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46717
46718 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46719 " int=%u oom=%u\n",
46720 - atomic_read(&fscache_n_retrievals),
46721 - atomic_read(&fscache_n_retrievals_ok),
46722 - atomic_read(&fscache_n_retrievals_wait),
46723 - atomic_read(&fscache_n_retrievals_nodata),
46724 - atomic_read(&fscache_n_retrievals_nobufs),
46725 - atomic_read(&fscache_n_retrievals_intr),
46726 - atomic_read(&fscache_n_retrievals_nomem));
46727 + atomic_read_unchecked(&fscache_n_retrievals),
46728 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46729 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46730 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46731 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46732 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46733 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46734 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46735 - atomic_read(&fscache_n_retrieval_ops),
46736 - atomic_read(&fscache_n_retrieval_op_waits),
46737 - atomic_read(&fscache_n_retrievals_object_dead));
46738 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46739 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46740 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46741
46742 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46743 - atomic_read(&fscache_n_stores),
46744 - atomic_read(&fscache_n_stores_ok),
46745 - atomic_read(&fscache_n_stores_again),
46746 - atomic_read(&fscache_n_stores_nobufs),
46747 - atomic_read(&fscache_n_stores_oom));
46748 + atomic_read_unchecked(&fscache_n_stores),
46749 + atomic_read_unchecked(&fscache_n_stores_ok),
46750 + atomic_read_unchecked(&fscache_n_stores_again),
46751 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46752 + atomic_read_unchecked(&fscache_n_stores_oom));
46753 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46754 - atomic_read(&fscache_n_store_ops),
46755 - atomic_read(&fscache_n_store_calls),
46756 - atomic_read(&fscache_n_store_pages),
46757 - atomic_read(&fscache_n_store_radix_deletes),
46758 - atomic_read(&fscache_n_store_pages_over_limit));
46759 + atomic_read_unchecked(&fscache_n_store_ops),
46760 + atomic_read_unchecked(&fscache_n_store_calls),
46761 + atomic_read_unchecked(&fscache_n_store_pages),
46762 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46763 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46764
46765 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46766 - atomic_read(&fscache_n_store_vmscan_not_storing),
46767 - atomic_read(&fscache_n_store_vmscan_gone),
46768 - atomic_read(&fscache_n_store_vmscan_busy),
46769 - atomic_read(&fscache_n_store_vmscan_cancelled));
46770 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46771 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46772 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46773 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46774
46775 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46776 - atomic_read(&fscache_n_op_pend),
46777 - atomic_read(&fscache_n_op_run),
46778 - atomic_read(&fscache_n_op_enqueue),
46779 - atomic_read(&fscache_n_op_cancelled),
46780 - atomic_read(&fscache_n_op_rejected));
46781 + atomic_read_unchecked(&fscache_n_op_pend),
46782 + atomic_read_unchecked(&fscache_n_op_run),
46783 + atomic_read_unchecked(&fscache_n_op_enqueue),
46784 + atomic_read_unchecked(&fscache_n_op_cancelled),
46785 + atomic_read_unchecked(&fscache_n_op_rejected));
46786 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46787 - atomic_read(&fscache_n_op_deferred_release),
46788 - atomic_read(&fscache_n_op_release),
46789 - atomic_read(&fscache_n_op_gc));
46790 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46791 + atomic_read_unchecked(&fscache_n_op_release),
46792 + atomic_read_unchecked(&fscache_n_op_gc));
46793
46794 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46795 atomic_read(&fscache_n_cop_alloc_object),
46796 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46797 index 3426521..3b75162 100644
46798 --- a/fs/fuse/cuse.c
46799 +++ b/fs/fuse/cuse.c
46800 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46801 INIT_LIST_HEAD(&cuse_conntbl[i]);
46802
46803 /* inherit and extend fuse_dev_operations */
46804 - cuse_channel_fops = fuse_dev_operations;
46805 - cuse_channel_fops.owner = THIS_MODULE;
46806 - cuse_channel_fops.open = cuse_channel_open;
46807 - cuse_channel_fops.release = cuse_channel_release;
46808 + pax_open_kernel();
46809 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46810 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46811 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46812 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46813 + pax_close_kernel();
46814
46815 cuse_class = class_create(THIS_MODULE, "cuse");
46816 if (IS_ERR(cuse_class))
46817 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46818 index 5f3368a..8306426 100644
46819 --- a/fs/fuse/dev.c
46820 +++ b/fs/fuse/dev.c
46821 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46822 ret = 0;
46823 pipe_lock(pipe);
46824
46825 - if (!pipe->readers) {
46826 + if (!atomic_read(&pipe->readers)) {
46827 send_sig(SIGPIPE, current, 0);
46828 if (!ret)
46829 ret = -EPIPE;
46830 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46831 index 2066328..f5add3b 100644
46832 --- a/fs/fuse/dir.c
46833 +++ b/fs/fuse/dir.c
46834 @@ -1175,7 +1175,7 @@ static char *read_link(struct dentry *dentry)
46835 return link;
46836 }
46837
46838 -static void free_link(char *link)
46839 +static void free_link(const char *link)
46840 {
46841 if (!IS_ERR(link))
46842 free_page((unsigned long) link);
46843 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46844 index 5698746..6086012 100644
46845 --- a/fs/gfs2/inode.c
46846 +++ b/fs/gfs2/inode.c
46847 @@ -1487,7 +1487,7 @@ out:
46848
46849 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46850 {
46851 - char *s = nd_get_link(nd);
46852 + const char *s = nd_get_link(nd);
46853 if (!IS_ERR(s))
46854 kfree(s);
46855 }
46856 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46857 index 3645cd3..786809c 100644
46858 --- a/fs/hugetlbfs/inode.c
46859 +++ b/fs/hugetlbfs/inode.c
46860 @@ -914,7 +914,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46861 .kill_sb = kill_litter_super,
46862 };
46863
46864 -static struct vfsmount *hugetlbfs_vfsmount;
46865 +struct vfsmount *hugetlbfs_vfsmount;
46866
46867 static int can_do_hugetlb_shm(void)
46868 {
46869 diff --git a/fs/inode.c b/fs/inode.c
46870 index 83ab215..8842101 100644
46871 --- a/fs/inode.c
46872 +++ b/fs/inode.c
46873 @@ -870,8 +870,8 @@ unsigned int get_next_ino(void)
46874
46875 #ifdef CONFIG_SMP
46876 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46877 - static atomic_t shared_last_ino;
46878 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46879 + static atomic_unchecked_t shared_last_ino;
46880 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46881
46882 res = next - LAST_INO_BATCH;
46883 }
46884 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46885 index eafb8d3..f423d37 100644
46886 --- a/fs/jffs2/erase.c
46887 +++ b/fs/jffs2/erase.c
46888 @@ -438,7 +438,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46889 struct jffs2_unknown_node marker = {
46890 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46891 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46892 - .totlen = cpu_to_je32(c->cleanmarker_size)
46893 + .totlen = cpu_to_je32(c->cleanmarker_size),
46894 + .hdr_crc = cpu_to_je32(0)
46895 };
46896
46897 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46898 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46899 index 30e8f47..21f600c 100644
46900 --- a/fs/jffs2/wbuf.c
46901 +++ b/fs/jffs2/wbuf.c
46902 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46903 {
46904 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46905 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46906 - .totlen = constant_cpu_to_je32(8)
46907 + .totlen = constant_cpu_to_je32(8),
46908 + .hdr_crc = constant_cpu_to_je32(0)
46909 };
46910
46911 /*
46912 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46913 index 682bca6..86b8e6e 100644
46914 --- a/fs/jfs/super.c
46915 +++ b/fs/jfs/super.c
46916 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46917
46918 jfs_inode_cachep =
46919 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46920 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46921 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46922 init_once);
46923 if (jfs_inode_cachep == NULL)
46924 return -ENOMEM;
46925 diff --git a/fs/libfs.c b/fs/libfs.c
46926 index 5b2dbb3..7442d54 100644
46927 --- a/fs/libfs.c
46928 +++ b/fs/libfs.c
46929 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46930
46931 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46932 struct dentry *next;
46933 + char d_name[sizeof(next->d_iname)];
46934 + const unsigned char *name;
46935 +
46936 next = list_entry(p, struct dentry, d_u.d_child);
46937 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46938 if (!simple_positive(next)) {
46939 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46940
46941 spin_unlock(&next->d_lock);
46942 spin_unlock(&dentry->d_lock);
46943 - if (filldir(dirent, next->d_name.name,
46944 + name = next->d_name.name;
46945 + if (name == next->d_iname) {
46946 + memcpy(d_name, name, next->d_name.len);
46947 + name = d_name;
46948 + }
46949 + if (filldir(dirent, name,
46950 next->d_name.len, filp->f_pos,
46951 next->d_inode->i_ino,
46952 dt_type(next->d_inode)) < 0)
46953 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46954 index 8392cb8..80d6193 100644
46955 --- a/fs/lockd/clntproc.c
46956 +++ b/fs/lockd/clntproc.c
46957 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46958 /*
46959 * Cookie counter for NLM requests
46960 */
46961 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46962 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46963
46964 void nlmclnt_next_cookie(struct nlm_cookie *c)
46965 {
46966 - u32 cookie = atomic_inc_return(&nlm_cookie);
46967 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46968
46969 memcpy(c->data, &cookie, 4);
46970 c->len=4;
46971 diff --git a/fs/locks.c b/fs/locks.c
46972 index 0d68f1f..f216b79 100644
46973 --- a/fs/locks.c
46974 +++ b/fs/locks.c
46975 @@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
46976 return;
46977
46978 if (filp->f_op && filp->f_op->flock) {
46979 - struct file_lock fl = {
46980 + struct file_lock flock = {
46981 .fl_pid = current->tgid,
46982 .fl_file = filp,
46983 .fl_flags = FL_FLOCK,
46984 .fl_type = F_UNLCK,
46985 .fl_end = OFFSET_MAX,
46986 };
46987 - filp->f_op->flock(filp, F_SETLKW, &fl);
46988 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46989 - fl.fl_ops->fl_release_private(&fl);
46990 + filp->f_op->flock(filp, F_SETLKW, &flock);
46991 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46992 + flock.fl_ops->fl_release_private(&flock);
46993 }
46994
46995 lock_flocks();
46996 diff --git a/fs/namei.c b/fs/namei.c
46997 index 46ea9cc..c7cf3a3 100644
46998 --- a/fs/namei.c
46999 +++ b/fs/namei.c
47000 @@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
47001 if (ret != -EACCES)
47002 return ret;
47003
47004 +#ifdef CONFIG_GRKERNSEC
47005 + /* we'll block if we have to log due to a denied capability use */
47006 + if (mask & MAY_NOT_BLOCK)
47007 + return -ECHILD;
47008 +#endif
47009 +
47010 if (S_ISDIR(inode->i_mode)) {
47011 /* DACs are overridable for directories */
47012 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
47013 - return 0;
47014 if (!(mask & MAY_WRITE))
47015 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
47016 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
47017 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
47018 return 0;
47019 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
47020 + return 0;
47021 return -EACCES;
47022 }
47023 /*
47024 + * Searching includes executable on directories, else just read.
47025 + */
47026 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47027 + if (mask == MAY_READ)
47028 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
47029 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
47030 + return 0;
47031 +
47032 + /*
47033 * Read/write DACs are always overridable.
47034 * Executable DACs are overridable when there is
47035 * at least one exec bit set.
47036 @@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
47037 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
47038 return 0;
47039
47040 - /*
47041 - * Searching includes executable on directories, else just read.
47042 - */
47043 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47044 - if (mask == MAY_READ)
47045 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
47046 - return 0;
47047 -
47048 return -EACCES;
47049 }
47050
47051 @@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47052 return error;
47053 }
47054
47055 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47056 + dentry->d_inode, dentry, nd->path.mnt)) {
47057 + error = -EACCES;
47058 + *p = ERR_PTR(error); /* no ->put_link(), please */
47059 + path_put(&nd->path);
47060 + return error;
47061 + }
47062 +
47063 nd->last_type = LAST_BIND;
47064 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47065 error = PTR_ERR(*p);
47066 if (!IS_ERR(*p)) {
47067 - char *s = nd_get_link(nd);
47068 + const char *s = nd_get_link(nd);
47069 error = 0;
47070 if (s)
47071 error = __vfs_follow_link(nd, s);
47072 @@ -1650,6 +1666,21 @@ static int path_lookupat(int dfd, const char *name,
47073 if (!err)
47074 err = complete_walk(nd);
47075
47076 + if (!(nd->flags & LOOKUP_PARENT)) {
47077 +#ifdef CONFIG_GRKERNSEC
47078 + if (flags & LOOKUP_RCU) {
47079 + if (!err)
47080 + path_put(&nd->path);
47081 + err = -ECHILD;
47082 + } else
47083 +#endif
47084 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47085 + if (!err)
47086 + path_put(&nd->path);
47087 + err = -ENOENT;
47088 + }
47089 + }
47090 +
47091 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47092 if (!nd->inode->i_op->lookup) {
47093 path_put(&nd->path);
47094 @@ -1677,6 +1708,15 @@ static int do_path_lookup(int dfd, const char *name,
47095 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47096
47097 if (likely(!retval)) {
47098 + if (*name != '/' && nd->path.dentry && nd->inode) {
47099 +#ifdef CONFIG_GRKERNSEC
47100 + if (flags & LOOKUP_RCU)
47101 + return -ECHILD;
47102 +#endif
47103 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47104 + return -ENOENT;
47105 + }
47106 +
47107 if (unlikely(!audit_dummy_context())) {
47108 if (nd->path.dentry && nd->inode)
47109 audit_inode(name, nd->path.dentry);
47110 @@ -2071,6 +2111,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47111 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47112 return -EPERM;
47113
47114 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47115 + return -EPERM;
47116 + if (gr_handle_rawio(inode))
47117 + return -EPERM;
47118 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47119 + return -EACCES;
47120 +
47121 return 0;
47122 }
47123
47124 @@ -2132,6 +2179,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47125 error = complete_walk(nd);
47126 if (error)
47127 return ERR_PTR(error);
47128 +#ifdef CONFIG_GRKERNSEC
47129 + if (nd->flags & LOOKUP_RCU) {
47130 + error = -ECHILD;
47131 + goto exit;
47132 + }
47133 +#endif
47134 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47135 + error = -ENOENT;
47136 + goto exit;
47137 + }
47138 audit_inode(pathname, nd->path.dentry);
47139 if (open_flag & O_CREAT) {
47140 error = -EISDIR;
47141 @@ -2142,6 +2199,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47142 error = complete_walk(nd);
47143 if (error)
47144 return ERR_PTR(error);
47145 +#ifdef CONFIG_GRKERNSEC
47146 + if (nd->flags & LOOKUP_RCU) {
47147 + error = -ECHILD;
47148 + goto exit;
47149 + }
47150 +#endif
47151 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47152 + error = -ENOENT;
47153 + goto exit;
47154 + }
47155 audit_inode(pathname, dir);
47156 goto ok;
47157 }
47158 @@ -2163,6 +2230,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47159 error = complete_walk(nd);
47160 if (error)
47161 return ERR_PTR(error);
47162 +#ifdef CONFIG_GRKERNSEC
47163 + if (nd->flags & LOOKUP_RCU) {
47164 + error = -ECHILD;
47165 + goto exit;
47166 + }
47167 +#endif
47168 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47169 + error = -ENOENT;
47170 + goto exit;
47171 + }
47172
47173 error = -ENOTDIR;
47174 if (nd->flags & LOOKUP_DIRECTORY) {
47175 @@ -2203,6 +2280,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47176 /* Negative dentry, just create the file */
47177 if (!dentry->d_inode) {
47178 umode_t mode = op->mode;
47179 +
47180 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47181 + error = -EACCES;
47182 + goto exit_mutex_unlock;
47183 + }
47184 +
47185 if (!IS_POSIXACL(dir->d_inode))
47186 mode &= ~current_umask();
47187 /*
47188 @@ -2226,6 +2309,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47189 error = vfs_create(dir->d_inode, dentry, mode, nd);
47190 if (error)
47191 goto exit_mutex_unlock;
47192 + else
47193 + gr_handle_create(path->dentry, path->mnt);
47194 mutex_unlock(&dir->d_inode->i_mutex);
47195 dput(nd->path.dentry);
47196 nd->path.dentry = dentry;
47197 @@ -2235,6 +2320,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47198 /*
47199 * It already exists.
47200 */
47201 +
47202 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47203 + error = -ENOENT;
47204 + goto exit_mutex_unlock;
47205 + }
47206 +
47207 + /* only check if O_CREAT is specified, all other checks need to go
47208 + into may_open */
47209 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47210 + error = -EACCES;
47211 + goto exit_mutex_unlock;
47212 + }
47213 +
47214 mutex_unlock(&dir->d_inode->i_mutex);
47215 audit_inode(pathname, path->dentry);
47216
47217 @@ -2447,6 +2545,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47218 *path = nd.path;
47219 return dentry;
47220 eexist:
47221 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47222 + dput(dentry);
47223 + dentry = ERR_PTR(-ENOENT);
47224 + goto fail;
47225 + }
47226 dput(dentry);
47227 dentry = ERR_PTR(-EEXIST);
47228 fail:
47229 @@ -2469,6 +2572,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47230 }
47231 EXPORT_SYMBOL(user_path_create);
47232
47233 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47234 +{
47235 + char *tmp = getname(pathname);
47236 + struct dentry *res;
47237 + if (IS_ERR(tmp))
47238 + return ERR_CAST(tmp);
47239 + res = kern_path_create(dfd, tmp, path, is_dir);
47240 + if (IS_ERR(res))
47241 + putname(tmp);
47242 + else
47243 + *to = tmp;
47244 + return res;
47245 +}
47246 +
47247 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47248 {
47249 int error = may_create(dir, dentry);
47250 @@ -2536,6 +2653,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47251 error = mnt_want_write(path.mnt);
47252 if (error)
47253 goto out_dput;
47254 +
47255 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47256 + error = -EPERM;
47257 + goto out_drop_write;
47258 + }
47259 +
47260 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47261 + error = -EACCES;
47262 + goto out_drop_write;
47263 + }
47264 +
47265 error = security_path_mknod(&path, dentry, mode, dev);
47266 if (error)
47267 goto out_drop_write;
47268 @@ -2553,6 +2681,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47269 }
47270 out_drop_write:
47271 mnt_drop_write(path.mnt);
47272 +
47273 + if (!error)
47274 + gr_handle_create(dentry, path.mnt);
47275 out_dput:
47276 dput(dentry);
47277 mutex_unlock(&path.dentry->d_inode->i_mutex);
47278 @@ -2602,12 +2733,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47279 error = mnt_want_write(path.mnt);
47280 if (error)
47281 goto out_dput;
47282 +
47283 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47284 + error = -EACCES;
47285 + goto out_drop_write;
47286 + }
47287 +
47288 error = security_path_mkdir(&path, dentry, mode);
47289 if (error)
47290 goto out_drop_write;
47291 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47292 out_drop_write:
47293 mnt_drop_write(path.mnt);
47294 +
47295 + if (!error)
47296 + gr_handle_create(dentry, path.mnt);
47297 out_dput:
47298 dput(dentry);
47299 mutex_unlock(&path.dentry->d_inode->i_mutex);
47300 @@ -2687,6 +2827,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47301 char * name;
47302 struct dentry *dentry;
47303 struct nameidata nd;
47304 + ino_t saved_ino = 0;
47305 + dev_t saved_dev = 0;
47306
47307 error = user_path_parent(dfd, pathname, &nd, &name);
47308 if (error)
47309 @@ -2715,6 +2857,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47310 error = -ENOENT;
47311 goto exit3;
47312 }
47313 +
47314 + saved_ino = dentry->d_inode->i_ino;
47315 + saved_dev = gr_get_dev_from_dentry(dentry);
47316 +
47317 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47318 + error = -EACCES;
47319 + goto exit3;
47320 + }
47321 +
47322 error = mnt_want_write(nd.path.mnt);
47323 if (error)
47324 goto exit3;
47325 @@ -2722,6 +2873,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47326 if (error)
47327 goto exit4;
47328 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47329 + if (!error && (saved_dev || saved_ino))
47330 + gr_handle_delete(saved_ino, saved_dev);
47331 exit4:
47332 mnt_drop_write(nd.path.mnt);
47333 exit3:
47334 @@ -2784,6 +2937,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47335 struct dentry *dentry;
47336 struct nameidata nd;
47337 struct inode *inode = NULL;
47338 + ino_t saved_ino = 0;
47339 + dev_t saved_dev = 0;
47340
47341 error = user_path_parent(dfd, pathname, &nd, &name);
47342 if (error)
47343 @@ -2806,6 +2961,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47344 if (!inode)
47345 goto slashes;
47346 ihold(inode);
47347 +
47348 + if (inode->i_nlink <= 1) {
47349 + saved_ino = inode->i_ino;
47350 + saved_dev = gr_get_dev_from_dentry(dentry);
47351 + }
47352 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47353 + error = -EACCES;
47354 + goto exit2;
47355 + }
47356 +
47357 error = mnt_want_write(nd.path.mnt);
47358 if (error)
47359 goto exit2;
47360 @@ -2813,6 +2978,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47361 if (error)
47362 goto exit3;
47363 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47364 + if (!error && (saved_ino || saved_dev))
47365 + gr_handle_delete(saved_ino, saved_dev);
47366 exit3:
47367 mnt_drop_write(nd.path.mnt);
47368 exit2:
47369 @@ -2888,10 +3055,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47370 error = mnt_want_write(path.mnt);
47371 if (error)
47372 goto out_dput;
47373 +
47374 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47375 + error = -EACCES;
47376 + goto out_drop_write;
47377 + }
47378 +
47379 error = security_path_symlink(&path, dentry, from);
47380 if (error)
47381 goto out_drop_write;
47382 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47383 + if (!error)
47384 + gr_handle_create(dentry, path.mnt);
47385 out_drop_write:
47386 mnt_drop_write(path.mnt);
47387 out_dput:
47388 @@ -2963,6 +3138,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47389 {
47390 struct dentry *new_dentry;
47391 struct path old_path, new_path;
47392 + char *to = NULL;
47393 int how = 0;
47394 int error;
47395
47396 @@ -2986,7 +3162,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47397 if (error)
47398 return error;
47399
47400 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47401 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47402 error = PTR_ERR(new_dentry);
47403 if (IS_ERR(new_dentry))
47404 goto out;
47405 @@ -2997,13 +3173,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47406 error = mnt_want_write(new_path.mnt);
47407 if (error)
47408 goto out_dput;
47409 +
47410 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47411 + old_path.dentry->d_inode,
47412 + old_path.dentry->d_inode->i_mode, to)) {
47413 + error = -EACCES;
47414 + goto out_drop_write;
47415 + }
47416 +
47417 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47418 + old_path.dentry, old_path.mnt, to)) {
47419 + error = -EACCES;
47420 + goto out_drop_write;
47421 + }
47422 +
47423 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47424 if (error)
47425 goto out_drop_write;
47426 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47427 + if (!error)
47428 + gr_handle_create(new_dentry, new_path.mnt);
47429 out_drop_write:
47430 mnt_drop_write(new_path.mnt);
47431 out_dput:
47432 + putname(to);
47433 dput(new_dentry);
47434 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47435 path_put(&new_path);
47436 @@ -3231,6 +3424,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47437 if (new_dentry == trap)
47438 goto exit5;
47439
47440 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47441 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47442 + to);
47443 + if (error)
47444 + goto exit5;
47445 +
47446 error = mnt_want_write(oldnd.path.mnt);
47447 if (error)
47448 goto exit5;
47449 @@ -3240,6 +3439,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47450 goto exit6;
47451 error = vfs_rename(old_dir->d_inode, old_dentry,
47452 new_dir->d_inode, new_dentry);
47453 + if (!error)
47454 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47455 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47456 exit6:
47457 mnt_drop_write(oldnd.path.mnt);
47458 exit5:
47459 @@ -3265,6 +3467,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47460
47461 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47462 {
47463 + char tmpbuf[64];
47464 + const char *newlink;
47465 int len;
47466
47467 len = PTR_ERR(link);
47468 @@ -3274,7 +3478,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47469 len = strlen(link);
47470 if (len > (unsigned) buflen)
47471 len = buflen;
47472 - if (copy_to_user(buffer, link, len))
47473 +
47474 + if (len < sizeof(tmpbuf)) {
47475 + memcpy(tmpbuf, link, len);
47476 + newlink = tmpbuf;
47477 + } else
47478 + newlink = link;
47479 +
47480 + if (copy_to_user(buffer, newlink, len))
47481 len = -EFAULT;
47482 out:
47483 return len;
47484 diff --git a/fs/namespace.c b/fs/namespace.c
47485 index e608199..9609cb9 100644
47486 --- a/fs/namespace.c
47487 +++ b/fs/namespace.c
47488 @@ -1155,6 +1155,9 @@ static int do_umount(struct mount *mnt, int flags)
47489 if (!(sb->s_flags & MS_RDONLY))
47490 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47491 up_write(&sb->s_umount);
47492 +
47493 + gr_log_remount(mnt->mnt_devname, retval);
47494 +
47495 return retval;
47496 }
47497
47498 @@ -1174,6 +1177,9 @@ static int do_umount(struct mount *mnt, int flags)
47499 br_write_unlock(vfsmount_lock);
47500 up_write(&namespace_sem);
47501 release_mounts(&umount_list);
47502 +
47503 + gr_log_unmount(mnt->mnt_devname, retval);
47504 +
47505 return retval;
47506 }
47507
47508 @@ -2175,6 +2181,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47509 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47510 MS_STRICTATIME);
47511
47512 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47513 + retval = -EPERM;
47514 + goto dput_out;
47515 + }
47516 +
47517 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47518 + retval = -EPERM;
47519 + goto dput_out;
47520 + }
47521 +
47522 if (flags & MS_REMOUNT)
47523 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47524 data_page);
47525 @@ -2189,6 +2205,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47526 dev_name, data_page);
47527 dput_out:
47528 path_put(&path);
47529 +
47530 + gr_log_mount(dev_name, dir_name, retval);
47531 +
47532 return retval;
47533 }
47534
47535 @@ -2470,6 +2489,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47536 if (error)
47537 goto out2;
47538
47539 + if (gr_handle_chroot_pivot()) {
47540 + error = -EPERM;
47541 + goto out2;
47542 + }
47543 +
47544 get_fs_root(current->fs, &root);
47545 error = lock_mount(&old);
47546 if (error)
47547 diff --git a/fs/ncpfs/ncplib_kernel.h b/fs/ncpfs/ncplib_kernel.h
47548 index 32c0658..b1c2045e 100644
47549 --- a/fs/ncpfs/ncplib_kernel.h
47550 +++ b/fs/ncpfs/ncplib_kernel.h
47551 @@ -130,7 +130,7 @@ static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int voln
47552 int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *,
47553 const unsigned char *, unsigned int, int);
47554 int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
47555 - const unsigned char *, unsigned int, int);
47556 + const unsigned char *, unsigned int, int) __size_overflow(5);
47557
47558 #define NCP_ESC ':'
47559 #define NCP_IO_TABLE(sb) (NCP_SBP(sb)->nls_io)
47560 @@ -146,7 +146,7 @@ int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
47561 int ncp__io2vol(unsigned char *, unsigned int *,
47562 const unsigned char *, unsigned int, int);
47563 int ncp__vol2io(unsigned char *, unsigned int *,
47564 - const unsigned char *, unsigned int, int);
47565 + const unsigned char *, unsigned int, int) __size_overflow(5);
47566
47567 #define NCP_IO_TABLE(sb) NULL
47568 #define ncp_tolower(t, c) tolower(c)
47569 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47570 index f649fba..236bf92 100644
47571 --- a/fs/nfs/inode.c
47572 +++ b/fs/nfs/inode.c
47573 @@ -151,7 +151,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47574 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47575 nfsi->attrtimeo_timestamp = jiffies;
47576
47577 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47578 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47579 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47580 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47581 else
47582 @@ -1003,16 +1003,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47583 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47584 }
47585
47586 -static atomic_long_t nfs_attr_generation_counter;
47587 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47588
47589 static unsigned long nfs_read_attr_generation_counter(void)
47590 {
47591 - return atomic_long_read(&nfs_attr_generation_counter);
47592 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47593 }
47594
47595 unsigned long nfs_inc_attr_generation_counter(void)
47596 {
47597 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47598 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47599 }
47600
47601 void nfs_fattr_init(struct nfs_fattr *fattr)
47602 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47603 index edf6d3e..bdd1da7 100644
47604 --- a/fs/nfsd/vfs.c
47605 +++ b/fs/nfsd/vfs.c
47606 @@ -925,7 +925,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47607 } else {
47608 oldfs = get_fs();
47609 set_fs(KERNEL_DS);
47610 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47611 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47612 set_fs(oldfs);
47613 }
47614
47615 @@ -1029,7 +1029,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47616
47617 /* Write the data. */
47618 oldfs = get_fs(); set_fs(KERNEL_DS);
47619 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47620 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47621 set_fs(oldfs);
47622 if (host_err < 0)
47623 goto out_nfserr;
47624 @@ -1564,7 +1564,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47625 */
47626
47627 oldfs = get_fs(); set_fs(KERNEL_DS);
47628 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
47629 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
47630 set_fs(oldfs);
47631
47632 if (host_err < 0)
47633 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47634 index 3568c8a..e0240d8 100644
47635 --- a/fs/notify/fanotify/fanotify_user.c
47636 +++ b/fs/notify/fanotify/fanotify_user.c
47637 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47638 goto out_close_fd;
47639
47640 ret = -EFAULT;
47641 - if (copy_to_user(buf, &fanotify_event_metadata,
47642 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47643 + copy_to_user(buf, &fanotify_event_metadata,
47644 fanotify_event_metadata.event_len))
47645 goto out_kill_access_response;
47646
47647 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47648 index ee18815..7aa5d01 100644
47649 --- a/fs/notify/notification.c
47650 +++ b/fs/notify/notification.c
47651 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47652 * get set to 0 so it will never get 'freed'
47653 */
47654 static struct fsnotify_event *q_overflow_event;
47655 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47656 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47657
47658 /**
47659 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47660 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47661 */
47662 u32 fsnotify_get_cookie(void)
47663 {
47664 - return atomic_inc_return(&fsnotify_sync_cookie);
47665 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47666 }
47667 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47668
47669 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47670 index 99e3610..02c1068 100644
47671 --- a/fs/ntfs/dir.c
47672 +++ b/fs/ntfs/dir.c
47673 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47674 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47675 ~(s64)(ndir->itype.index.block_size - 1)));
47676 /* Bounds checks. */
47677 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47678 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47679 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47680 "inode 0x%lx or driver bug.", vdir->i_ino);
47681 goto err_out;
47682 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47683 index c587e2d..3641eaa 100644
47684 --- a/fs/ntfs/file.c
47685 +++ b/fs/ntfs/file.c
47686 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47687 #endif /* NTFS_RW */
47688 };
47689
47690 -const struct file_operations ntfs_empty_file_ops = {};
47691 +const struct file_operations ntfs_empty_file_ops __read_only;
47692
47693 -const struct inode_operations ntfs_empty_inode_ops = {};
47694 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47695 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47696 index 210c352..a174f83 100644
47697 --- a/fs/ocfs2/localalloc.c
47698 +++ b/fs/ocfs2/localalloc.c
47699 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47700 goto bail;
47701 }
47702
47703 - atomic_inc(&osb->alloc_stats.moves);
47704 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47705
47706 bail:
47707 if (handle)
47708 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47709 index d355e6e..578d905 100644
47710 --- a/fs/ocfs2/ocfs2.h
47711 +++ b/fs/ocfs2/ocfs2.h
47712 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47713
47714 struct ocfs2_alloc_stats
47715 {
47716 - atomic_t moves;
47717 - atomic_t local_data;
47718 - atomic_t bitmap_data;
47719 - atomic_t bg_allocs;
47720 - atomic_t bg_extends;
47721 + atomic_unchecked_t moves;
47722 + atomic_unchecked_t local_data;
47723 + atomic_unchecked_t bitmap_data;
47724 + atomic_unchecked_t bg_allocs;
47725 + atomic_unchecked_t bg_extends;
47726 };
47727
47728 enum ocfs2_local_alloc_state
47729 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47730 index f169da4..9112253 100644
47731 --- a/fs/ocfs2/suballoc.c
47732 +++ b/fs/ocfs2/suballoc.c
47733 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47734 mlog_errno(status);
47735 goto bail;
47736 }
47737 - atomic_inc(&osb->alloc_stats.bg_extends);
47738 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47739
47740 /* You should never ask for this much metadata */
47741 BUG_ON(bits_wanted >
47742 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47743 mlog_errno(status);
47744 goto bail;
47745 }
47746 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47747 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47748
47749 *suballoc_loc = res.sr_bg_blkno;
47750 *suballoc_bit_start = res.sr_bit_offset;
47751 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47752 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47753 res->sr_bits);
47754
47755 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47756 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47757
47758 BUG_ON(res->sr_bits != 1);
47759
47760 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47761 mlog_errno(status);
47762 goto bail;
47763 }
47764 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47765 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47766
47767 BUG_ON(res.sr_bits != 1);
47768
47769 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47770 cluster_start,
47771 num_clusters);
47772 if (!status)
47773 - atomic_inc(&osb->alloc_stats.local_data);
47774 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47775 } else {
47776 if (min_clusters > (osb->bitmap_cpg - 1)) {
47777 /* The only paths asking for contiguousness
47778 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47779 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47780 res.sr_bg_blkno,
47781 res.sr_bit_offset);
47782 - atomic_inc(&osb->alloc_stats.bitmap_data);
47783 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47784 *num_clusters = res.sr_bits;
47785 }
47786 }
47787 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47788 index 604e12c..8426483 100644
47789 --- a/fs/ocfs2/super.c
47790 +++ b/fs/ocfs2/super.c
47791 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47792 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47793 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47794 "Stats",
47795 - atomic_read(&osb->alloc_stats.bitmap_data),
47796 - atomic_read(&osb->alloc_stats.local_data),
47797 - atomic_read(&osb->alloc_stats.bg_allocs),
47798 - atomic_read(&osb->alloc_stats.moves),
47799 - atomic_read(&osb->alloc_stats.bg_extends));
47800 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47801 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47802 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47803 + atomic_read_unchecked(&osb->alloc_stats.moves),
47804 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47805
47806 out += snprintf(buf + out, len - out,
47807 "%10s => State: %u Descriptor: %llu Size: %u bits "
47808 @@ -2117,11 +2117,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47809 spin_lock_init(&osb->osb_xattr_lock);
47810 ocfs2_init_steal_slots(osb);
47811
47812 - atomic_set(&osb->alloc_stats.moves, 0);
47813 - atomic_set(&osb->alloc_stats.local_data, 0);
47814 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47815 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47816 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47817 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47818 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47819 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47820 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47821 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47822
47823 /* Copy the blockcheck stats from the superblock probe */
47824 osb->osb_ecc_stats = *stats;
47825 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47826 index 5d22872..523db20 100644
47827 --- a/fs/ocfs2/symlink.c
47828 +++ b/fs/ocfs2/symlink.c
47829 @@ -142,7 +142,7 @@ bail:
47830
47831 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47832 {
47833 - char *link = nd_get_link(nd);
47834 + const char *link = nd_get_link(nd);
47835 if (!IS_ERR(link))
47836 kfree(link);
47837 }
47838 diff --git a/fs/open.c b/fs/open.c
47839 index 77becc0..aad7bd9 100644
47840 --- a/fs/open.c
47841 +++ b/fs/open.c
47842 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47843 error = locks_verify_truncate(inode, NULL, length);
47844 if (!error)
47845 error = security_path_truncate(&path);
47846 +
47847 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47848 + error = -EACCES;
47849 +
47850 if (!error)
47851 error = do_truncate(path.dentry, length, 0, NULL);
47852
47853 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47854 if (__mnt_is_readonly(path.mnt))
47855 res = -EROFS;
47856
47857 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47858 + res = -EACCES;
47859 +
47860 out_path_release:
47861 path_put(&path);
47862 out:
47863 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47864 if (error)
47865 goto dput_and_out;
47866
47867 + gr_log_chdir(path.dentry, path.mnt);
47868 +
47869 set_fs_pwd(current->fs, &path);
47870
47871 dput_and_out:
47872 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47873 goto out_putf;
47874
47875 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47876 +
47877 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47878 + error = -EPERM;
47879 +
47880 + if (!error)
47881 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47882 +
47883 if (!error)
47884 set_fs_pwd(current->fs, &file->f_path);
47885 out_putf:
47886 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47887 if (error)
47888 goto dput_and_out;
47889
47890 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47891 + goto dput_and_out;
47892 +
47893 set_fs_root(current->fs, &path);
47894 +
47895 + gr_handle_chroot_chdir(&path);
47896 +
47897 error = 0;
47898 dput_and_out:
47899 path_put(&path);
47900 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
47901 if (error)
47902 return error;
47903 mutex_lock(&inode->i_mutex);
47904 +
47905 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47906 + error = -EACCES;
47907 + goto out_unlock;
47908 + }
47909 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47910 + error = -EACCES;
47911 + goto out_unlock;
47912 + }
47913 +
47914 error = security_path_chmod(path, mode);
47915 if (error)
47916 goto out_unlock;
47917 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47918 int error;
47919 struct iattr newattrs;
47920
47921 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47922 + return -EACCES;
47923 +
47924 newattrs.ia_valid = ATTR_CTIME;
47925 if (user != (uid_t) -1) {
47926 newattrs.ia_valid |= ATTR_UID;
47927 diff --git a/fs/pipe.c b/fs/pipe.c
47928 index 82e651b..8a68573 100644
47929 --- a/fs/pipe.c
47930 +++ b/fs/pipe.c
47931 @@ -437,9 +437,9 @@ redo:
47932 }
47933 if (bufs) /* More to do? */
47934 continue;
47935 - if (!pipe->writers)
47936 + if (!atomic_read(&pipe->writers))
47937 break;
47938 - if (!pipe->waiting_writers) {
47939 + if (!atomic_read(&pipe->waiting_writers)) {
47940 /* syscall merging: Usually we must not sleep
47941 * if O_NONBLOCK is set, or if we got some data.
47942 * But if a writer sleeps in kernel space, then
47943 @@ -503,7 +503,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47944 mutex_lock(&inode->i_mutex);
47945 pipe = inode->i_pipe;
47946
47947 - if (!pipe->readers) {
47948 + if (!atomic_read(&pipe->readers)) {
47949 send_sig(SIGPIPE, current, 0);
47950 ret = -EPIPE;
47951 goto out;
47952 @@ -552,7 +552,7 @@ redo1:
47953 for (;;) {
47954 int bufs;
47955
47956 - if (!pipe->readers) {
47957 + if (!atomic_read(&pipe->readers)) {
47958 send_sig(SIGPIPE, current, 0);
47959 if (!ret)
47960 ret = -EPIPE;
47961 @@ -643,9 +643,9 @@ redo2:
47962 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47963 do_wakeup = 0;
47964 }
47965 - pipe->waiting_writers++;
47966 + atomic_inc(&pipe->waiting_writers);
47967 pipe_wait(pipe);
47968 - pipe->waiting_writers--;
47969 + atomic_dec(&pipe->waiting_writers);
47970 }
47971 out:
47972 mutex_unlock(&inode->i_mutex);
47973 @@ -712,7 +712,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47974 mask = 0;
47975 if (filp->f_mode & FMODE_READ) {
47976 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47977 - if (!pipe->writers && filp->f_version != pipe->w_counter)
47978 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47979 mask |= POLLHUP;
47980 }
47981
47982 @@ -722,7 +722,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47983 * Most Unices do not set POLLERR for FIFOs but on Linux they
47984 * behave exactly like pipes for poll().
47985 */
47986 - if (!pipe->readers)
47987 + if (!atomic_read(&pipe->readers))
47988 mask |= POLLERR;
47989 }
47990
47991 @@ -736,10 +736,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47992
47993 mutex_lock(&inode->i_mutex);
47994 pipe = inode->i_pipe;
47995 - pipe->readers -= decr;
47996 - pipe->writers -= decw;
47997 + atomic_sub(decr, &pipe->readers);
47998 + atomic_sub(decw, &pipe->writers);
47999
48000 - if (!pipe->readers && !pipe->writers) {
48001 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48002 free_pipe_info(inode);
48003 } else {
48004 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48005 @@ -829,7 +829,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48006
48007 if (inode->i_pipe) {
48008 ret = 0;
48009 - inode->i_pipe->readers++;
48010 + atomic_inc(&inode->i_pipe->readers);
48011 }
48012
48013 mutex_unlock(&inode->i_mutex);
48014 @@ -846,7 +846,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48015
48016 if (inode->i_pipe) {
48017 ret = 0;
48018 - inode->i_pipe->writers++;
48019 + atomic_inc(&inode->i_pipe->writers);
48020 }
48021
48022 mutex_unlock(&inode->i_mutex);
48023 @@ -864,9 +864,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48024 if (inode->i_pipe) {
48025 ret = 0;
48026 if (filp->f_mode & FMODE_READ)
48027 - inode->i_pipe->readers++;
48028 + atomic_inc(&inode->i_pipe->readers);
48029 if (filp->f_mode & FMODE_WRITE)
48030 - inode->i_pipe->writers++;
48031 + atomic_inc(&inode->i_pipe->writers);
48032 }
48033
48034 mutex_unlock(&inode->i_mutex);
48035 @@ -958,7 +958,7 @@ void free_pipe_info(struct inode *inode)
48036 inode->i_pipe = NULL;
48037 }
48038
48039 -static struct vfsmount *pipe_mnt __read_mostly;
48040 +struct vfsmount *pipe_mnt __read_mostly;
48041
48042 /*
48043 * pipefs_dname() is called from d_path().
48044 @@ -988,7 +988,8 @@ static struct inode * get_pipe_inode(void)
48045 goto fail_iput;
48046 inode->i_pipe = pipe;
48047
48048 - pipe->readers = pipe->writers = 1;
48049 + atomic_set(&pipe->readers, 1);
48050 + atomic_set(&pipe->writers, 1);
48051 inode->i_fop = &rdwr_pipefifo_fops;
48052
48053 /*
48054 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48055 index 15af622..0e9f4467 100644
48056 --- a/fs/proc/Kconfig
48057 +++ b/fs/proc/Kconfig
48058 @@ -30,12 +30,12 @@ config PROC_FS
48059
48060 config PROC_KCORE
48061 bool "/proc/kcore support" if !ARM
48062 - depends on PROC_FS && MMU
48063 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48064
48065 config PROC_VMCORE
48066 bool "/proc/vmcore support"
48067 - depends on PROC_FS && CRASH_DUMP
48068 - default y
48069 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48070 + default n
48071 help
48072 Exports the dump image of crashed kernel in ELF format.
48073
48074 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48075 limited in memory.
48076
48077 config PROC_PAGE_MONITOR
48078 - default y
48079 - depends on PROC_FS && MMU
48080 + default n
48081 + depends on PROC_FS && MMU && !GRKERNSEC
48082 bool "Enable /proc page monitoring" if EXPERT
48083 help
48084 Various /proc files exist to monitor process memory utilization:
48085 diff --git a/fs/proc/array.c b/fs/proc/array.c
48086 index c602b8d..a7de642 100644
48087 --- a/fs/proc/array.c
48088 +++ b/fs/proc/array.c
48089 @@ -60,6 +60,7 @@
48090 #include <linux/tty.h>
48091 #include <linux/string.h>
48092 #include <linux/mman.h>
48093 +#include <linux/grsecurity.h>
48094 #include <linux/proc_fs.h>
48095 #include <linux/ioport.h>
48096 #include <linux/uaccess.h>
48097 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48098 seq_putc(m, '\n');
48099 }
48100
48101 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48102 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48103 +{
48104 + if (p->mm)
48105 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48106 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48107 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48108 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48109 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48110 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48111 + else
48112 + seq_printf(m, "PaX:\t-----\n");
48113 +}
48114 +#endif
48115 +
48116 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48117 struct pid *pid, struct task_struct *task)
48118 {
48119 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48120 task_cpus_allowed(m, task);
48121 cpuset_task_status_allowed(m, task);
48122 task_context_switch_counts(m, task);
48123 +
48124 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48125 + task_pax(m, task);
48126 +#endif
48127 +
48128 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48129 + task_grsec_rbac(m, task);
48130 +#endif
48131 +
48132 return 0;
48133 }
48134
48135 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48136 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48137 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48138 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48139 +#endif
48140 +
48141 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48142 struct pid *pid, struct task_struct *task, int whole)
48143 {
48144 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48145 char tcomm[sizeof(task->comm)];
48146 unsigned long flags;
48147
48148 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48149 + if (current->exec_id != m->exec_id) {
48150 + gr_log_badprocpid("stat");
48151 + return 0;
48152 + }
48153 +#endif
48154 +
48155 state = *get_task_state(task);
48156 vsize = eip = esp = 0;
48157 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48158 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48159 gtime = task->gtime;
48160 }
48161
48162 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48163 + if (PAX_RAND_FLAGS(mm)) {
48164 + eip = 0;
48165 + esp = 0;
48166 + wchan = 0;
48167 + }
48168 +#endif
48169 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48170 + wchan = 0;
48171 + eip =0;
48172 + esp =0;
48173 +#endif
48174 +
48175 /* scale priority and nice values from timeslices to -20..20 */
48176 /* to make it look like a "normal" Unix priority/nice value */
48177 priority = task_prio(task);
48178 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48179 vsize,
48180 mm ? get_mm_rss(mm) : 0,
48181 rsslim,
48182 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48183 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
48184 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
48185 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
48186 +#else
48187 mm ? (permitted ? mm->start_code : 1) : 0,
48188 mm ? (permitted ? mm->end_code : 1) : 0,
48189 (permitted && mm) ? mm->start_stack : 0,
48190 +#endif
48191 esp,
48192 eip,
48193 /* The signal information here is obsolete.
48194 @@ -536,8 +593,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48195 struct pid *pid, struct task_struct *task)
48196 {
48197 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48198 - struct mm_struct *mm = get_task_mm(task);
48199 + struct mm_struct *mm;
48200
48201 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48202 + if (current->exec_id != m->exec_id) {
48203 + gr_log_badprocpid("statm");
48204 + return 0;
48205 + }
48206 +#endif
48207 + mm = get_task_mm(task);
48208 if (mm) {
48209 size = task_statm(mm, &shared, &text, &data, &resident);
48210 mmput(mm);
48211 @@ -547,3 +611,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48212
48213 return 0;
48214 }
48215 +
48216 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48217 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48218 +{
48219 + u32 curr_ip = 0;
48220 + unsigned long flags;
48221 +
48222 + if (lock_task_sighand(task, &flags)) {
48223 + curr_ip = task->signal->curr_ip;
48224 + unlock_task_sighand(task, &flags);
48225 + }
48226 +
48227 + return sprintf(buffer, "%pI4\n", &curr_ip);
48228 +}
48229 +#endif
48230 diff --git a/fs/proc/base.c b/fs/proc/base.c
48231 index d4548dd..d101f84 100644
48232 --- a/fs/proc/base.c
48233 +++ b/fs/proc/base.c
48234 @@ -109,6 +109,14 @@ struct pid_entry {
48235 union proc_op op;
48236 };
48237
48238 +struct getdents_callback {
48239 + struct linux_dirent __user * current_dir;
48240 + struct linux_dirent __user * previous;
48241 + struct file * file;
48242 + int count;
48243 + int error;
48244 +};
48245 +
48246 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48247 .name = (NAME), \
48248 .len = sizeof(NAME) - 1, \
48249 @@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48250 if (!mm->arg_end)
48251 goto out_mm; /* Shh! No looking before we're done */
48252
48253 + if (gr_acl_handle_procpidmem(task))
48254 + goto out_mm;
48255 +
48256 len = mm->arg_end - mm->arg_start;
48257
48258 if (len > PAGE_SIZE)
48259 @@ -240,12 +251,28 @@ out:
48260 return res;
48261 }
48262
48263 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48264 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48265 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48266 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48267 +#endif
48268 +
48269 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48270 {
48271 struct mm_struct *mm = mm_for_maps(task);
48272 int res = PTR_ERR(mm);
48273 if (mm && !IS_ERR(mm)) {
48274 unsigned int nwords = 0;
48275 +
48276 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48277 + /* allow if we're currently ptracing this task */
48278 + if (PAX_RAND_FLAGS(mm) &&
48279 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48280 + mmput(mm);
48281 + return 0;
48282 + }
48283 +#endif
48284 +
48285 do {
48286 nwords += 2;
48287 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48288 @@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48289 }
48290
48291
48292 -#ifdef CONFIG_KALLSYMS
48293 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48294 /*
48295 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48296 * Returns the resolved symbol. If that fails, simply return the address.
48297 @@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
48298 mutex_unlock(&task->signal->cred_guard_mutex);
48299 }
48300
48301 -#ifdef CONFIG_STACKTRACE
48302 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48303
48304 #define MAX_STACK_TRACE_DEPTH 64
48305
48306 @@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48307 return count;
48308 }
48309
48310 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48311 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48312 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48313 {
48314 long nr;
48315 @@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48316 /************************************************************************/
48317
48318 /* permission checks */
48319 -static int proc_fd_access_allowed(struct inode *inode)
48320 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48321 {
48322 struct task_struct *task;
48323 int allowed = 0;
48324 @@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48325 */
48326 task = get_proc_task(inode);
48327 if (task) {
48328 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48329 + if (log)
48330 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48331 + else
48332 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48333 put_task_struct(task);
48334 }
48335 return allowed;
48336 @@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48337 struct task_struct *task,
48338 int hide_pid_min)
48339 {
48340 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48341 + return false;
48342 +
48343 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48344 + rcu_read_lock();
48345 + {
48346 + const struct cred *tmpcred = current_cred();
48347 + const struct cred *cred = __task_cred(task);
48348 +
48349 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48350 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48351 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48352 +#endif
48353 + ) {
48354 + rcu_read_unlock();
48355 + return true;
48356 + }
48357 + }
48358 + rcu_read_unlock();
48359 +
48360 + if (!pid->hide_pid)
48361 + return false;
48362 +#endif
48363 +
48364 if (pid->hide_pid < hide_pid_min)
48365 return true;
48366 if (in_group_p(pid->pid_gid))
48367 return true;
48368 +
48369 return ptrace_may_access(task, PTRACE_MODE_READ);
48370 }
48371
48372 @@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48373 put_task_struct(task);
48374
48375 if (!has_perms) {
48376 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48377 + {
48378 +#else
48379 if (pid->hide_pid == 2) {
48380 +#endif
48381 /*
48382 * Let's make getdents(), stat(), and open()
48383 * consistent with each other. If a process
48384 @@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
48385 file->f_mode |= FMODE_UNSIGNED_OFFSET;
48386 file->private_data = mm;
48387
48388 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48389 + file->f_version = current->exec_id;
48390 +#endif
48391 +
48392 return 0;
48393 }
48394
48395 @@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48396 ssize_t copied;
48397 char *page;
48398
48399 +#ifdef CONFIG_GRKERNSEC
48400 + if (write)
48401 + return -EPERM;
48402 +#endif
48403 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48404 + if (file->f_version != current->exec_id) {
48405 + gr_log_badprocpid("mem");
48406 + return 0;
48407 + }
48408 +#endif
48409 +
48410 if (!mm)
48411 return 0;
48412
48413 @@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48414 if (!task)
48415 goto out_no_task;
48416
48417 + if (gr_acl_handle_procpidmem(task))
48418 + goto out;
48419 +
48420 ret = -ENOMEM;
48421 page = (char *)__get_free_page(GFP_TEMPORARY);
48422 if (!page)
48423 @@ -1434,7 +1511,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48424 path_put(&nd->path);
48425
48426 /* Are we allowed to snoop on the tasks file descriptors? */
48427 - if (!proc_fd_access_allowed(inode))
48428 + if (!proc_fd_access_allowed(inode, 0))
48429 goto out;
48430
48431 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48432 @@ -1473,8 +1550,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48433 struct path path;
48434
48435 /* Are we allowed to snoop on the tasks file descriptors? */
48436 - if (!proc_fd_access_allowed(inode))
48437 - goto out;
48438 + /* logging this is needed for learning on chromium to work properly,
48439 + but we don't want to flood the logs from 'ps' which does a readlink
48440 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48441 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48442 + */
48443 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48444 + if (!proc_fd_access_allowed(inode,0))
48445 + goto out;
48446 + } else {
48447 + if (!proc_fd_access_allowed(inode,1))
48448 + goto out;
48449 + }
48450
48451 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48452 if (error)
48453 @@ -1539,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48454 rcu_read_lock();
48455 cred = __task_cred(task);
48456 inode->i_uid = cred->euid;
48457 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48458 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48459 +#else
48460 inode->i_gid = cred->egid;
48461 +#endif
48462 rcu_read_unlock();
48463 }
48464 security_task_to_inode(task, inode);
48465 @@ -1575,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48466 return -ENOENT;
48467 }
48468 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48469 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48470 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48471 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48472 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48473 +#endif
48474 task_dumpable(task)) {
48475 cred = __task_cred(task);
48476 stat->uid = cred->euid;
48477 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48478 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48479 +#else
48480 stat->gid = cred->egid;
48481 +#endif
48482 }
48483 }
48484 rcu_read_unlock();
48485 @@ -1616,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48486
48487 if (task) {
48488 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48489 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48490 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48491 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48492 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48493 +#endif
48494 task_dumpable(task)) {
48495 rcu_read_lock();
48496 cred = __task_cred(task);
48497 inode->i_uid = cred->euid;
48498 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48499 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48500 +#else
48501 inode->i_gid = cred->egid;
48502 +#endif
48503 rcu_read_unlock();
48504 } else {
48505 inode->i_uid = 0;
48506 @@ -1738,7 +1847,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48507 int fd = proc_fd(inode);
48508
48509 if (task) {
48510 - files = get_files_struct(task);
48511 + if (!gr_acl_handle_procpidmem(task))
48512 + files = get_files_struct(task);
48513 put_task_struct(task);
48514 }
48515 if (files) {
48516 @@ -2355,11 +2465,21 @@ static const struct file_operations proc_map_files_operations = {
48517 */
48518 static int proc_fd_permission(struct inode *inode, int mask)
48519 {
48520 + struct task_struct *task;
48521 int rv = generic_permission(inode, mask);
48522 - if (rv == 0)
48523 - return 0;
48524 +
48525 if (task_pid(current) == proc_pid(inode))
48526 rv = 0;
48527 +
48528 + task = get_proc_task(inode);
48529 + if (task == NULL)
48530 + return rv;
48531 +
48532 + if (gr_acl_handle_procpidmem(task))
48533 + rv = -EACCES;
48534 +
48535 + put_task_struct(task);
48536 +
48537 return rv;
48538 }
48539
48540 @@ -2469,6 +2589,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48541 if (!task)
48542 goto out_no_task;
48543
48544 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48545 + goto out;
48546 +
48547 /*
48548 * Yes, it does not scale. And it should not. Don't add
48549 * new entries into /proc/<tgid>/ without very good reasons.
48550 @@ -2513,6 +2636,9 @@ static int proc_pident_readdir(struct file *filp,
48551 if (!task)
48552 goto out_no_task;
48553
48554 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48555 + goto out;
48556 +
48557 ret = 0;
48558 i = filp->f_pos;
48559 switch (i) {
48560 @@ -2783,7 +2909,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48561 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48562 void *cookie)
48563 {
48564 - char *s = nd_get_link(nd);
48565 + const char *s = nd_get_link(nd);
48566 if (!IS_ERR(s))
48567 __putname(s);
48568 }
48569 @@ -2984,7 +3110,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48570 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48571 #endif
48572 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48573 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48574 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48575 INF("syscall", S_IRUGO, proc_pid_syscall),
48576 #endif
48577 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48578 @@ -3009,10 +3135,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48579 #ifdef CONFIG_SECURITY
48580 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48581 #endif
48582 -#ifdef CONFIG_KALLSYMS
48583 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48584 INF("wchan", S_IRUGO, proc_pid_wchan),
48585 #endif
48586 -#ifdef CONFIG_STACKTRACE
48587 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48588 ONE("stack", S_IRUGO, proc_pid_stack),
48589 #endif
48590 #ifdef CONFIG_SCHEDSTATS
48591 @@ -3046,6 +3172,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48592 #ifdef CONFIG_HARDWALL
48593 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48594 #endif
48595 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48596 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48597 +#endif
48598 };
48599
48600 static int proc_tgid_base_readdir(struct file * filp,
48601 @@ -3172,7 +3301,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48602 if (!inode)
48603 goto out;
48604
48605 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48606 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48607 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48608 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48609 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48610 +#else
48611 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48612 +#endif
48613 inode->i_op = &proc_tgid_base_inode_operations;
48614 inode->i_fop = &proc_tgid_base_operations;
48615 inode->i_flags|=S_IMMUTABLE;
48616 @@ -3214,7 +3350,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48617 if (!task)
48618 goto out;
48619
48620 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48621 + goto out_put_task;
48622 +
48623 result = proc_pid_instantiate(dir, dentry, task, NULL);
48624 +out_put_task:
48625 put_task_struct(task);
48626 out:
48627 return result;
48628 @@ -3277,6 +3417,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48629 static int fake_filldir(void *buf, const char *name, int namelen,
48630 loff_t offset, u64 ino, unsigned d_type)
48631 {
48632 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
48633 + __buf->error = -EINVAL;
48634 return 0;
48635 }
48636
48637 @@ -3343,7 +3485,7 @@ static const struct pid_entry tid_base_stuff[] = {
48638 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48639 #endif
48640 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48641 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48642 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48643 INF("syscall", S_IRUGO, proc_pid_syscall),
48644 #endif
48645 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48646 @@ -3367,10 +3509,10 @@ static const struct pid_entry tid_base_stuff[] = {
48647 #ifdef CONFIG_SECURITY
48648 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48649 #endif
48650 -#ifdef CONFIG_KALLSYMS
48651 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48652 INF("wchan", S_IRUGO, proc_pid_wchan),
48653 #endif
48654 -#ifdef CONFIG_STACKTRACE
48655 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48656 ONE("stack", S_IRUGO, proc_pid_stack),
48657 #endif
48658 #ifdef CONFIG_SCHEDSTATS
48659 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48660 index 82676e3..5f8518a 100644
48661 --- a/fs/proc/cmdline.c
48662 +++ b/fs/proc/cmdline.c
48663 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48664
48665 static int __init proc_cmdline_init(void)
48666 {
48667 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48668 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48669 +#else
48670 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48671 +#endif
48672 return 0;
48673 }
48674 module_init(proc_cmdline_init);
48675 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48676 index b143471..bb105e5 100644
48677 --- a/fs/proc/devices.c
48678 +++ b/fs/proc/devices.c
48679 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48680
48681 static int __init proc_devices_init(void)
48682 {
48683 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48684 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48685 +#else
48686 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48687 +#endif
48688 return 0;
48689 }
48690 module_init(proc_devices_init);
48691 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48692 index 84fd323..f698a32 100644
48693 --- a/fs/proc/inode.c
48694 +++ b/fs/proc/inode.c
48695 @@ -21,12 +21,18 @@
48696 #include <linux/seq_file.h>
48697 #include <linux/slab.h>
48698 #include <linux/mount.h>
48699 +#include <linux/grsecurity.h>
48700
48701 #include <asm/system.h>
48702 #include <asm/uaccess.h>
48703
48704 #include "internal.h"
48705
48706 +#ifdef CONFIG_PROC_SYSCTL
48707 +extern const struct inode_operations proc_sys_inode_operations;
48708 +extern const struct inode_operations proc_sys_dir_operations;
48709 +#endif
48710 +
48711 static void proc_evict_inode(struct inode *inode)
48712 {
48713 struct proc_dir_entry *de;
48714 @@ -52,6 +58,13 @@ static void proc_evict_inode(struct inode *inode)
48715 ns_ops = PROC_I(inode)->ns_ops;
48716 if (ns_ops && ns_ops->put)
48717 ns_ops->put(PROC_I(inode)->ns);
48718 +
48719 +#ifdef CONFIG_PROC_SYSCTL
48720 + if (inode->i_op == &proc_sys_inode_operations ||
48721 + inode->i_op == &proc_sys_dir_operations)
48722 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48723 +#endif
48724 +
48725 }
48726
48727 static struct kmem_cache * proc_inode_cachep;
48728 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48729 if (de->mode) {
48730 inode->i_mode = de->mode;
48731 inode->i_uid = de->uid;
48732 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48733 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48734 +#else
48735 inode->i_gid = de->gid;
48736 +#endif
48737 }
48738 if (de->size)
48739 inode->i_size = de->size;
48740 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48741 index 2925775..4f08fae 100644
48742 --- a/fs/proc/internal.h
48743 +++ b/fs/proc/internal.h
48744 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48745 struct pid *pid, struct task_struct *task);
48746 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48747 struct pid *pid, struct task_struct *task);
48748 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48749 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48750 +#endif
48751 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48752
48753 extern const struct file_operations proc_maps_operations;
48754 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48755 index d245cb2..f4e8498 100644
48756 --- a/fs/proc/kcore.c
48757 +++ b/fs/proc/kcore.c
48758 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48759 * the addresses in the elf_phdr on our list.
48760 */
48761 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48762 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48763 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48764 + if (tsz > buflen)
48765 tsz = buflen;
48766 -
48767 +
48768 while (buflen) {
48769 struct kcore_list *m;
48770
48771 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48772 kfree(elf_buf);
48773 } else {
48774 if (kern_addr_valid(start)) {
48775 - unsigned long n;
48776 + char *elf_buf;
48777 + mm_segment_t oldfs;
48778
48779 - n = copy_to_user(buffer, (char *)start, tsz);
48780 - /*
48781 - * We cannot distingush between fault on source
48782 - * and fault on destination. When this happens
48783 - * we clear too and hope it will trigger the
48784 - * EFAULT again.
48785 - */
48786 - if (n) {
48787 - if (clear_user(buffer + tsz - n,
48788 - n))
48789 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48790 + if (!elf_buf)
48791 + return -ENOMEM;
48792 + oldfs = get_fs();
48793 + set_fs(KERNEL_DS);
48794 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48795 + set_fs(oldfs);
48796 + if (copy_to_user(buffer, elf_buf, tsz)) {
48797 + kfree(elf_buf);
48798 return -EFAULT;
48799 + }
48800 }
48801 + set_fs(oldfs);
48802 + kfree(elf_buf);
48803 } else {
48804 if (clear_user(buffer, tsz))
48805 return -EFAULT;
48806 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48807
48808 static int open_kcore(struct inode *inode, struct file *filp)
48809 {
48810 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48811 + return -EPERM;
48812 +#endif
48813 if (!capable(CAP_SYS_RAWIO))
48814 return -EPERM;
48815 if (kcore_need_update)
48816 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48817 index 80e4645..53e5fcf 100644
48818 --- a/fs/proc/meminfo.c
48819 +++ b/fs/proc/meminfo.c
48820 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48821 vmi.used >> 10,
48822 vmi.largest_chunk >> 10
48823 #ifdef CONFIG_MEMORY_FAILURE
48824 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48825 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48826 #endif
48827 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48828 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48829 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48830 index b1822dd..df622cb 100644
48831 --- a/fs/proc/nommu.c
48832 +++ b/fs/proc/nommu.c
48833 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48834 if (len < 1)
48835 len = 1;
48836 seq_printf(m, "%*c", len, ' ');
48837 - seq_path(m, &file->f_path, "");
48838 + seq_path(m, &file->f_path, "\n\\");
48839 }
48840
48841 seq_putc(m, '\n');
48842 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48843 index 06e1cc1..177cd98 100644
48844 --- a/fs/proc/proc_net.c
48845 +++ b/fs/proc/proc_net.c
48846 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48847 struct task_struct *task;
48848 struct nsproxy *ns;
48849 struct net *net = NULL;
48850 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48851 + const struct cred *cred = current_cred();
48852 +#endif
48853 +
48854 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48855 + if (cred->fsuid)
48856 + return net;
48857 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48858 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48859 + return net;
48860 +#endif
48861
48862 rcu_read_lock();
48863 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48864 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48865 index 53c3bce..10ad159 100644
48866 --- a/fs/proc/proc_sysctl.c
48867 +++ b/fs/proc/proc_sysctl.c
48868 @@ -9,11 +9,13 @@
48869 #include <linux/namei.h>
48870 #include "internal.h"
48871
48872 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
48873 +
48874 static const struct dentry_operations proc_sys_dentry_operations;
48875 static const struct file_operations proc_sys_file_operations;
48876 -static const struct inode_operations proc_sys_inode_operations;
48877 +const struct inode_operations proc_sys_inode_operations;
48878 static const struct file_operations proc_sys_dir_file_operations;
48879 -static const struct inode_operations proc_sys_dir_operations;
48880 +const struct inode_operations proc_sys_dir_operations;
48881
48882 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48883 {
48884 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48885
48886 err = NULL;
48887 d_set_d_op(dentry, &proc_sys_dentry_operations);
48888 +
48889 + gr_handle_proc_create(dentry, inode);
48890 +
48891 d_add(dentry, inode);
48892
48893 + if (gr_handle_sysctl(p, MAY_EXEC))
48894 + err = ERR_PTR(-ENOENT);
48895 +
48896 out:
48897 sysctl_head_finish(head);
48898 return err;
48899 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48900 if (!table->proc_handler)
48901 goto out;
48902
48903 +#ifdef CONFIG_GRKERNSEC
48904 + error = -EPERM;
48905 + if (write && !capable(CAP_SYS_ADMIN))
48906 + goto out;
48907 +#endif
48908 +
48909 /* careful: calling conventions are nasty here */
48910 res = count;
48911 error = table->proc_handler(table, write, buf, &res, ppos);
48912 @@ -260,6 +274,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48913 return -ENOMEM;
48914 } else {
48915 d_set_d_op(child, &proc_sys_dentry_operations);
48916 +
48917 + gr_handle_proc_create(child, inode);
48918 +
48919 d_add(child, inode);
48920 }
48921 } else {
48922 @@ -288,6 +305,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48923 if (*pos < file->f_pos)
48924 continue;
48925
48926 + if (gr_handle_sysctl(table, 0))
48927 + continue;
48928 +
48929 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
48930 if (res)
48931 return res;
48932 @@ -413,6 +433,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48933 if (IS_ERR(head))
48934 return PTR_ERR(head);
48935
48936 + if (table && gr_handle_sysctl(table, MAY_EXEC))
48937 + return -ENOENT;
48938 +
48939 generic_fillattr(inode, stat);
48940 if (table)
48941 stat->mode = (stat->mode & S_IFMT) | table->mode;
48942 @@ -435,13 +458,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48943 .llseek = generic_file_llseek,
48944 };
48945
48946 -static const struct inode_operations proc_sys_inode_operations = {
48947 +const struct inode_operations proc_sys_inode_operations = {
48948 .permission = proc_sys_permission,
48949 .setattr = proc_sys_setattr,
48950 .getattr = proc_sys_getattr,
48951 };
48952
48953 -static const struct inode_operations proc_sys_dir_operations = {
48954 +const struct inode_operations proc_sys_dir_operations = {
48955 .lookup = proc_sys_lookup,
48956 .permission = proc_sys_permission,
48957 .setattr = proc_sys_setattr,
48958 diff --git a/fs/proc/root.c b/fs/proc/root.c
48959 index 46a15d8..335631a 100644
48960 --- a/fs/proc/root.c
48961 +++ b/fs/proc/root.c
48962 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
48963 #ifdef CONFIG_PROC_DEVICETREE
48964 proc_device_tree_init();
48965 #endif
48966 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48967 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48968 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48969 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48970 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48971 +#endif
48972 +#else
48973 proc_mkdir("bus", NULL);
48974 +#endif
48975 proc_sys_init();
48976 }
48977
48978 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48979 index 3efa725..23c925b 100644
48980 --- a/fs/proc/task_mmu.c
48981 +++ b/fs/proc/task_mmu.c
48982 @@ -11,6 +11,7 @@
48983 #include <linux/rmap.h>
48984 #include <linux/swap.h>
48985 #include <linux/swapops.h>
48986 +#include <linux/grsecurity.h>
48987
48988 #include <asm/elf.h>
48989 #include <asm/uaccess.h>
48990 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48991 "VmExe:\t%8lu kB\n"
48992 "VmLib:\t%8lu kB\n"
48993 "VmPTE:\t%8lu kB\n"
48994 - "VmSwap:\t%8lu kB\n",
48995 - hiwater_vm << (PAGE_SHIFT-10),
48996 + "VmSwap:\t%8lu kB\n"
48997 +
48998 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48999 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49000 +#endif
49001 +
49002 + ,hiwater_vm << (PAGE_SHIFT-10),
49003 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49004 mm->locked_vm << (PAGE_SHIFT-10),
49005 mm->pinned_vm << (PAGE_SHIFT-10),
49006 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49007 data << (PAGE_SHIFT-10),
49008 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49009 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49010 - swap << (PAGE_SHIFT-10));
49011 + swap << (PAGE_SHIFT-10)
49012 +
49013 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49014 + , mm->context.user_cs_base, mm->context.user_cs_limit
49015 +#endif
49016 +
49017 + );
49018 }
49019
49020 unsigned long task_vsize(struct mm_struct *mm)
49021 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
49022 return ret;
49023 }
49024
49025 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49026 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49027 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49028 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49029 +#endif
49030 +
49031 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49032 {
49033 struct mm_struct *mm = vma->vm_mm;
49034 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49035 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49036 }
49037
49038 - /* We don't show the stack guard page in /proc/maps */
49039 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49040 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49041 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49042 +#else
49043 start = vma->vm_start;
49044 - if (stack_guard_page_start(vma, start))
49045 - start += PAGE_SIZE;
49046 end = vma->vm_end;
49047 - if (stack_guard_page_end(vma, end))
49048 - end -= PAGE_SIZE;
49049 +#endif
49050
49051 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49052 start,
49053 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49054 flags & VM_WRITE ? 'w' : '-',
49055 flags & VM_EXEC ? 'x' : '-',
49056 flags & VM_MAYSHARE ? 's' : 'p',
49057 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49058 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49059 +#else
49060 pgoff,
49061 +#endif
49062 MAJOR(dev), MINOR(dev), ino, &len);
49063
49064 /*
49065 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49066 */
49067 if (file) {
49068 pad_len_spaces(m, len);
49069 - seq_path(m, &file->f_path, "\n");
49070 + seq_path(m, &file->f_path, "\n\\");
49071 } else {
49072 const char *name = arch_vma_name(vma);
49073 if (!name) {
49074 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49075 if (vma->vm_start <= mm->brk &&
49076 vma->vm_end >= mm->start_brk) {
49077 name = "[heap]";
49078 - } else if (vma->vm_start <= mm->start_stack &&
49079 - vma->vm_end >= mm->start_stack) {
49080 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49081 + (vma->vm_start <= mm->start_stack &&
49082 + vma->vm_end >= mm->start_stack)) {
49083 name = "[stack]";
49084 }
49085 } else {
49086 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
49087 struct proc_maps_private *priv = m->private;
49088 struct task_struct *task = priv->task;
49089
49090 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49091 + if (current->exec_id != m->exec_id) {
49092 + gr_log_badprocpid("maps");
49093 + return 0;
49094 + }
49095 +#endif
49096 +
49097 show_map_vma(m, vma);
49098
49099 if (m->count < m->size) /* vma is copied successfully */
49100 @@ -437,12 +467,23 @@ static int show_smap(struct seq_file *m, void *v)
49101 .private = &mss,
49102 };
49103
49104 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49105 + if (current->exec_id != m->exec_id) {
49106 + gr_log_badprocpid("smaps");
49107 + return 0;
49108 + }
49109 +#endif
49110 memset(&mss, 0, sizeof mss);
49111 - mss.vma = vma;
49112 - /* mmap_sem is held in m_start */
49113 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49114 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49115 -
49116 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49117 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49118 +#endif
49119 + mss.vma = vma;
49120 + /* mmap_sem is held in m_start */
49121 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49122 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49123 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49124 + }
49125 +#endif
49126 show_map_vma(m, vma);
49127
49128 seq_printf(m,
49129 @@ -460,7 +501,11 @@ static int show_smap(struct seq_file *m, void *v)
49130 "KernelPageSize: %8lu kB\n"
49131 "MMUPageSize: %8lu kB\n"
49132 "Locked: %8lu kB\n",
49133 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49134 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49135 +#else
49136 (vma->vm_end - vma->vm_start) >> 10,
49137 +#endif
49138 mss.resident >> 10,
49139 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49140 mss.shared_clean >> 10,
49141 @@ -1024,6 +1069,13 @@ static int show_numa_map(struct seq_file *m, void *v)
49142 int n;
49143 char buffer[50];
49144
49145 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49146 + if (current->exec_id != m->exec_id) {
49147 + gr_log_badprocpid("numa_maps");
49148 + return 0;
49149 + }
49150 +#endif
49151 +
49152 if (!mm)
49153 return 0;
49154
49155 @@ -1041,11 +1093,15 @@ static int show_numa_map(struct seq_file *m, void *v)
49156 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49157 mpol_cond_put(pol);
49158
49159 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49160 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49161 +#else
49162 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49163 +#endif
49164
49165 if (file) {
49166 seq_printf(m, " file=");
49167 - seq_path(m, &file->f_path, "\n\t= ");
49168 + seq_path(m, &file->f_path, "\n\t\\= ");
49169 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49170 seq_printf(m, " heap");
49171 } else if (vma->vm_start <= mm->start_stack &&
49172 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49173 index 980de54..2a4db5f 100644
49174 --- a/fs/proc/task_nommu.c
49175 +++ b/fs/proc/task_nommu.c
49176 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49177 else
49178 bytes += kobjsize(mm);
49179
49180 - if (current->fs && current->fs->users > 1)
49181 + if (current->fs && atomic_read(&current->fs->users) > 1)
49182 sbytes += kobjsize(current->fs);
49183 else
49184 bytes += kobjsize(current->fs);
49185 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
49186
49187 if (file) {
49188 pad_len_spaces(m, len);
49189 - seq_path(m, &file->f_path, "");
49190 + seq_path(m, &file->f_path, "\n\\");
49191 } else if (mm) {
49192 if (vma->vm_start <= mm->start_stack &&
49193 vma->vm_end >= mm->start_stack) {
49194 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49195 index d67908b..d13f6a6 100644
49196 --- a/fs/quota/netlink.c
49197 +++ b/fs/quota/netlink.c
49198 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49199 void quota_send_warning(short type, unsigned int id, dev_t dev,
49200 const char warntype)
49201 {
49202 - static atomic_t seq;
49203 + static atomic_unchecked_t seq;
49204 struct sk_buff *skb;
49205 void *msg_head;
49206 int ret;
49207 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49208 "VFS: Not enough memory to send quota warning.\n");
49209 return;
49210 }
49211 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49212 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49213 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49214 if (!msg_head) {
49215 printk(KERN_ERR
49216 diff --git a/fs/readdir.c b/fs/readdir.c
49217 index 356f715..c918d38 100644
49218 --- a/fs/readdir.c
49219 +++ b/fs/readdir.c
49220 @@ -17,6 +17,7 @@
49221 #include <linux/security.h>
49222 #include <linux/syscalls.h>
49223 #include <linux/unistd.h>
49224 +#include <linux/namei.h>
49225
49226 #include <asm/uaccess.h>
49227
49228 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49229
49230 struct readdir_callback {
49231 struct old_linux_dirent __user * dirent;
49232 + struct file * file;
49233 int result;
49234 };
49235
49236 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49237 buf->result = -EOVERFLOW;
49238 return -EOVERFLOW;
49239 }
49240 +
49241 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49242 + return 0;
49243 +
49244 buf->result++;
49245 dirent = buf->dirent;
49246 if (!access_ok(VERIFY_WRITE, dirent,
49247 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49248
49249 buf.result = 0;
49250 buf.dirent = dirent;
49251 + buf.file = file;
49252
49253 error = vfs_readdir(file, fillonedir, &buf);
49254 if (buf.result)
49255 @@ -142,6 +149,7 @@ struct linux_dirent {
49256 struct getdents_callback {
49257 struct linux_dirent __user * current_dir;
49258 struct linux_dirent __user * previous;
49259 + struct file * file;
49260 int count;
49261 int error;
49262 };
49263 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49264 buf->error = -EOVERFLOW;
49265 return -EOVERFLOW;
49266 }
49267 +
49268 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49269 + return 0;
49270 +
49271 dirent = buf->previous;
49272 if (dirent) {
49273 if (__put_user(offset, &dirent->d_off))
49274 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49275 buf.previous = NULL;
49276 buf.count = count;
49277 buf.error = 0;
49278 + buf.file = file;
49279
49280 error = vfs_readdir(file, filldir, &buf);
49281 if (error >= 0)
49282 @@ -229,6 +242,7 @@ out:
49283 struct getdents_callback64 {
49284 struct linux_dirent64 __user * current_dir;
49285 struct linux_dirent64 __user * previous;
49286 + struct file *file;
49287 int count;
49288 int error;
49289 };
49290 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49291 buf->error = -EINVAL; /* only used if we fail.. */
49292 if (reclen > buf->count)
49293 return -EINVAL;
49294 +
49295 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49296 + return 0;
49297 +
49298 dirent = buf->previous;
49299 if (dirent) {
49300 if (__put_user(offset, &dirent->d_off))
49301 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49302
49303 buf.current_dir = dirent;
49304 buf.previous = NULL;
49305 + buf.file = file;
49306 buf.count = count;
49307 buf.error = 0;
49308
49309 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49310 error = buf.error;
49311 lastdirent = buf.previous;
49312 if (lastdirent) {
49313 - typeof(lastdirent->d_off) d_off = file->f_pos;
49314 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49315 if (__put_user(d_off, &lastdirent->d_off))
49316 error = -EFAULT;
49317 else
49318 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49319 index 60c0804..d814f98 100644
49320 --- a/fs/reiserfs/do_balan.c
49321 +++ b/fs/reiserfs/do_balan.c
49322 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49323 return;
49324 }
49325
49326 - atomic_inc(&(fs_generation(tb->tb_sb)));
49327 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49328 do_balance_starts(tb);
49329
49330 /* balance leaf returns 0 except if combining L R and S into
49331 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49332 index 7a99811..a7c96c4 100644
49333 --- a/fs/reiserfs/procfs.c
49334 +++ b/fs/reiserfs/procfs.c
49335 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49336 "SMALL_TAILS " : "NO_TAILS ",
49337 replay_only(sb) ? "REPLAY_ONLY " : "",
49338 convert_reiserfs(sb) ? "CONV " : "",
49339 - atomic_read(&r->s_generation_counter),
49340 + atomic_read_unchecked(&r->s_generation_counter),
49341 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49342 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49343 SF(s_good_search_by_key_reada), SF(s_bmaps),
49344 diff --git a/fs/select.c b/fs/select.c
49345 index e782258..3b4b44c 100644
49346 --- a/fs/select.c
49347 +++ b/fs/select.c
49348 @@ -20,6 +20,7 @@
49349 #include <linux/module.h>
49350 #include <linux/slab.h>
49351 #include <linux/poll.h>
49352 +#include <linux/security.h>
49353 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49354 #include <linux/file.h>
49355 #include <linux/fdtable.h>
49356 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49357 struct poll_list *walk = head;
49358 unsigned long todo = nfds;
49359
49360 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49361 if (nfds > rlimit(RLIMIT_NOFILE))
49362 return -EINVAL;
49363
49364 diff --git a/fs/seq_file.c b/fs/seq_file.c
49365 index 4023d6b..ab46c6a 100644
49366 --- a/fs/seq_file.c
49367 +++ b/fs/seq_file.c
49368 @@ -9,6 +9,7 @@
49369 #include <linux/module.h>
49370 #include <linux/seq_file.h>
49371 #include <linux/slab.h>
49372 +#include <linux/sched.h>
49373
49374 #include <asm/uaccess.h>
49375 #include <asm/page.h>
49376 @@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49377 memset(p, 0, sizeof(*p));
49378 mutex_init(&p->lock);
49379 p->op = op;
49380 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49381 + p->exec_id = current->exec_id;
49382 +#endif
49383
49384 /*
49385 * Wrappers around seq_open(e.g. swaps_open) need to be
49386 @@ -549,7 +553,7 @@ static void single_stop(struct seq_file *p, void *v)
49387 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49388 void *data)
49389 {
49390 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49391 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49392 int res = -ENOMEM;
49393
49394 if (op) {
49395 diff --git a/fs/splice.c b/fs/splice.c
49396 index 96d7b28..fd465ac 100644
49397 --- a/fs/splice.c
49398 +++ b/fs/splice.c
49399 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49400 pipe_lock(pipe);
49401
49402 for (;;) {
49403 - if (!pipe->readers) {
49404 + if (!atomic_read(&pipe->readers)) {
49405 send_sig(SIGPIPE, current, 0);
49406 if (!ret)
49407 ret = -EPIPE;
49408 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49409 do_wakeup = 0;
49410 }
49411
49412 - pipe->waiting_writers++;
49413 + atomic_inc(&pipe->waiting_writers);
49414 pipe_wait(pipe);
49415 - pipe->waiting_writers--;
49416 + atomic_dec(&pipe->waiting_writers);
49417 }
49418
49419 pipe_unlock(pipe);
49420 @@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49421 old_fs = get_fs();
49422 set_fs(get_ds());
49423 /* The cast to a user pointer is valid due to the set_fs() */
49424 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49425 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49426 set_fs(old_fs);
49427
49428 return res;
49429 @@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49430 old_fs = get_fs();
49431 set_fs(get_ds());
49432 /* The cast to a user pointer is valid due to the set_fs() */
49433 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49434 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49435 set_fs(old_fs);
49436
49437 return res;
49438 @@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49439 goto err;
49440
49441 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49442 - vec[i].iov_base = (void __user *) page_address(page);
49443 + vec[i].iov_base = (void __force_user *) page_address(page);
49444 vec[i].iov_len = this_len;
49445 spd.pages[i] = page;
49446 spd.nr_pages++;
49447 @@ -848,10 +848,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49448 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49449 {
49450 while (!pipe->nrbufs) {
49451 - if (!pipe->writers)
49452 + if (!atomic_read(&pipe->writers))
49453 return 0;
49454
49455 - if (!pipe->waiting_writers && sd->num_spliced)
49456 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49457 return 0;
49458
49459 if (sd->flags & SPLICE_F_NONBLOCK)
49460 @@ -1184,7 +1184,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49461 * out of the pipe right after the splice_to_pipe(). So set
49462 * PIPE_READERS appropriately.
49463 */
49464 - pipe->readers = 1;
49465 + atomic_set(&pipe->readers, 1);
49466
49467 current->splice_pipe = pipe;
49468 }
49469 @@ -1736,9 +1736,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49470 ret = -ERESTARTSYS;
49471 break;
49472 }
49473 - if (!pipe->writers)
49474 + if (!atomic_read(&pipe->writers))
49475 break;
49476 - if (!pipe->waiting_writers) {
49477 + if (!atomic_read(&pipe->waiting_writers)) {
49478 if (flags & SPLICE_F_NONBLOCK) {
49479 ret = -EAGAIN;
49480 break;
49481 @@ -1770,7 +1770,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49482 pipe_lock(pipe);
49483
49484 while (pipe->nrbufs >= pipe->buffers) {
49485 - if (!pipe->readers) {
49486 + if (!atomic_read(&pipe->readers)) {
49487 send_sig(SIGPIPE, current, 0);
49488 ret = -EPIPE;
49489 break;
49490 @@ -1783,9 +1783,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49491 ret = -ERESTARTSYS;
49492 break;
49493 }
49494 - pipe->waiting_writers++;
49495 + atomic_inc(&pipe->waiting_writers);
49496 pipe_wait(pipe);
49497 - pipe->waiting_writers--;
49498 + atomic_dec(&pipe->waiting_writers);
49499 }
49500
49501 pipe_unlock(pipe);
49502 @@ -1821,14 +1821,14 @@ retry:
49503 pipe_double_lock(ipipe, opipe);
49504
49505 do {
49506 - if (!opipe->readers) {
49507 + if (!atomic_read(&opipe->readers)) {
49508 send_sig(SIGPIPE, current, 0);
49509 if (!ret)
49510 ret = -EPIPE;
49511 break;
49512 }
49513
49514 - if (!ipipe->nrbufs && !ipipe->writers)
49515 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49516 break;
49517
49518 /*
49519 @@ -1925,7 +1925,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49520 pipe_double_lock(ipipe, opipe);
49521
49522 do {
49523 - if (!opipe->readers) {
49524 + if (!atomic_read(&opipe->readers)) {
49525 send_sig(SIGPIPE, current, 0);
49526 if (!ret)
49527 ret = -EPIPE;
49528 @@ -1970,7 +1970,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49529 * return EAGAIN if we have the potential of some data in the
49530 * future, otherwise just return 0
49531 */
49532 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49533 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49534 ret = -EAGAIN;
49535
49536 pipe_unlock(ipipe);
49537 diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
49538 index a475983..9c6a1f0 100644
49539 --- a/fs/sysfs/bin.c
49540 +++ b/fs/sysfs/bin.c
49541 @@ -67,6 +67,8 @@ fill_read(struct file *file, char *buffer, loff_t off, size_t count)
49542 }
49543
49544 static ssize_t
49545 +read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off) __size_overflow(3);
49546 +static ssize_t
49547 read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
49548 {
49549 struct bin_buffer *bb = file->private_data;
49550 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49551 index 7fdf6a7..e6cd8ad 100644
49552 --- a/fs/sysfs/dir.c
49553 +++ b/fs/sysfs/dir.c
49554 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49555 struct sysfs_dirent *sd;
49556 int rc;
49557
49558 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49559 + const char *parent_name = parent_sd->s_name;
49560 +
49561 + mode = S_IFDIR | S_IRWXU;
49562 +
49563 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49564 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49565 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49566 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49567 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49568 +#endif
49569 +
49570 /* allocate */
49571 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49572 if (!sd)
49573 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49574 index 00012e3..8392349 100644
49575 --- a/fs/sysfs/file.c
49576 +++ b/fs/sysfs/file.c
49577 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49578
49579 struct sysfs_open_dirent {
49580 atomic_t refcnt;
49581 - atomic_t event;
49582 + atomic_unchecked_t event;
49583 wait_queue_head_t poll;
49584 struct list_head buffers; /* goes through sysfs_buffer.list */
49585 };
49586 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49587 if (!sysfs_get_active(attr_sd))
49588 return -ENODEV;
49589
49590 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49591 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49592 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49593
49594 sysfs_put_active(attr_sd);
49595 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49596 return -ENOMEM;
49597
49598 atomic_set(&new_od->refcnt, 0);
49599 - atomic_set(&new_od->event, 1);
49600 + atomic_set_unchecked(&new_od->event, 1);
49601 init_waitqueue_head(&new_od->poll);
49602 INIT_LIST_HEAD(&new_od->buffers);
49603 goto retry;
49604 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49605
49606 sysfs_put_active(attr_sd);
49607
49608 - if (buffer->event != atomic_read(&od->event))
49609 + if (buffer->event != atomic_read_unchecked(&od->event))
49610 goto trigger;
49611
49612 return DEFAULT_POLLMASK;
49613 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49614
49615 od = sd->s_attr.open;
49616 if (od) {
49617 - atomic_inc(&od->event);
49618 + atomic_inc_unchecked(&od->event);
49619 wake_up_interruptible(&od->poll);
49620 }
49621
49622 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49623 index a7ac78f..02158e1 100644
49624 --- a/fs/sysfs/symlink.c
49625 +++ b/fs/sysfs/symlink.c
49626 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49627
49628 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49629 {
49630 - char *page = nd_get_link(nd);
49631 + const char *page = nd_get_link(nd);
49632 if (!IS_ERR(page))
49633 free_page((unsigned long)page);
49634 }
49635 diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
49636 index f922cba..062fb02 100644
49637 --- a/fs/ubifs/debug.c
49638 +++ b/fs/ubifs/debug.c
49639 @@ -2819,6 +2819,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count,
49640 * debugfs file. Returns %0 or %1 in case of success and a negative error code
49641 * in case of failure.
49642 */
49643 +static int interpret_user_input(const char __user *u, size_t count) __size_overflow(2);
49644 static int interpret_user_input(const char __user *u, size_t count)
49645 {
49646 size_t buf_size;
49647 @@ -2837,6 +2838,8 @@ static int interpret_user_input(const char __user *u, size_t count)
49648 }
49649
49650 static ssize_t dfs_file_write(struct file *file, const char __user *u,
49651 + size_t count, loff_t *ppos) __size_overflow(3);
49652 +static ssize_t dfs_file_write(struct file *file, const char __user *u,
49653 size_t count, loff_t *ppos)
49654 {
49655 struct ubifs_info *c = file->private_data;
49656 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49657 index c175b4d..8f36a16 100644
49658 --- a/fs/udf/misc.c
49659 +++ b/fs/udf/misc.c
49660 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49661
49662 u8 udf_tag_checksum(const struct tag *t)
49663 {
49664 - u8 *data = (u8 *)t;
49665 + const u8 *data = (const u8 *)t;
49666 u8 checksum = 0;
49667 int i;
49668 for (i = 0; i < sizeof(struct tag); ++i)
49669 diff --git a/fs/utimes.c b/fs/utimes.c
49670 index ba653f3..06ea4b1 100644
49671 --- a/fs/utimes.c
49672 +++ b/fs/utimes.c
49673 @@ -1,6 +1,7 @@
49674 #include <linux/compiler.h>
49675 #include <linux/file.h>
49676 #include <linux/fs.h>
49677 +#include <linux/security.h>
49678 #include <linux/linkage.h>
49679 #include <linux/mount.h>
49680 #include <linux/namei.h>
49681 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49682 goto mnt_drop_write_and_out;
49683 }
49684 }
49685 +
49686 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49687 + error = -EACCES;
49688 + goto mnt_drop_write_and_out;
49689 + }
49690 +
49691 mutex_lock(&inode->i_mutex);
49692 error = notify_change(path->dentry, &newattrs);
49693 mutex_unlock(&inode->i_mutex);
49694 diff --git a/fs/xattr.c b/fs/xattr.c
49695 index 82f4337..236473c 100644
49696 --- a/fs/xattr.c
49697 +++ b/fs/xattr.c
49698 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49699 * Extended attribute SET operations
49700 */
49701 static long
49702 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49703 +setxattr(struct path *path, const char __user *name, const void __user *value,
49704 size_t size, int flags)
49705 {
49706 int error;
49707 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49708 return PTR_ERR(kvalue);
49709 }
49710
49711 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49712 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49713 + error = -EACCES;
49714 + goto out;
49715 + }
49716 +
49717 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49718 +out:
49719 kfree(kvalue);
49720 return error;
49721 }
49722 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49723 return error;
49724 error = mnt_want_write(path.mnt);
49725 if (!error) {
49726 - error = setxattr(path.dentry, name, value, size, flags);
49727 + error = setxattr(&path, name, value, size, flags);
49728 mnt_drop_write(path.mnt);
49729 }
49730 path_put(&path);
49731 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49732 return error;
49733 error = mnt_want_write(path.mnt);
49734 if (!error) {
49735 - error = setxattr(path.dentry, name, value, size, flags);
49736 + error = setxattr(&path, name, value, size, flags);
49737 mnt_drop_write(path.mnt);
49738 }
49739 path_put(&path);
49740 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49741 const void __user *,value, size_t, size, int, flags)
49742 {
49743 struct file *f;
49744 - struct dentry *dentry;
49745 int error = -EBADF;
49746
49747 f = fget(fd);
49748 if (!f)
49749 return error;
49750 - dentry = f->f_path.dentry;
49751 - audit_inode(NULL, dentry);
49752 + audit_inode(NULL, f->f_path.dentry);
49753 error = mnt_want_write_file(f);
49754 if (!error) {
49755 - error = setxattr(dentry, name, value, size, flags);
49756 + error = setxattr(&f->f_path, name, value, size, flags);
49757 mnt_drop_write_file(f);
49758 }
49759 fput(f);
49760 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49761 index 8d5a506..7f62712 100644
49762 --- a/fs/xattr_acl.c
49763 +++ b/fs/xattr_acl.c
49764 @@ -17,8 +17,8 @@
49765 struct posix_acl *
49766 posix_acl_from_xattr(const void *value, size_t size)
49767 {
49768 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49769 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49770 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49771 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49772 int count;
49773 struct posix_acl *acl;
49774 struct posix_acl_entry *acl_e;
49775 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49776 index 188ef2f..adcf864 100644
49777 --- a/fs/xfs/xfs_bmap.c
49778 +++ b/fs/xfs/xfs_bmap.c
49779 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49780 int nmap,
49781 int ret_nmap);
49782 #else
49783 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49784 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49785 #endif /* DEBUG */
49786
49787 STATIC int
49788 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49789 index 79d05e8..e3e5861 100644
49790 --- a/fs/xfs/xfs_dir2_sf.c
49791 +++ b/fs/xfs/xfs_dir2_sf.c
49792 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49793 }
49794
49795 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49796 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49797 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49798 + char name[sfep->namelen];
49799 + memcpy(name, sfep->name, sfep->namelen);
49800 + if (filldir(dirent, name, sfep->namelen,
49801 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49802 + *offset = off & 0x7fffffff;
49803 + return 0;
49804 + }
49805 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49806 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49807 *offset = off & 0x7fffffff;
49808 return 0;
49809 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49810 index 76f3ca5..f57f712 100644
49811 --- a/fs/xfs/xfs_ioctl.c
49812 +++ b/fs/xfs/xfs_ioctl.c
49813 @@ -128,7 +128,7 @@ xfs_find_handle(
49814 }
49815
49816 error = -EFAULT;
49817 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49818 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49819 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49820 goto out_put;
49821
49822 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49823 index ab30253..4d86958 100644
49824 --- a/fs/xfs/xfs_iops.c
49825 +++ b/fs/xfs/xfs_iops.c
49826 @@ -447,7 +447,7 @@ xfs_vn_put_link(
49827 struct nameidata *nd,
49828 void *p)
49829 {
49830 - char *s = nd_get_link(nd);
49831 + const char *s = nd_get_link(nd);
49832
49833 if (!IS_ERR(s))
49834 kfree(s);
49835 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49836 new file mode 100644
49837 index 0000000..4089e05
49838 --- /dev/null
49839 +++ b/grsecurity/Kconfig
49840 @@ -0,0 +1,1078 @@
49841 +#
49842 +# grecurity configuration
49843 +#
49844 +
49845 +menu "Grsecurity"
49846 +
49847 +config GRKERNSEC
49848 + bool "Grsecurity"
49849 + select CRYPTO
49850 + select CRYPTO_SHA256
49851 + help
49852 + If you say Y here, you will be able to configure many features
49853 + that will enhance the security of your system. It is highly
49854 + recommended that you say Y here and read through the help
49855 + for each option so that you fully understand the features and
49856 + can evaluate their usefulness for your machine.
49857 +
49858 +choice
49859 + prompt "Security Level"
49860 + depends on GRKERNSEC
49861 + default GRKERNSEC_CUSTOM
49862 +
49863 +config GRKERNSEC_LOW
49864 + bool "Low"
49865 + select GRKERNSEC_LINK
49866 + select GRKERNSEC_FIFO
49867 + select GRKERNSEC_RANDNET
49868 + select GRKERNSEC_DMESG
49869 + select GRKERNSEC_CHROOT
49870 + select GRKERNSEC_CHROOT_CHDIR
49871 +
49872 + help
49873 + If you choose this option, several of the grsecurity options will
49874 + be enabled that will give you greater protection against a number
49875 + of attacks, while assuring that none of your software will have any
49876 + conflicts with the additional security measures. If you run a lot
49877 + of unusual software, or you are having problems with the higher
49878 + security levels, you should say Y here. With this option, the
49879 + following features are enabled:
49880 +
49881 + - Linking restrictions
49882 + - FIFO restrictions
49883 + - Restricted dmesg
49884 + - Enforced chdir("/") on chroot
49885 + - Runtime module disabling
49886 +
49887 +config GRKERNSEC_MEDIUM
49888 + bool "Medium"
49889 + select PAX
49890 + select PAX_EI_PAX
49891 + select PAX_PT_PAX_FLAGS
49892 + select PAX_HAVE_ACL_FLAGS
49893 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49894 + select GRKERNSEC_CHROOT
49895 + select GRKERNSEC_CHROOT_SYSCTL
49896 + select GRKERNSEC_LINK
49897 + select GRKERNSEC_FIFO
49898 + select GRKERNSEC_DMESG
49899 + select GRKERNSEC_RANDNET
49900 + select GRKERNSEC_FORKFAIL
49901 + select GRKERNSEC_TIME
49902 + select GRKERNSEC_SIGNAL
49903 + select GRKERNSEC_CHROOT
49904 + select GRKERNSEC_CHROOT_UNIX
49905 + select GRKERNSEC_CHROOT_MOUNT
49906 + select GRKERNSEC_CHROOT_PIVOT
49907 + select GRKERNSEC_CHROOT_DOUBLE
49908 + select GRKERNSEC_CHROOT_CHDIR
49909 + select GRKERNSEC_CHROOT_MKNOD
49910 + select GRKERNSEC_PROC
49911 + select GRKERNSEC_PROC_USERGROUP
49912 + select PAX_RANDUSTACK
49913 + select PAX_ASLR
49914 + select PAX_RANDMMAP
49915 + select PAX_REFCOUNT if (X86 || SPARC64)
49916 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
49917 +
49918 + help
49919 + If you say Y here, several features in addition to those included
49920 + in the low additional security level will be enabled. These
49921 + features provide even more security to your system, though in rare
49922 + cases they may be incompatible with very old or poorly written
49923 + software. If you enable this option, make sure that your auth
49924 + service (identd) is running as gid 1001. With this option,
49925 + the following features (in addition to those provided in the
49926 + low additional security level) will be enabled:
49927 +
49928 + - Failed fork logging
49929 + - Time change logging
49930 + - Signal logging
49931 + - Deny mounts in chroot
49932 + - Deny double chrooting
49933 + - Deny sysctl writes in chroot
49934 + - Deny mknod in chroot
49935 + - Deny access to abstract AF_UNIX sockets out of chroot
49936 + - Deny pivot_root in chroot
49937 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
49938 + - /proc restrictions with special GID set to 10 (usually wheel)
49939 + - Address Space Layout Randomization (ASLR)
49940 + - Prevent exploitation of most refcount overflows
49941 + - Bounds checking of copying between the kernel and userland
49942 +
49943 +config GRKERNSEC_HIGH
49944 + bool "High"
49945 + select GRKERNSEC_LINK
49946 + select GRKERNSEC_FIFO
49947 + select GRKERNSEC_DMESG
49948 + select GRKERNSEC_FORKFAIL
49949 + select GRKERNSEC_TIME
49950 + select GRKERNSEC_SIGNAL
49951 + select GRKERNSEC_CHROOT
49952 + select GRKERNSEC_CHROOT_SHMAT
49953 + select GRKERNSEC_CHROOT_UNIX
49954 + select GRKERNSEC_CHROOT_MOUNT
49955 + select GRKERNSEC_CHROOT_FCHDIR
49956 + select GRKERNSEC_CHROOT_PIVOT
49957 + select GRKERNSEC_CHROOT_DOUBLE
49958 + select GRKERNSEC_CHROOT_CHDIR
49959 + select GRKERNSEC_CHROOT_MKNOD
49960 + select GRKERNSEC_CHROOT_CAPS
49961 + select GRKERNSEC_CHROOT_SYSCTL
49962 + select GRKERNSEC_CHROOT_FINDTASK
49963 + select GRKERNSEC_SYSFS_RESTRICT
49964 + select GRKERNSEC_PROC
49965 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49966 + select GRKERNSEC_HIDESYM
49967 + select GRKERNSEC_BRUTE
49968 + select GRKERNSEC_PROC_USERGROUP
49969 + select GRKERNSEC_KMEM
49970 + select GRKERNSEC_RESLOG
49971 + select GRKERNSEC_RANDNET
49972 + select GRKERNSEC_PROC_ADD
49973 + select GRKERNSEC_CHROOT_CHMOD
49974 + select GRKERNSEC_CHROOT_NICE
49975 + select GRKERNSEC_SETXID
49976 + select GRKERNSEC_AUDIT_MOUNT
49977 + select GRKERNSEC_MODHARDEN if (MODULES)
49978 + select GRKERNSEC_HARDEN_PTRACE
49979 + select GRKERNSEC_PTRACE_READEXEC
49980 + select GRKERNSEC_VM86 if (X86_32)
49981 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
49982 + select PAX
49983 + select PAX_RANDUSTACK
49984 + select PAX_ASLR
49985 + select PAX_RANDMMAP
49986 + select PAX_NOEXEC
49987 + select PAX_MPROTECT
49988 + select PAX_EI_PAX
49989 + select PAX_PT_PAX_FLAGS
49990 + select PAX_HAVE_ACL_FLAGS
49991 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
49992 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
49993 + select PAX_RANDKSTACK if (X86_TSC && X86)
49994 + select PAX_SEGMEXEC if (X86_32)
49995 + select PAX_PAGEEXEC
49996 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
49997 + select PAX_EMUTRAMP if (PARISC)
49998 + select PAX_EMUSIGRT if (PARISC)
49999 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
50000 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
50001 + select PAX_REFCOUNT if (X86 || SPARC64)
50002 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
50003 + help
50004 + If you say Y here, many of the features of grsecurity will be
50005 + enabled, which will protect you against many kinds of attacks
50006 + against your system. The heightened security comes at a cost
50007 + of an increased chance of incompatibilities with rare software
50008 + on your machine. Since this security level enables PaX, you should
50009 + view <http://pax.grsecurity.net> and read about the PaX
50010 + project. While you are there, download chpax and run it on
50011 + binaries that cause problems with PaX. Also remember that
50012 + since the /proc restrictions are enabled, you must run your
50013 + identd as gid 1001. This security level enables the following
50014 + features in addition to those listed in the low and medium
50015 + security levels:
50016 +
50017 + - Additional /proc restrictions
50018 + - Chmod restrictions in chroot
50019 + - No signals, ptrace, or viewing of processes outside of chroot
50020 + - Capability restrictions in chroot
50021 + - Deny fchdir out of chroot
50022 + - Priority restrictions in chroot
50023 + - Segmentation-based implementation of PaX
50024 + - Mprotect restrictions
50025 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
50026 + - Kernel stack randomization
50027 + - Mount/unmount/remount logging
50028 + - Kernel symbol hiding
50029 + - Hardening of module auto-loading
50030 + - Ptrace restrictions
50031 + - Restricted vm86 mode
50032 + - Restricted sysfs/debugfs
50033 + - Active kernel exploit response
50034 +
50035 +config GRKERNSEC_CUSTOM
50036 + bool "Custom"
50037 + help
50038 + If you say Y here, you will be able to configure every grsecurity
50039 + option, which allows you to enable many more features that aren't
50040 + covered in the basic security levels. These additional features
50041 + include TPE, socket restrictions, and the sysctl system for
50042 + grsecurity. It is advised that you read through the help for
50043 + each option to determine its usefulness in your situation.
50044 +
50045 +endchoice
50046 +
50047 +menu "Memory Protections"
50048 +depends on GRKERNSEC
50049 +
50050 +config GRKERNSEC_KMEM
50051 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50052 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50053 + help
50054 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50055 + be written to or read from to modify or leak the contents of the running
50056 + kernel. /dev/port will also not be allowed to be opened. If you have module
50057 + support disabled, enabling this will close up four ways that are
50058 + currently used to insert malicious code into the running kernel.
50059 + Even with all these features enabled, we still highly recommend that
50060 + you use the RBAC system, as it is still possible for an attacker to
50061 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50062 + If you are not using XFree86, you may be able to stop this additional
50063 + case by enabling the 'Disable privileged I/O' option. Though nothing
50064 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50065 + but only to video memory, which is the only writing we allow in this
50066 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50067 + not be allowed to mprotect it with PROT_WRITE later.
50068 + It is highly recommended that you say Y here if you meet all the
50069 + conditions above.
50070 +
50071 +config GRKERNSEC_VM86
50072 + bool "Restrict VM86 mode"
50073 + depends on X86_32
50074 +
50075 + help
50076 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50077 + make use of a special execution mode on 32bit x86 processors called
50078 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50079 + video cards and will still work with this option enabled. The purpose
50080 + of the option is to prevent exploitation of emulation errors in
50081 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50082 + Nearly all users should be able to enable this option.
50083 +
50084 +config GRKERNSEC_IO
50085 + bool "Disable privileged I/O"
50086 + depends on X86
50087 + select RTC_CLASS
50088 + select RTC_INTF_DEV
50089 + select RTC_DRV_CMOS
50090 +
50091 + help
50092 + If you say Y here, all ioperm and iopl calls will return an error.
50093 + Ioperm and iopl can be used to modify the running kernel.
50094 + Unfortunately, some programs need this access to operate properly,
50095 + the most notable of which are XFree86 and hwclock. hwclock can be
50096 + remedied by having RTC support in the kernel, so real-time
50097 + clock support is enabled if this option is enabled, to ensure
50098 + that hwclock operates correctly. XFree86 still will not
50099 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50100 + IF YOU USE XFree86. If you use XFree86 and you still want to
50101 + protect your kernel against modification, use the RBAC system.
50102 +
50103 +config GRKERNSEC_PROC_MEMMAP
50104 + bool "Harden ASLR against information leaks and entropy reduction"
50105 + default y if (PAX_NOEXEC || PAX_ASLR)
50106 + depends on PAX_NOEXEC || PAX_ASLR
50107 + help
50108 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50109 + give no information about the addresses of its mappings if
50110 + PaX features that rely on random addresses are enabled on the task.
50111 + In addition to sanitizing this information and disabling other
50112 + dangerous sources of information, this option causes reads of sensitive
50113 + /proc/<pid> entries where the file descriptor was opened in a different
50114 + task than the one performing the read. Such attempts are logged.
50115 + This option also limits argv/env strings for suid/sgid binaries
50116 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50117 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50118 + binaries to prevent alternative mmap layouts from being abused.
50119 +
50120 + If you use PaX it is essential that you say Y here as it closes up
50121 + several holes that make full ASLR useless locally.
50122 +
50123 +config GRKERNSEC_BRUTE
50124 + bool "Deter exploit bruteforcing"
50125 + help
50126 + If you say Y here, attempts to bruteforce exploits against forking
50127 + daemons such as apache or sshd, as well as against suid/sgid binaries
50128 + will be deterred. When a child of a forking daemon is killed by PaX
50129 + or crashes due to an illegal instruction or other suspicious signal,
50130 + the parent process will be delayed 30 seconds upon every subsequent
50131 + fork until the administrator is able to assess the situation and
50132 + restart the daemon.
50133 + In the suid/sgid case, the attempt is logged, the user has all their
50134 + processes terminated, and they are prevented from executing any further
50135 + processes for 15 minutes.
50136 + It is recommended that you also enable signal logging in the auditing
50137 + section so that logs are generated when a process triggers a suspicious
50138 + signal.
50139 + If the sysctl option is enabled, a sysctl option with name
50140 + "deter_bruteforce" is created.
50141 +
50142 +
50143 +config GRKERNSEC_MODHARDEN
50144 + bool "Harden module auto-loading"
50145 + depends on MODULES
50146 + help
50147 + If you say Y here, module auto-loading in response to use of some
50148 + feature implemented by an unloaded module will be restricted to
50149 + root users. Enabling this option helps defend against attacks
50150 + by unprivileged users who abuse the auto-loading behavior to
50151 + cause a vulnerable module to load that is then exploited.
50152 +
50153 + If this option prevents a legitimate use of auto-loading for a
50154 + non-root user, the administrator can execute modprobe manually
50155 + with the exact name of the module mentioned in the alert log.
50156 + Alternatively, the administrator can add the module to the list
50157 + of modules loaded at boot by modifying init scripts.
50158 +
50159 + Modification of init scripts will most likely be needed on
50160 + Ubuntu servers with encrypted home directory support enabled,
50161 + as the first non-root user logging in will cause the ecb(aes),
50162 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50163 +
50164 +config GRKERNSEC_HIDESYM
50165 + bool "Hide kernel symbols"
50166 + help
50167 + If you say Y here, getting information on loaded modules, and
50168 + displaying all kernel symbols through a syscall will be restricted
50169 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50170 + /proc/kallsyms will be restricted to the root user. The RBAC
50171 + system can hide that entry even from root.
50172 +
50173 + This option also prevents leaking of kernel addresses through
50174 + several /proc entries.
50175 +
50176 + Note that this option is only effective provided the following
50177 + conditions are met:
50178 + 1) The kernel using grsecurity is not precompiled by some distribution
50179 + 2) You have also enabled GRKERNSEC_DMESG
50180 + 3) You are using the RBAC system and hiding other files such as your
50181 + kernel image and System.map. Alternatively, enabling this option
50182 + causes the permissions on /boot, /lib/modules, and the kernel
50183 + source directory to change at compile time to prevent
50184 + reading by non-root users.
50185 + If the above conditions are met, this option will aid in providing a
50186 + useful protection against local kernel exploitation of overflows
50187 + and arbitrary read/write vulnerabilities.
50188 +
50189 +config GRKERNSEC_KERN_LOCKOUT
50190 + bool "Active kernel exploit response"
50191 + depends on X86 || ARM || PPC || SPARC
50192 + help
50193 + If you say Y here, when a PaX alert is triggered due to suspicious
50194 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50195 + or an OOPs occurs due to bad memory accesses, instead of just
50196 + terminating the offending process (and potentially allowing
50197 + a subsequent exploit from the same user), we will take one of two
50198 + actions:
50199 + If the user was root, we will panic the system
50200 + If the user was non-root, we will log the attempt, terminate
50201 + all processes owned by the user, then prevent them from creating
50202 + any new processes until the system is restarted
50203 + This deters repeated kernel exploitation/bruteforcing attempts
50204 + and is useful for later forensics.
50205 +
50206 +endmenu
50207 +menu "Role Based Access Control Options"
50208 +depends on GRKERNSEC
50209 +
50210 +config GRKERNSEC_RBAC_DEBUG
50211 + bool
50212 +
50213 +config GRKERNSEC_NO_RBAC
50214 + bool "Disable RBAC system"
50215 + help
50216 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50217 + preventing the RBAC system from being enabled. You should only say Y
50218 + here if you have no intention of using the RBAC system, so as to prevent
50219 + an attacker with root access from misusing the RBAC system to hide files
50220 + and processes when loadable module support and /dev/[k]mem have been
50221 + locked down.
50222 +
50223 +config GRKERNSEC_ACL_HIDEKERN
50224 + bool "Hide kernel processes"
50225 + help
50226 + If you say Y here, all kernel threads will be hidden to all
50227 + processes but those whose subject has the "view hidden processes"
50228 + flag.
50229 +
50230 +config GRKERNSEC_ACL_MAXTRIES
50231 + int "Maximum tries before password lockout"
50232 + default 3
50233 + help
50234 + This option enforces the maximum number of times a user can attempt
50235 + to authorize themselves with the grsecurity RBAC system before being
50236 + denied the ability to attempt authorization again for a specified time.
50237 + The lower the number, the harder it will be to brute-force a password.
50238 +
50239 +config GRKERNSEC_ACL_TIMEOUT
50240 + int "Time to wait after max password tries, in seconds"
50241 + default 30
50242 + help
50243 + This option specifies the time the user must wait after attempting to
50244 + authorize to the RBAC system with the maximum number of invalid
50245 + passwords. The higher the number, the harder it will be to brute-force
50246 + a password.
50247 +
50248 +endmenu
50249 +menu "Filesystem Protections"
50250 +depends on GRKERNSEC
50251 +
50252 +config GRKERNSEC_PROC
50253 + bool "Proc restrictions"
50254 + help
50255 + If you say Y here, the permissions of the /proc filesystem
50256 + will be altered to enhance system security and privacy. You MUST
50257 + choose either a user only restriction or a user and group restriction.
50258 + Depending upon the option you choose, you can either restrict users to
50259 + see only the processes they themselves run, or choose a group that can
50260 + view all processes and files normally restricted to root if you choose
50261 + the "restrict to user only" option. NOTE: If you're running identd or
50262 + ntpd as a non-root user, you will have to run it as the group you
50263 + specify here.
50264 +
50265 +config GRKERNSEC_PROC_USER
50266 + bool "Restrict /proc to user only"
50267 + depends on GRKERNSEC_PROC
50268 + help
50269 + If you say Y here, non-root users will only be able to view their own
50270 + processes, and restricts them from viewing network-related information,
50271 + and viewing kernel symbol and module information.
50272 +
50273 +config GRKERNSEC_PROC_USERGROUP
50274 + bool "Allow special group"
50275 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50276 + help
50277 + If you say Y here, you will be able to select a group that will be
50278 + able to view all processes and network-related information. If you've
50279 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50280 + remain hidden. This option is useful if you want to run identd as
50281 + a non-root user.
50282 +
50283 +config GRKERNSEC_PROC_GID
50284 + int "GID for special group"
50285 + depends on GRKERNSEC_PROC_USERGROUP
50286 + default 1001
50287 +
50288 +config GRKERNSEC_PROC_ADD
50289 + bool "Additional restrictions"
50290 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50291 + help
50292 + If you say Y here, additional restrictions will be placed on
50293 + /proc that keep normal users from viewing device information and
50294 + slabinfo information that could be useful for exploits.
50295 +
50296 +config GRKERNSEC_LINK
50297 + bool "Linking restrictions"
50298 + help
50299 + If you say Y here, /tmp race exploits will be prevented, since users
50300 + will no longer be able to follow symlinks owned by other users in
50301 + world-writable +t directories (e.g. /tmp), unless the owner of the
50302 + symlink is the owner of the directory. users will also not be
50303 + able to hardlink to files they do not own. If the sysctl option is
50304 + enabled, a sysctl option with name "linking_restrictions" is created.
50305 +
50306 +config GRKERNSEC_FIFO
50307 + bool "FIFO restrictions"
50308 + help
50309 + If you say Y here, users will not be able to write to FIFOs they don't
50310 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50311 + the FIFO is the same owner of the directory it's held in. If the sysctl
50312 + option is enabled, a sysctl option with name "fifo_restrictions" is
50313 + created.
50314 +
50315 +config GRKERNSEC_SYSFS_RESTRICT
50316 + bool "Sysfs/debugfs restriction"
50317 + depends on SYSFS
50318 + help
50319 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50320 + any filesystem normally mounted under it (e.g. debugfs) will be
50321 + mostly accessible only by root. These filesystems generally provide access
50322 + to hardware and debug information that isn't appropriate for unprivileged
50323 + users of the system. Sysfs and debugfs have also become a large source
50324 + of new vulnerabilities, ranging from infoleaks to local compromise.
50325 + There has been very little oversight with an eye toward security involved
50326 + in adding new exporters of information to these filesystems, so their
50327 + use is discouraged.
50328 + For reasons of compatibility, a few directories have been whitelisted
50329 + for access by non-root users:
50330 + /sys/fs/selinux
50331 + /sys/fs/fuse
50332 + /sys/devices/system/cpu
50333 +
50334 +config GRKERNSEC_ROFS
50335 + bool "Runtime read-only mount protection"
50336 + help
50337 + If you say Y here, a sysctl option with name "romount_protect" will
50338 + be created. By setting this option to 1 at runtime, filesystems
50339 + will be protected in the following ways:
50340 + * No new writable mounts will be allowed
50341 + * Existing read-only mounts won't be able to be remounted read/write
50342 + * Write operations will be denied on all block devices
50343 + This option acts independently of grsec_lock: once it is set to 1,
50344 + it cannot be turned off. Therefore, please be mindful of the resulting
50345 + behavior if this option is enabled in an init script on a read-only
50346 + filesystem. This feature is mainly intended for secure embedded systems.
50347 +
50348 +config GRKERNSEC_CHROOT
50349 + bool "Chroot jail restrictions"
50350 + help
50351 + If you say Y here, you will be able to choose several options that will
50352 + make breaking out of a chrooted jail much more difficult. If you
50353 + encounter no software incompatibilities with the following options, it
50354 + is recommended that you enable each one.
50355 +
50356 +config GRKERNSEC_CHROOT_MOUNT
50357 + bool "Deny mounts"
50358 + depends on GRKERNSEC_CHROOT
50359 + help
50360 + If you say Y here, processes inside a chroot will not be able to
50361 + mount or remount filesystems. If the sysctl option is enabled, a
50362 + sysctl option with name "chroot_deny_mount" is created.
50363 +
50364 +config GRKERNSEC_CHROOT_DOUBLE
50365 + bool "Deny double-chroots"
50366 + depends on GRKERNSEC_CHROOT
50367 + help
50368 + If you say Y here, processes inside a chroot will not be able to chroot
50369 + again outside the chroot. This is a widely used method of breaking
50370 + out of a chroot jail and should not be allowed. If the sysctl
50371 + option is enabled, a sysctl option with name
50372 + "chroot_deny_chroot" is created.
50373 +
50374 +config GRKERNSEC_CHROOT_PIVOT
50375 + bool "Deny pivot_root in chroot"
50376 + depends on GRKERNSEC_CHROOT
50377 + help
50378 + If you say Y here, processes inside a chroot will not be able to use
50379 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50380 + works similar to chroot in that it changes the root filesystem. This
50381 + function could be misused in a chrooted process to attempt to break out
50382 + of the chroot, and therefore should not be allowed. If the sysctl
50383 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50384 + created.
50385 +
50386 +config GRKERNSEC_CHROOT_CHDIR
50387 + bool "Enforce chdir(\"/\") on all chroots"
50388 + depends on GRKERNSEC_CHROOT
50389 + help
50390 + If you say Y here, the current working directory of all newly-chrooted
50391 + applications will be set to the the root directory of the chroot.
50392 + The man page on chroot(2) states:
50393 + Note that this call does not change the current working
50394 + directory, so that `.' can be outside the tree rooted at
50395 + `/'. In particular, the super-user can escape from a
50396 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50397 +
50398 + It is recommended that you say Y here, since it's not known to break
50399 + any software. If the sysctl option is enabled, a sysctl option with
50400 + name "chroot_enforce_chdir" is created.
50401 +
50402 +config GRKERNSEC_CHROOT_CHMOD
50403 + bool "Deny (f)chmod +s"
50404 + depends on GRKERNSEC_CHROOT
50405 + help
50406 + If you say Y here, processes inside a chroot will not be able to chmod
50407 + or fchmod files to make them have suid or sgid bits. This protects
50408 + against another published method of breaking a chroot. If the sysctl
50409 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50410 + created.
50411 +
50412 +config GRKERNSEC_CHROOT_FCHDIR
50413 + bool "Deny fchdir out of chroot"
50414 + depends on GRKERNSEC_CHROOT
50415 + help
50416 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50417 + to a file descriptor of the chrooting process that points to a directory
50418 + outside the filesystem will be stopped. If the sysctl option
50419 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50420 +
50421 +config GRKERNSEC_CHROOT_MKNOD
50422 + bool "Deny mknod"
50423 + depends on GRKERNSEC_CHROOT
50424 + help
50425 + If you say Y here, processes inside a chroot will not be allowed to
50426 + mknod. The problem with using mknod inside a chroot is that it
50427 + would allow an attacker to create a device entry that is the same
50428 + as one on the physical root of your system, which could range from
50429 + anything from the console device to a device for your harddrive (which
50430 + they could then use to wipe the drive or steal data). It is recommended
50431 + that you say Y here, unless you run into software incompatibilities.
50432 + If the sysctl option is enabled, a sysctl option with name
50433 + "chroot_deny_mknod" is created.
50434 +
50435 +config GRKERNSEC_CHROOT_SHMAT
50436 + bool "Deny shmat() out of chroot"
50437 + depends on GRKERNSEC_CHROOT
50438 + help
50439 + If you say Y here, processes inside a chroot will not be able to attach
50440 + to shared memory segments that were created outside of the chroot jail.
50441 + It is recommended that you say Y here. If the sysctl option is enabled,
50442 + a sysctl option with name "chroot_deny_shmat" is created.
50443 +
50444 +config GRKERNSEC_CHROOT_UNIX
50445 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50446 + depends on GRKERNSEC_CHROOT
50447 + help
50448 + If you say Y here, processes inside a chroot will not be able to
50449 + connect to abstract (meaning not belonging to a filesystem) Unix
50450 + domain sockets that were bound outside of a chroot. It is recommended
50451 + that you say Y here. If the sysctl option is enabled, a sysctl option
50452 + with name "chroot_deny_unix" is created.
50453 +
50454 +config GRKERNSEC_CHROOT_FINDTASK
50455 + bool "Protect outside processes"
50456 + depends on GRKERNSEC_CHROOT
50457 + help
50458 + If you say Y here, processes inside a chroot will not be able to
50459 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50460 + getsid, or view any process outside of the chroot. If the sysctl
50461 + option is enabled, a sysctl option with name "chroot_findtask" is
50462 + created.
50463 +
50464 +config GRKERNSEC_CHROOT_NICE
50465 + bool "Restrict priority changes"
50466 + depends on GRKERNSEC_CHROOT
50467 + help
50468 + If you say Y here, processes inside a chroot will not be able to raise
50469 + the priority of processes in the chroot, or alter the priority of
50470 + processes outside the chroot. This provides more security than simply
50471 + removing CAP_SYS_NICE from the process' capability set. If the
50472 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50473 + is created.
50474 +
50475 +config GRKERNSEC_CHROOT_SYSCTL
50476 + bool "Deny sysctl writes"
50477 + depends on GRKERNSEC_CHROOT
50478 + help
50479 + If you say Y here, an attacker in a chroot will not be able to
50480 + write to sysctl entries, either by sysctl(2) or through a /proc
50481 + interface. It is strongly recommended that you say Y here. If the
50482 + sysctl option is enabled, a sysctl option with name
50483 + "chroot_deny_sysctl" is created.
50484 +
50485 +config GRKERNSEC_CHROOT_CAPS
50486 + bool "Capability restrictions"
50487 + depends on GRKERNSEC_CHROOT
50488 + help
50489 + If you say Y here, the capabilities on all processes within a
50490 + chroot jail will be lowered to stop module insertion, raw i/o,
50491 + system and net admin tasks, rebooting the system, modifying immutable
50492 + files, modifying IPC owned by another, and changing the system time.
50493 + This is left an option because it can break some apps. Disable this
50494 + if your chrooted apps are having problems performing those kinds of
50495 + tasks. If the sysctl option is enabled, a sysctl option with
50496 + name "chroot_caps" is created.
50497 +
50498 +endmenu
50499 +menu "Kernel Auditing"
50500 +depends on GRKERNSEC
50501 +
50502 +config GRKERNSEC_AUDIT_GROUP
50503 + bool "Single group for auditing"
50504 + help
50505 + If you say Y here, the exec, chdir, and (un)mount logging features
50506 + will only operate on a group you specify. This option is recommended
50507 + if you only want to watch certain users instead of having a large
50508 + amount of logs from the entire system. If the sysctl option is enabled,
50509 + a sysctl option with name "audit_group" is created.
50510 +
50511 +config GRKERNSEC_AUDIT_GID
50512 + int "GID for auditing"
50513 + depends on GRKERNSEC_AUDIT_GROUP
50514 + default 1007
50515 +
50516 +config GRKERNSEC_EXECLOG
50517 + bool "Exec logging"
50518 + help
50519 + If you say Y here, all execve() calls will be logged (since the
50520 + other exec*() calls are frontends to execve(), all execution
50521 + will be logged). Useful for shell-servers that like to keep track
50522 + of their users. If the sysctl option is enabled, a sysctl option with
50523 + name "exec_logging" is created.
50524 + WARNING: This option when enabled will produce a LOT of logs, especially
50525 + on an active system.
50526 +
50527 +config GRKERNSEC_RESLOG
50528 + bool "Resource logging"
50529 + help
50530 + If you say Y here, all attempts to overstep resource limits will
50531 + be logged with the resource name, the requested size, and the current
50532 + limit. It is highly recommended that you say Y here. If the sysctl
50533 + option is enabled, a sysctl option with name "resource_logging" is
50534 + created. If the RBAC system is enabled, the sysctl value is ignored.
50535 +
50536 +config GRKERNSEC_CHROOT_EXECLOG
50537 + bool "Log execs within chroot"
50538 + help
50539 + If you say Y here, all executions inside a chroot jail will be logged
50540 + to syslog. This can cause a large amount of logs if certain
50541 + applications (eg. djb's daemontools) are installed on the system, and
50542 + is therefore left as an option. If the sysctl option is enabled, a
50543 + sysctl option with name "chroot_execlog" is created.
50544 +
50545 +config GRKERNSEC_AUDIT_PTRACE
50546 + bool "Ptrace logging"
50547 + help
50548 + If you say Y here, all attempts to attach to a process via ptrace
50549 + will be logged. If the sysctl option is enabled, a sysctl option
50550 + with name "audit_ptrace" is created.
50551 +
50552 +config GRKERNSEC_AUDIT_CHDIR
50553 + bool "Chdir logging"
50554 + help
50555 + If you say Y here, all chdir() calls will be logged. If the sysctl
50556 + option is enabled, a sysctl option with name "audit_chdir" is created.
50557 +
50558 +config GRKERNSEC_AUDIT_MOUNT
50559 + bool "(Un)Mount logging"
50560 + help
50561 + If you say Y here, all mounts and unmounts will be logged. If the
50562 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50563 + created.
50564 +
50565 +config GRKERNSEC_SIGNAL
50566 + bool "Signal logging"
50567 + help
50568 + If you say Y here, certain important signals will be logged, such as
50569 + SIGSEGV, which will as a result inform you of when a error in a program
50570 + occurred, which in some cases could mean a possible exploit attempt.
50571 + If the sysctl option is enabled, a sysctl option with name
50572 + "signal_logging" is created.
50573 +
50574 +config GRKERNSEC_FORKFAIL
50575 + bool "Fork failure logging"
50576 + help
50577 + If you say Y here, all failed fork() attempts will be logged.
50578 + This could suggest a fork bomb, or someone attempting to overstep
50579 + their process limit. If the sysctl option is enabled, a sysctl option
50580 + with name "forkfail_logging" is created.
50581 +
50582 +config GRKERNSEC_TIME
50583 + bool "Time change logging"
50584 + help
50585 + If you say Y here, any changes of the system clock will be logged.
50586 + If the sysctl option is enabled, a sysctl option with name
50587 + "timechange_logging" is created.
50588 +
50589 +config GRKERNSEC_PROC_IPADDR
50590 + bool "/proc/<pid>/ipaddr support"
50591 + help
50592 + If you say Y here, a new entry will be added to each /proc/<pid>
50593 + directory that contains the IP address of the person using the task.
50594 + The IP is carried across local TCP and AF_UNIX stream sockets.
50595 + This information can be useful for IDS/IPSes to perform remote response
50596 + to a local attack. The entry is readable by only the owner of the
50597 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50598 + the RBAC system), and thus does not create privacy concerns.
50599 +
50600 +config GRKERNSEC_RWXMAP_LOG
50601 + bool 'Denied RWX mmap/mprotect logging'
50602 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50603 + help
50604 + If you say Y here, calls to mmap() and mprotect() with explicit
50605 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50606 + denied by the PAX_MPROTECT feature. If the sysctl option is
50607 + enabled, a sysctl option with name "rwxmap_logging" is created.
50608 +
50609 +config GRKERNSEC_AUDIT_TEXTREL
50610 + bool 'ELF text relocations logging (READ HELP)'
50611 + depends on PAX_MPROTECT
50612 + help
50613 + If you say Y here, text relocations will be logged with the filename
50614 + of the offending library or binary. The purpose of the feature is
50615 + to help Linux distribution developers get rid of libraries and
50616 + binaries that need text relocations which hinder the future progress
50617 + of PaX. Only Linux distribution developers should say Y here, and
50618 + never on a production machine, as this option creates an information
50619 + leak that could aid an attacker in defeating the randomization of
50620 + a single memory region. If the sysctl option is enabled, a sysctl
50621 + option with name "audit_textrel" is created.
50622 +
50623 +endmenu
50624 +
50625 +menu "Executable Protections"
50626 +depends on GRKERNSEC
50627 +
50628 +config GRKERNSEC_DMESG
50629 + bool "Dmesg(8) restriction"
50630 + help
50631 + If you say Y here, non-root users will not be able to use dmesg(8)
50632 + to view up to the last 4kb of messages in the kernel's log buffer.
50633 + The kernel's log buffer often contains kernel addresses and other
50634 + identifying information useful to an attacker in fingerprinting a
50635 + system for a targeted exploit.
50636 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50637 + created.
50638 +
50639 +config GRKERNSEC_HARDEN_PTRACE
50640 + bool "Deter ptrace-based process snooping"
50641 + help
50642 + If you say Y here, TTY sniffers and other malicious monitoring
50643 + programs implemented through ptrace will be defeated. If you
50644 + have been using the RBAC system, this option has already been
50645 + enabled for several years for all users, with the ability to make
50646 + fine-grained exceptions.
50647 +
50648 + This option only affects the ability of non-root users to ptrace
50649 + processes that are not a descendent of the ptracing process.
50650 + This means that strace ./binary and gdb ./binary will still work,
50651 + but attaching to arbitrary processes will not. If the sysctl
50652 + option is enabled, a sysctl option with name "harden_ptrace" is
50653 + created.
50654 +
50655 +config GRKERNSEC_PTRACE_READEXEC
50656 + bool "Require read access to ptrace sensitive binaries"
50657 + help
50658 + If you say Y here, unprivileged users will not be able to ptrace unreadable
50659 + binaries. This option is useful in environments that
50660 + remove the read bits (e.g. file mode 4711) from suid binaries to
50661 + prevent infoleaking of their contents. This option adds
50662 + consistency to the use of that file mode, as the binary could normally
50663 + be read out when run without privileges while ptracing.
50664 +
50665 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50666 + is created.
50667 +
50668 +config GRKERNSEC_SETXID
50669 + bool "Enforce consistent multithreaded privileges"
50670 + help
50671 + If you say Y here, a change from a root uid to a non-root uid
50672 + in a multithreaded application will cause the resulting uids,
50673 + gids, supplementary groups, and capabilities in that thread
50674 + to be propagated to the other threads of the process. In most
50675 + cases this is unnecessary, as glibc will emulate this behavior
50676 + on behalf of the application. Other libcs do not act in the
50677 + same way, allowing the other threads of the process to continue
50678 + running with root privileges. If the sysctl option is enabled,
50679 + a sysctl option with name "consistent_setxid" is created.
50680 +
50681 +config GRKERNSEC_TPE
50682 + bool "Trusted Path Execution (TPE)"
50683 + help
50684 + If you say Y here, you will be able to choose a gid to add to the
50685 + supplementary groups of users you want to mark as "untrusted."
50686 + These users will not be able to execute any files that are not in
50687 + root-owned directories writable only by root. If the sysctl option
50688 + is enabled, a sysctl option with name "tpe" is created.
50689 +
50690 +config GRKERNSEC_TPE_ALL
50691 + bool "Partially restrict all non-root users"
50692 + depends on GRKERNSEC_TPE
50693 + help
50694 + If you say Y here, all non-root users will be covered under
50695 + a weaker TPE restriction. This is separate from, and in addition to,
50696 + the main TPE options that you have selected elsewhere. Thus, if a
50697 + "trusted" GID is chosen, this restriction applies to even that GID.
50698 + Under this restriction, all non-root users will only be allowed to
50699 + execute files in directories they own that are not group or
50700 + world-writable, or in directories owned by root and writable only by
50701 + root. If the sysctl option is enabled, a sysctl option with name
50702 + "tpe_restrict_all" is created.
50703 +
50704 +config GRKERNSEC_TPE_INVERT
50705 + bool "Invert GID option"
50706 + depends on GRKERNSEC_TPE
50707 + help
50708 + If you say Y here, the group you specify in the TPE configuration will
50709 + decide what group TPE restrictions will be *disabled* for. This
50710 + option is useful if you want TPE restrictions to be applied to most
50711 + users on the system. If the sysctl option is enabled, a sysctl option
50712 + with name "tpe_invert" is created. Unlike other sysctl options, this
50713 + entry will default to on for backward-compatibility.
50714 +
50715 +config GRKERNSEC_TPE_GID
50716 + int "GID for untrusted users"
50717 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50718 + default 1005
50719 + help
50720 + Setting this GID determines what group TPE restrictions will be
50721 + *enabled* for. If the sysctl option is enabled, a sysctl option
50722 + with name "tpe_gid" is created.
50723 +
50724 +config GRKERNSEC_TPE_GID
50725 + int "GID for trusted users"
50726 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50727 + default 1005
50728 + help
50729 + Setting this GID determines what group TPE restrictions will be
50730 + *disabled* for. If the sysctl option is enabled, a sysctl option
50731 + with name "tpe_gid" is created.
50732 +
50733 +endmenu
50734 +menu "Network Protections"
50735 +depends on GRKERNSEC
50736 +
50737 +config GRKERNSEC_RANDNET
50738 + bool "Larger entropy pools"
50739 + help
50740 + If you say Y here, the entropy pools used for many features of Linux
50741 + and grsecurity will be doubled in size. Since several grsecurity
50742 + features use additional randomness, it is recommended that you say Y
50743 + here. Saying Y here has a similar effect as modifying
50744 + /proc/sys/kernel/random/poolsize.
50745 +
50746 +config GRKERNSEC_BLACKHOLE
50747 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50748 + depends on NET
50749 + help
50750 + If you say Y here, neither TCP resets nor ICMP
50751 + destination-unreachable packets will be sent in response to packets
50752 + sent to ports for which no associated listening process exists.
50753 + This feature supports both IPV4 and IPV6 and exempts the
50754 + loopback interface from blackholing. Enabling this feature
50755 + makes a host more resilient to DoS attacks and reduces network
50756 + visibility against scanners.
50757 +
50758 + The blackhole feature as-implemented is equivalent to the FreeBSD
50759 + blackhole feature, as it prevents RST responses to all packets, not
50760 + just SYNs. Under most application behavior this causes no
50761 + problems, but applications (like haproxy) may not close certain
50762 + connections in a way that cleanly terminates them on the remote
50763 + end, leaving the remote host in LAST_ACK state. Because of this
50764 + side-effect and to prevent intentional LAST_ACK DoSes, this
50765 + feature also adds automatic mitigation against such attacks.
50766 + The mitigation drastically reduces the amount of time a socket
50767 + can spend in LAST_ACK state. If you're using haproxy and not
50768 + all servers it connects to have this option enabled, consider
50769 + disabling this feature on the haproxy host.
50770 +
50771 + If the sysctl option is enabled, two sysctl options with names
50772 + "ip_blackhole" and "lastack_retries" will be created.
50773 + While "ip_blackhole" takes the standard zero/non-zero on/off
50774 + toggle, "lastack_retries" uses the same kinds of values as
50775 + "tcp_retries1" and "tcp_retries2". The default value of 4
50776 + prevents a socket from lasting more than 45 seconds in LAST_ACK
50777 + state.
50778 +
50779 +config GRKERNSEC_SOCKET
50780 + bool "Socket restrictions"
50781 + depends on NET
50782 + help
50783 + If you say Y here, you will be able to choose from several options.
50784 + If you assign a GID on your system and add it to the supplementary
50785 + groups of users you want to restrict socket access to, this patch
50786 + will perform up to three things, based on the option(s) you choose.
50787 +
50788 +config GRKERNSEC_SOCKET_ALL
50789 + bool "Deny any sockets to group"
50790 + depends on GRKERNSEC_SOCKET
50791 + help
50792 + If you say Y here, you will be able to choose a GID of whose users will
50793 + be unable to connect to other hosts from your machine or run server
50794 + applications from your machine. If the sysctl option is enabled, a
50795 + sysctl option with name "socket_all" is created.
50796 +
50797 +config GRKERNSEC_SOCKET_ALL_GID
50798 + int "GID to deny all sockets for"
50799 + depends on GRKERNSEC_SOCKET_ALL
50800 + default 1004
50801 + help
50802 + Here you can choose the GID to disable socket access for. Remember to
50803 + add the users you want socket access disabled for to the GID
50804 + specified here. If the sysctl option is enabled, a sysctl option
50805 + with name "socket_all_gid" is created.
50806 +
50807 +config GRKERNSEC_SOCKET_CLIENT
50808 + bool "Deny client sockets to group"
50809 + depends on GRKERNSEC_SOCKET
50810 + help
50811 + If you say Y here, you will be able to choose a GID of whose users will
50812 + be unable to connect to other hosts from your machine, but will be
50813 + able to run servers. If this option is enabled, all users in the group
50814 + you specify will have to use passive mode when initiating ftp transfers
50815 + from the shell on your machine. If the sysctl option is enabled, a
50816 + sysctl option with name "socket_client" is created.
50817 +
50818 +config GRKERNSEC_SOCKET_CLIENT_GID
50819 + int "GID to deny client sockets for"
50820 + depends on GRKERNSEC_SOCKET_CLIENT
50821 + default 1003
50822 + help
50823 + Here you can choose the GID to disable client socket access for.
50824 + Remember to add the users you want client socket access disabled for to
50825 + the GID specified here. If the sysctl option is enabled, a sysctl
50826 + option with name "socket_client_gid" is created.
50827 +
50828 +config GRKERNSEC_SOCKET_SERVER
50829 + bool "Deny server sockets to group"
50830 + depends on GRKERNSEC_SOCKET
50831 + help
50832 + If you say Y here, you will be able to choose a GID of whose users will
50833 + be unable to run server applications from your machine. If the sysctl
50834 + option is enabled, a sysctl option with name "socket_server" is created.
50835 +
50836 +config GRKERNSEC_SOCKET_SERVER_GID
50837 + int "GID to deny server sockets for"
50838 + depends on GRKERNSEC_SOCKET_SERVER
50839 + default 1002
50840 + help
50841 + Here you can choose the GID to disable server socket access for.
50842 + Remember to add the users you want server socket access disabled for to
50843 + the GID specified here. If the sysctl option is enabled, a sysctl
50844 + option with name "socket_server_gid" is created.
50845 +
50846 +endmenu
50847 +menu "Sysctl support"
50848 +depends on GRKERNSEC && SYSCTL
50849 +
50850 +config GRKERNSEC_SYSCTL
50851 + bool "Sysctl support"
50852 + help
50853 + If you say Y here, you will be able to change the options that
50854 + grsecurity runs with at bootup, without having to recompile your
50855 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50856 + to enable (1) or disable (0) various features. All the sysctl entries
50857 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50858 + All features enabled in the kernel configuration are disabled at boot
50859 + if you do not say Y to the "Turn on features by default" option.
50860 + All options should be set at startup, and the grsec_lock entry should
50861 + be set to a non-zero value after all the options are set.
50862 + *THIS IS EXTREMELY IMPORTANT*
50863 +
50864 +config GRKERNSEC_SYSCTL_DISTRO
50865 + bool "Extra sysctl support for distro makers (READ HELP)"
50866 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50867 + help
50868 + If you say Y here, additional sysctl options will be created
50869 + for features that affect processes running as root. Therefore,
50870 + it is critical when using this option that the grsec_lock entry be
50871 + enabled after boot. Only distros with prebuilt kernel packages
50872 + with this option enabled that can ensure grsec_lock is enabled
50873 + after boot should use this option.
50874 + *Failure to set grsec_lock after boot makes all grsec features
50875 + this option covers useless*
50876 +
50877 + Currently this option creates the following sysctl entries:
50878 + "Disable Privileged I/O": "disable_priv_io"
50879 +
50880 +config GRKERNSEC_SYSCTL_ON
50881 + bool "Turn on features by default"
50882 + depends on GRKERNSEC_SYSCTL
50883 + help
50884 + If you say Y here, instead of having all features enabled in the
50885 + kernel configuration disabled at boot time, the features will be
50886 + enabled at boot time. It is recommended you say Y here unless
50887 + there is some reason you would want all sysctl-tunable features to
50888 + be disabled by default. As mentioned elsewhere, it is important
50889 + to enable the grsec_lock entry once you have finished modifying
50890 + the sysctl entries.
50891 +
50892 +endmenu
50893 +menu "Logging Options"
50894 +depends on GRKERNSEC
50895 +
50896 +config GRKERNSEC_FLOODTIME
50897 + int "Seconds in between log messages (minimum)"
50898 + default 10
50899 + help
50900 + This option allows you to enforce the number of seconds between
50901 + grsecurity log messages. The default should be suitable for most
50902 + people, however, if you choose to change it, choose a value small enough
50903 + to allow informative logs to be produced, but large enough to
50904 + prevent flooding.
50905 +
50906 +config GRKERNSEC_FLOODBURST
50907 + int "Number of messages in a burst (maximum)"
50908 + default 6
50909 + help
50910 + This option allows you to choose the maximum number of messages allowed
50911 + within the flood time interval you chose in a separate option. The
50912 + default should be suitable for most people, however if you find that
50913 + many of your logs are being interpreted as flooding, you may want to
50914 + raise this value.
50915 +
50916 +endmenu
50917 +
50918 +endmenu
50919 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50920 new file mode 100644
50921 index 0000000..1b9afa9
50922 --- /dev/null
50923 +++ b/grsecurity/Makefile
50924 @@ -0,0 +1,38 @@
50925 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50926 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50927 +# into an RBAC system
50928 +#
50929 +# All code in this directory and various hooks inserted throughout the kernel
50930 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50931 +# under the GPL v2 or higher
50932 +
50933 +KBUILD_CFLAGS += -Werror
50934 +
50935 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50936 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50937 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50938 +
50939 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50940 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50941 + gracl_learn.o grsec_log.o
50942 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50943 +
50944 +ifdef CONFIG_NET
50945 +obj-y += grsec_sock.o
50946 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50947 +endif
50948 +
50949 +ifndef CONFIG_GRKERNSEC
50950 +obj-y += grsec_disabled.o
50951 +endif
50952 +
50953 +ifdef CONFIG_GRKERNSEC_HIDESYM
50954 +extra-y := grsec_hidesym.o
50955 +$(obj)/grsec_hidesym.o:
50956 + @-chmod -f 500 /boot
50957 + @-chmod -f 500 /lib/modules
50958 + @-chmod -f 500 /lib64/modules
50959 + @-chmod -f 500 /lib32/modules
50960 + @-chmod -f 700 .
50961 + @echo ' grsec: protected kernel image paths'
50962 +endif
50963 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50964 new file mode 100644
50965 index 0000000..a6d83f0
50966 --- /dev/null
50967 +++ b/grsecurity/gracl.c
50968 @@ -0,0 +1,4193 @@
50969 +#include <linux/kernel.h>
50970 +#include <linux/module.h>
50971 +#include <linux/sched.h>
50972 +#include <linux/mm.h>
50973 +#include <linux/file.h>
50974 +#include <linux/fs.h>
50975 +#include <linux/namei.h>
50976 +#include <linux/mount.h>
50977 +#include <linux/tty.h>
50978 +#include <linux/proc_fs.h>
50979 +#include <linux/lglock.h>
50980 +#include <linux/slab.h>
50981 +#include <linux/vmalloc.h>
50982 +#include <linux/types.h>
50983 +#include <linux/sysctl.h>
50984 +#include <linux/netdevice.h>
50985 +#include <linux/ptrace.h>
50986 +#include <linux/gracl.h>
50987 +#include <linux/gralloc.h>
50988 +#include <linux/security.h>
50989 +#include <linux/grinternal.h>
50990 +#include <linux/pid_namespace.h>
50991 +#include <linux/fdtable.h>
50992 +#include <linux/percpu.h>
50993 +#include "../fs/mount.h"
50994 +
50995 +#include <asm/uaccess.h>
50996 +#include <asm/errno.h>
50997 +#include <asm/mman.h>
50998 +
50999 +static struct acl_role_db acl_role_set;
51000 +static struct name_db name_set;
51001 +static struct inodev_db inodev_set;
51002 +
51003 +/* for keeping track of userspace pointers used for subjects, so we
51004 + can share references in the kernel as well
51005 +*/
51006 +
51007 +static struct path real_root;
51008 +
51009 +static struct acl_subj_map_db subj_map_set;
51010 +
51011 +static struct acl_role_label *default_role;
51012 +
51013 +static struct acl_role_label *role_list;
51014 +
51015 +static u16 acl_sp_role_value;
51016 +
51017 +extern char *gr_shared_page[4];
51018 +static DEFINE_MUTEX(gr_dev_mutex);
51019 +DEFINE_RWLOCK(gr_inode_lock);
51020 +
51021 +struct gr_arg *gr_usermode;
51022 +
51023 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51024 +
51025 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51026 +extern void gr_clear_learn_entries(void);
51027 +
51028 +#ifdef CONFIG_GRKERNSEC_RESLOG
51029 +extern void gr_log_resource(const struct task_struct *task,
51030 + const int res, const unsigned long wanted, const int gt);
51031 +#endif
51032 +
51033 +unsigned char *gr_system_salt;
51034 +unsigned char *gr_system_sum;
51035 +
51036 +static struct sprole_pw **acl_special_roles = NULL;
51037 +static __u16 num_sprole_pws = 0;
51038 +
51039 +static struct acl_role_label *kernel_role = NULL;
51040 +
51041 +static unsigned int gr_auth_attempts = 0;
51042 +static unsigned long gr_auth_expires = 0UL;
51043 +
51044 +#ifdef CONFIG_NET
51045 +extern struct vfsmount *sock_mnt;
51046 +#endif
51047 +
51048 +extern struct vfsmount *pipe_mnt;
51049 +extern struct vfsmount *shm_mnt;
51050 +#ifdef CONFIG_HUGETLBFS
51051 +extern struct vfsmount *hugetlbfs_vfsmount;
51052 +#endif
51053 +
51054 +static struct acl_object_label *fakefs_obj_rw;
51055 +static struct acl_object_label *fakefs_obj_rwx;
51056 +
51057 +extern int gr_init_uidset(void);
51058 +extern void gr_free_uidset(void);
51059 +extern void gr_remove_uid(uid_t uid);
51060 +extern int gr_find_uid(uid_t uid);
51061 +
51062 +DECLARE_BRLOCK(vfsmount_lock);
51063 +
51064 +__inline__ int
51065 +gr_acl_is_enabled(void)
51066 +{
51067 + return (gr_status & GR_READY);
51068 +}
51069 +
51070 +#ifdef CONFIG_BTRFS_FS
51071 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51072 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51073 +#endif
51074 +
51075 +static inline dev_t __get_dev(const struct dentry *dentry)
51076 +{
51077 +#ifdef CONFIG_BTRFS_FS
51078 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51079 + return get_btrfs_dev_from_inode(dentry->d_inode);
51080 + else
51081 +#endif
51082 + return dentry->d_inode->i_sb->s_dev;
51083 +}
51084 +
51085 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51086 +{
51087 + return __get_dev(dentry);
51088 +}
51089 +
51090 +static char gr_task_roletype_to_char(struct task_struct *task)
51091 +{
51092 + switch (task->role->roletype &
51093 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51094 + GR_ROLE_SPECIAL)) {
51095 + case GR_ROLE_DEFAULT:
51096 + return 'D';
51097 + case GR_ROLE_USER:
51098 + return 'U';
51099 + case GR_ROLE_GROUP:
51100 + return 'G';
51101 + case GR_ROLE_SPECIAL:
51102 + return 'S';
51103 + }
51104 +
51105 + return 'X';
51106 +}
51107 +
51108 +char gr_roletype_to_char(void)
51109 +{
51110 + return gr_task_roletype_to_char(current);
51111 +}
51112 +
51113 +__inline__ int
51114 +gr_acl_tpe_check(void)
51115 +{
51116 + if (unlikely(!(gr_status & GR_READY)))
51117 + return 0;
51118 + if (current->role->roletype & GR_ROLE_TPE)
51119 + return 1;
51120 + else
51121 + return 0;
51122 +}
51123 +
51124 +int
51125 +gr_handle_rawio(const struct inode *inode)
51126 +{
51127 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51128 + if (inode && S_ISBLK(inode->i_mode) &&
51129 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51130 + !capable(CAP_SYS_RAWIO))
51131 + return 1;
51132 +#endif
51133 + return 0;
51134 +}
51135 +
51136 +static int
51137 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51138 +{
51139 + if (likely(lena != lenb))
51140 + return 0;
51141 +
51142 + return !memcmp(a, b, lena);
51143 +}
51144 +
51145 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51146 +{
51147 + *buflen -= namelen;
51148 + if (*buflen < 0)
51149 + return -ENAMETOOLONG;
51150 + *buffer -= namelen;
51151 + memcpy(*buffer, str, namelen);
51152 + return 0;
51153 +}
51154 +
51155 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51156 +{
51157 + return prepend(buffer, buflen, name->name, name->len);
51158 +}
51159 +
51160 +static int prepend_path(const struct path *path, struct path *root,
51161 + char **buffer, int *buflen)
51162 +{
51163 + struct dentry *dentry = path->dentry;
51164 + struct vfsmount *vfsmnt = path->mnt;
51165 + struct mount *mnt = real_mount(vfsmnt);
51166 + bool slash = false;
51167 + int error = 0;
51168 +
51169 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51170 + struct dentry * parent;
51171 +
51172 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51173 + /* Global root? */
51174 + if (!mnt_has_parent(mnt)) {
51175 + goto out;
51176 + }
51177 + dentry = mnt->mnt_mountpoint;
51178 + mnt = mnt->mnt_parent;
51179 + vfsmnt = &mnt->mnt;
51180 + continue;
51181 + }
51182 + parent = dentry->d_parent;
51183 + prefetch(parent);
51184 + spin_lock(&dentry->d_lock);
51185 + error = prepend_name(buffer, buflen, &dentry->d_name);
51186 + spin_unlock(&dentry->d_lock);
51187 + if (!error)
51188 + error = prepend(buffer, buflen, "/", 1);
51189 + if (error)
51190 + break;
51191 +
51192 + slash = true;
51193 + dentry = parent;
51194 + }
51195 +
51196 +out:
51197 + if (!error && !slash)
51198 + error = prepend(buffer, buflen, "/", 1);
51199 +
51200 + return error;
51201 +}
51202 +
51203 +/* this must be called with vfsmount_lock and rename_lock held */
51204 +
51205 +static char *__our_d_path(const struct path *path, struct path *root,
51206 + char *buf, int buflen)
51207 +{
51208 + char *res = buf + buflen;
51209 + int error;
51210 +
51211 + prepend(&res, &buflen, "\0", 1);
51212 + error = prepend_path(path, root, &res, &buflen);
51213 + if (error)
51214 + return ERR_PTR(error);
51215 +
51216 + return res;
51217 +}
51218 +
51219 +static char *
51220 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51221 +{
51222 + char *retval;
51223 +
51224 + retval = __our_d_path(path, root, buf, buflen);
51225 + if (unlikely(IS_ERR(retval)))
51226 + retval = strcpy(buf, "<path too long>");
51227 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51228 + retval[1] = '\0';
51229 +
51230 + return retval;
51231 +}
51232 +
51233 +static char *
51234 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51235 + char *buf, int buflen)
51236 +{
51237 + struct path path;
51238 + char *res;
51239 +
51240 + path.dentry = (struct dentry *)dentry;
51241 + path.mnt = (struct vfsmount *)vfsmnt;
51242 +
51243 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51244 + by the RBAC system */
51245 + res = gen_full_path(&path, &real_root, buf, buflen);
51246 +
51247 + return res;
51248 +}
51249 +
51250 +static char *
51251 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51252 + char *buf, int buflen)
51253 +{
51254 + char *res;
51255 + struct path path;
51256 + struct path root;
51257 + struct task_struct *reaper = &init_task;
51258 +
51259 + path.dentry = (struct dentry *)dentry;
51260 + path.mnt = (struct vfsmount *)vfsmnt;
51261 +
51262 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51263 + get_fs_root(reaper->fs, &root);
51264 +
51265 + write_seqlock(&rename_lock);
51266 + br_read_lock(vfsmount_lock);
51267 + res = gen_full_path(&path, &root, buf, buflen);
51268 + br_read_unlock(vfsmount_lock);
51269 + write_sequnlock(&rename_lock);
51270 +
51271 + path_put(&root);
51272 + return res;
51273 +}
51274 +
51275 +static char *
51276 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51277 +{
51278 + char *ret;
51279 + write_seqlock(&rename_lock);
51280 + br_read_lock(vfsmount_lock);
51281 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51282 + PAGE_SIZE);
51283 + br_read_unlock(vfsmount_lock);
51284 + write_sequnlock(&rename_lock);
51285 + return ret;
51286 +}
51287 +
51288 +static char *
51289 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51290 +{
51291 + char *ret;
51292 + char *buf;
51293 + int buflen;
51294 +
51295 + write_seqlock(&rename_lock);
51296 + br_read_lock(vfsmount_lock);
51297 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51298 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51299 + buflen = (int)(ret - buf);
51300 + if (buflen >= 5)
51301 + prepend(&ret, &buflen, "/proc", 5);
51302 + else
51303 + ret = strcpy(buf, "<path too long>");
51304 + br_read_unlock(vfsmount_lock);
51305 + write_sequnlock(&rename_lock);
51306 + return ret;
51307 +}
51308 +
51309 +char *
51310 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51311 +{
51312 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51313 + PAGE_SIZE);
51314 +}
51315 +
51316 +char *
51317 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51318 +{
51319 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51320 + PAGE_SIZE);
51321 +}
51322 +
51323 +char *
51324 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51325 +{
51326 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51327 + PAGE_SIZE);
51328 +}
51329 +
51330 +char *
51331 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51332 +{
51333 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51334 + PAGE_SIZE);
51335 +}
51336 +
51337 +char *
51338 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51339 +{
51340 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51341 + PAGE_SIZE);
51342 +}
51343 +
51344 +__inline__ __u32
51345 +to_gr_audit(const __u32 reqmode)
51346 +{
51347 + /* masks off auditable permission flags, then shifts them to create
51348 + auditing flags, and adds the special case of append auditing if
51349 + we're requesting write */
51350 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51351 +}
51352 +
51353 +struct acl_subject_label *
51354 +lookup_subject_map(const struct acl_subject_label *userp)
51355 +{
51356 + unsigned int index = shash(userp, subj_map_set.s_size);
51357 + struct subject_map *match;
51358 +
51359 + match = subj_map_set.s_hash[index];
51360 +
51361 + while (match && match->user != userp)
51362 + match = match->next;
51363 +
51364 + if (match != NULL)
51365 + return match->kernel;
51366 + else
51367 + return NULL;
51368 +}
51369 +
51370 +static void
51371 +insert_subj_map_entry(struct subject_map *subjmap)
51372 +{
51373 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51374 + struct subject_map **curr;
51375 +
51376 + subjmap->prev = NULL;
51377 +
51378 + curr = &subj_map_set.s_hash[index];
51379 + if (*curr != NULL)
51380 + (*curr)->prev = subjmap;
51381 +
51382 + subjmap->next = *curr;
51383 + *curr = subjmap;
51384 +
51385 + return;
51386 +}
51387 +
51388 +static struct acl_role_label *
51389 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51390 + const gid_t gid)
51391 +{
51392 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51393 + struct acl_role_label *match;
51394 + struct role_allowed_ip *ipp;
51395 + unsigned int x;
51396 + u32 curr_ip = task->signal->curr_ip;
51397 +
51398 + task->signal->saved_ip = curr_ip;
51399 +
51400 + match = acl_role_set.r_hash[index];
51401 +
51402 + while (match) {
51403 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51404 + for (x = 0; x < match->domain_child_num; x++) {
51405 + if (match->domain_children[x] == uid)
51406 + goto found;
51407 + }
51408 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51409 + break;
51410 + match = match->next;
51411 + }
51412 +found:
51413 + if (match == NULL) {
51414 + try_group:
51415 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51416 + match = acl_role_set.r_hash[index];
51417 +
51418 + while (match) {
51419 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51420 + for (x = 0; x < match->domain_child_num; x++) {
51421 + if (match->domain_children[x] == gid)
51422 + goto found2;
51423 + }
51424 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51425 + break;
51426 + match = match->next;
51427 + }
51428 +found2:
51429 + if (match == NULL)
51430 + match = default_role;
51431 + if (match->allowed_ips == NULL)
51432 + return match;
51433 + else {
51434 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51435 + if (likely
51436 + ((ntohl(curr_ip) & ipp->netmask) ==
51437 + (ntohl(ipp->addr) & ipp->netmask)))
51438 + return match;
51439 + }
51440 + match = default_role;
51441 + }
51442 + } else if (match->allowed_ips == NULL) {
51443 + return match;
51444 + } else {
51445 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51446 + if (likely
51447 + ((ntohl(curr_ip) & ipp->netmask) ==
51448 + (ntohl(ipp->addr) & ipp->netmask)))
51449 + return match;
51450 + }
51451 + goto try_group;
51452 + }
51453 +
51454 + return match;
51455 +}
51456 +
51457 +struct acl_subject_label *
51458 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51459 + const struct acl_role_label *role)
51460 +{
51461 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51462 + struct acl_subject_label *match;
51463 +
51464 + match = role->subj_hash[index];
51465 +
51466 + while (match && (match->inode != ino || match->device != dev ||
51467 + (match->mode & GR_DELETED))) {
51468 + match = match->next;
51469 + }
51470 +
51471 + if (match && !(match->mode & GR_DELETED))
51472 + return match;
51473 + else
51474 + return NULL;
51475 +}
51476 +
51477 +struct acl_subject_label *
51478 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51479 + const struct acl_role_label *role)
51480 +{
51481 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51482 + struct acl_subject_label *match;
51483 +
51484 + match = role->subj_hash[index];
51485 +
51486 + while (match && (match->inode != ino || match->device != dev ||
51487 + !(match->mode & GR_DELETED))) {
51488 + match = match->next;
51489 + }
51490 +
51491 + if (match && (match->mode & GR_DELETED))
51492 + return match;
51493 + else
51494 + return NULL;
51495 +}
51496 +
51497 +static struct acl_object_label *
51498 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51499 + const struct acl_subject_label *subj)
51500 +{
51501 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51502 + struct acl_object_label *match;
51503 +
51504 + match = subj->obj_hash[index];
51505 +
51506 + while (match && (match->inode != ino || match->device != dev ||
51507 + (match->mode & GR_DELETED))) {
51508 + match = match->next;
51509 + }
51510 +
51511 + if (match && !(match->mode & GR_DELETED))
51512 + return match;
51513 + else
51514 + return NULL;
51515 +}
51516 +
51517 +static struct acl_object_label *
51518 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51519 + const struct acl_subject_label *subj)
51520 +{
51521 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51522 + struct acl_object_label *match;
51523 +
51524 + match = subj->obj_hash[index];
51525 +
51526 + while (match && (match->inode != ino || match->device != dev ||
51527 + !(match->mode & GR_DELETED))) {
51528 + match = match->next;
51529 + }
51530 +
51531 + if (match && (match->mode & GR_DELETED))
51532 + return match;
51533 +
51534 + match = subj->obj_hash[index];
51535 +
51536 + while (match && (match->inode != ino || match->device != dev ||
51537 + (match->mode & GR_DELETED))) {
51538 + match = match->next;
51539 + }
51540 +
51541 + if (match && !(match->mode & GR_DELETED))
51542 + return match;
51543 + else
51544 + return NULL;
51545 +}
51546 +
51547 +static struct name_entry *
51548 +lookup_name_entry(const char *name)
51549 +{
51550 + unsigned int len = strlen(name);
51551 + unsigned int key = full_name_hash(name, len);
51552 + unsigned int index = key % name_set.n_size;
51553 + struct name_entry *match;
51554 +
51555 + match = name_set.n_hash[index];
51556 +
51557 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51558 + match = match->next;
51559 +
51560 + return match;
51561 +}
51562 +
51563 +static struct name_entry *
51564 +lookup_name_entry_create(const char *name)
51565 +{
51566 + unsigned int len = strlen(name);
51567 + unsigned int key = full_name_hash(name, len);
51568 + unsigned int index = key % name_set.n_size;
51569 + struct name_entry *match;
51570 +
51571 + match = name_set.n_hash[index];
51572 +
51573 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51574 + !match->deleted))
51575 + match = match->next;
51576 +
51577 + if (match && match->deleted)
51578 + return match;
51579 +
51580 + match = name_set.n_hash[index];
51581 +
51582 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51583 + match->deleted))
51584 + match = match->next;
51585 +
51586 + if (match && !match->deleted)
51587 + return match;
51588 + else
51589 + return NULL;
51590 +}
51591 +
51592 +static struct inodev_entry *
51593 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51594 +{
51595 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51596 + struct inodev_entry *match;
51597 +
51598 + match = inodev_set.i_hash[index];
51599 +
51600 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51601 + match = match->next;
51602 +
51603 + return match;
51604 +}
51605 +
51606 +static void
51607 +insert_inodev_entry(struct inodev_entry *entry)
51608 +{
51609 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51610 + inodev_set.i_size);
51611 + struct inodev_entry **curr;
51612 +
51613 + entry->prev = NULL;
51614 +
51615 + curr = &inodev_set.i_hash[index];
51616 + if (*curr != NULL)
51617 + (*curr)->prev = entry;
51618 +
51619 + entry->next = *curr;
51620 + *curr = entry;
51621 +
51622 + return;
51623 +}
51624 +
51625 +static void
51626 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51627 +{
51628 + unsigned int index =
51629 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51630 + struct acl_role_label **curr;
51631 + struct acl_role_label *tmp, *tmp2;
51632 +
51633 + curr = &acl_role_set.r_hash[index];
51634 +
51635 + /* simple case, slot is empty, just set it to our role */
51636 + if (*curr == NULL) {
51637 + *curr = role;
51638 + } else {
51639 + /* example:
51640 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
51641 + 2 -> 3
51642 + */
51643 + /* first check to see if we can already be reached via this slot */
51644 + tmp = *curr;
51645 + while (tmp && tmp != role)
51646 + tmp = tmp->next;
51647 + if (tmp == role) {
51648 + /* we don't need to add ourselves to this slot's chain */
51649 + return;
51650 + }
51651 + /* we need to add ourselves to this chain, two cases */
51652 + if (role->next == NULL) {
51653 + /* simple case, append the current chain to our role */
51654 + role->next = *curr;
51655 + *curr = role;
51656 + } else {
51657 + /* 1 -> 2 -> 3 -> 4
51658 + 2 -> 3 -> 4
51659 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51660 + */
51661 + /* trickier case: walk our role's chain until we find
51662 + the role for the start of the current slot's chain */
51663 + tmp = role;
51664 + tmp2 = *curr;
51665 + while (tmp->next && tmp->next != tmp2)
51666 + tmp = tmp->next;
51667 + if (tmp->next == tmp2) {
51668 + /* from example above, we found 3, so just
51669 + replace this slot's chain with ours */
51670 + *curr = role;
51671 + } else {
51672 + /* we didn't find a subset of our role's chain
51673 + in the current slot's chain, so append their
51674 + chain to ours, and set us as the first role in
51675 + the slot's chain
51676 +
51677 + we could fold this case with the case above,
51678 + but making it explicit for clarity
51679 + */
51680 + tmp->next = tmp2;
51681 + *curr = role;
51682 + }
51683 + }
51684 + }
51685 +
51686 + return;
51687 +}
51688 +
51689 +static void
51690 +insert_acl_role_label(struct acl_role_label *role)
51691 +{
51692 + int i;
51693 +
51694 + if (role_list == NULL) {
51695 + role_list = role;
51696 + role->prev = NULL;
51697 + } else {
51698 + role->prev = role_list;
51699 + role_list = role;
51700 + }
51701 +
51702 + /* used for hash chains */
51703 + role->next = NULL;
51704 +
51705 + if (role->roletype & GR_ROLE_DOMAIN) {
51706 + for (i = 0; i < role->domain_child_num; i++)
51707 + __insert_acl_role_label(role, role->domain_children[i]);
51708 + } else
51709 + __insert_acl_role_label(role, role->uidgid);
51710 +}
51711 +
51712 +static int
51713 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51714 +{
51715 + struct name_entry **curr, *nentry;
51716 + struct inodev_entry *ientry;
51717 + unsigned int len = strlen(name);
51718 + unsigned int key = full_name_hash(name, len);
51719 + unsigned int index = key % name_set.n_size;
51720 +
51721 + curr = &name_set.n_hash[index];
51722 +
51723 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51724 + curr = &((*curr)->next);
51725 +
51726 + if (*curr != NULL)
51727 + return 1;
51728 +
51729 + nentry = acl_alloc(sizeof (struct name_entry));
51730 + if (nentry == NULL)
51731 + return 0;
51732 + ientry = acl_alloc(sizeof (struct inodev_entry));
51733 + if (ientry == NULL)
51734 + return 0;
51735 + ientry->nentry = nentry;
51736 +
51737 + nentry->key = key;
51738 + nentry->name = name;
51739 + nentry->inode = inode;
51740 + nentry->device = device;
51741 + nentry->len = len;
51742 + nentry->deleted = deleted;
51743 +
51744 + nentry->prev = NULL;
51745 + curr = &name_set.n_hash[index];
51746 + if (*curr != NULL)
51747 + (*curr)->prev = nentry;
51748 + nentry->next = *curr;
51749 + *curr = nentry;
51750 +
51751 + /* insert us into the table searchable by inode/dev */
51752 + insert_inodev_entry(ientry);
51753 +
51754 + return 1;
51755 +}
51756 +
51757 +static void
51758 +insert_acl_obj_label(struct acl_object_label *obj,
51759 + struct acl_subject_label *subj)
51760 +{
51761 + unsigned int index =
51762 + fhash(obj->inode, obj->device, subj->obj_hash_size);
51763 + struct acl_object_label **curr;
51764 +
51765 +
51766 + obj->prev = NULL;
51767 +
51768 + curr = &subj->obj_hash[index];
51769 + if (*curr != NULL)
51770 + (*curr)->prev = obj;
51771 +
51772 + obj->next = *curr;
51773 + *curr = obj;
51774 +
51775 + return;
51776 +}
51777 +
51778 +static void
51779 +insert_acl_subj_label(struct acl_subject_label *obj,
51780 + struct acl_role_label *role)
51781 +{
51782 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51783 + struct acl_subject_label **curr;
51784 +
51785 + obj->prev = NULL;
51786 +
51787 + curr = &role->subj_hash[index];
51788 + if (*curr != NULL)
51789 + (*curr)->prev = obj;
51790 +
51791 + obj->next = *curr;
51792 + *curr = obj;
51793 +
51794 + return;
51795 +}
51796 +
51797 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51798 +
51799 +static void *
51800 +create_table(__u32 * len, int elementsize)
51801 +{
51802 + unsigned int table_sizes[] = {
51803 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51804 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51805 + 4194301, 8388593, 16777213, 33554393, 67108859
51806 + };
51807 + void *newtable = NULL;
51808 + unsigned int pwr = 0;
51809 +
51810 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51811 + table_sizes[pwr] <= *len)
51812 + pwr++;
51813 +
51814 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51815 + return newtable;
51816 +
51817 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51818 + newtable =
51819 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51820 + else
51821 + newtable = vmalloc(table_sizes[pwr] * elementsize);
51822 +
51823 + *len = table_sizes[pwr];
51824 +
51825 + return newtable;
51826 +}
51827 +
51828 +static int
51829 +init_variables(const struct gr_arg *arg)
51830 +{
51831 + struct task_struct *reaper = &init_task;
51832 + unsigned int stacksize;
51833 +
51834 + subj_map_set.s_size = arg->role_db.num_subjects;
51835 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51836 + name_set.n_size = arg->role_db.num_objects;
51837 + inodev_set.i_size = arg->role_db.num_objects;
51838 +
51839 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
51840 + !name_set.n_size || !inodev_set.i_size)
51841 + return 1;
51842 +
51843 + if (!gr_init_uidset())
51844 + return 1;
51845 +
51846 + /* set up the stack that holds allocation info */
51847 +
51848 + stacksize = arg->role_db.num_pointers + 5;
51849 +
51850 + if (!acl_alloc_stack_init(stacksize))
51851 + return 1;
51852 +
51853 + /* grab reference for the real root dentry and vfsmount */
51854 + get_fs_root(reaper->fs, &real_root);
51855 +
51856 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51857 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51858 +#endif
51859 +
51860 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51861 + if (fakefs_obj_rw == NULL)
51862 + return 1;
51863 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51864 +
51865 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51866 + if (fakefs_obj_rwx == NULL)
51867 + return 1;
51868 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51869 +
51870 + subj_map_set.s_hash =
51871 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51872 + acl_role_set.r_hash =
51873 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51874 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51875 + inodev_set.i_hash =
51876 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51877 +
51878 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51879 + !name_set.n_hash || !inodev_set.i_hash)
51880 + return 1;
51881 +
51882 + memset(subj_map_set.s_hash, 0,
51883 + sizeof(struct subject_map *) * subj_map_set.s_size);
51884 + memset(acl_role_set.r_hash, 0,
51885 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51886 + memset(name_set.n_hash, 0,
51887 + sizeof (struct name_entry *) * name_set.n_size);
51888 + memset(inodev_set.i_hash, 0,
51889 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51890 +
51891 + return 0;
51892 +}
51893 +
51894 +/* free information not needed after startup
51895 + currently contains user->kernel pointer mappings for subjects
51896 +*/
51897 +
51898 +static void
51899 +free_init_variables(void)
51900 +{
51901 + __u32 i;
51902 +
51903 + if (subj_map_set.s_hash) {
51904 + for (i = 0; i < subj_map_set.s_size; i++) {
51905 + if (subj_map_set.s_hash[i]) {
51906 + kfree(subj_map_set.s_hash[i]);
51907 + subj_map_set.s_hash[i] = NULL;
51908 + }
51909 + }
51910 +
51911 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51912 + PAGE_SIZE)
51913 + kfree(subj_map_set.s_hash);
51914 + else
51915 + vfree(subj_map_set.s_hash);
51916 + }
51917 +
51918 + return;
51919 +}
51920 +
51921 +static void
51922 +free_variables(void)
51923 +{
51924 + struct acl_subject_label *s;
51925 + struct acl_role_label *r;
51926 + struct task_struct *task, *task2;
51927 + unsigned int x;
51928 +
51929 + gr_clear_learn_entries();
51930 +
51931 + read_lock(&tasklist_lock);
51932 + do_each_thread(task2, task) {
51933 + task->acl_sp_role = 0;
51934 + task->acl_role_id = 0;
51935 + task->acl = NULL;
51936 + task->role = NULL;
51937 + } while_each_thread(task2, task);
51938 + read_unlock(&tasklist_lock);
51939 +
51940 + /* release the reference to the real root dentry and vfsmount */
51941 + path_put(&real_root);
51942 + memset(&real_root, 0, sizeof(real_root));
51943 +
51944 + /* free all object hash tables */
51945 +
51946 + FOR_EACH_ROLE_START(r)
51947 + if (r->subj_hash == NULL)
51948 + goto next_role;
51949 + FOR_EACH_SUBJECT_START(r, s, x)
51950 + if (s->obj_hash == NULL)
51951 + break;
51952 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51953 + kfree(s->obj_hash);
51954 + else
51955 + vfree(s->obj_hash);
51956 + FOR_EACH_SUBJECT_END(s, x)
51957 + FOR_EACH_NESTED_SUBJECT_START(r, s)
51958 + if (s->obj_hash == NULL)
51959 + break;
51960 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51961 + kfree(s->obj_hash);
51962 + else
51963 + vfree(s->obj_hash);
51964 + FOR_EACH_NESTED_SUBJECT_END(s)
51965 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51966 + kfree(r->subj_hash);
51967 + else
51968 + vfree(r->subj_hash);
51969 + r->subj_hash = NULL;
51970 +next_role:
51971 + FOR_EACH_ROLE_END(r)
51972 +
51973 + acl_free_all();
51974 +
51975 + if (acl_role_set.r_hash) {
51976 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51977 + PAGE_SIZE)
51978 + kfree(acl_role_set.r_hash);
51979 + else
51980 + vfree(acl_role_set.r_hash);
51981 + }
51982 + if (name_set.n_hash) {
51983 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
51984 + PAGE_SIZE)
51985 + kfree(name_set.n_hash);
51986 + else
51987 + vfree(name_set.n_hash);
51988 + }
51989 +
51990 + if (inodev_set.i_hash) {
51991 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51992 + PAGE_SIZE)
51993 + kfree(inodev_set.i_hash);
51994 + else
51995 + vfree(inodev_set.i_hash);
51996 + }
51997 +
51998 + gr_free_uidset();
51999 +
52000 + memset(&name_set, 0, sizeof (struct name_db));
52001 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52002 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52003 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52004 +
52005 + default_role = NULL;
52006 + kernel_role = NULL;
52007 + role_list = NULL;
52008 +
52009 + return;
52010 +}
52011 +
52012 +static __u32
52013 +count_user_objs(struct acl_object_label *userp)
52014 +{
52015 + struct acl_object_label o_tmp;
52016 + __u32 num = 0;
52017 +
52018 + while (userp) {
52019 + if (copy_from_user(&o_tmp, userp,
52020 + sizeof (struct acl_object_label)))
52021 + break;
52022 +
52023 + userp = o_tmp.prev;
52024 + num++;
52025 + }
52026 +
52027 + return num;
52028 +}
52029 +
52030 +static struct acl_subject_label *
52031 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52032 +
52033 +static int
52034 +copy_user_glob(struct acl_object_label *obj)
52035 +{
52036 + struct acl_object_label *g_tmp, **guser;
52037 + unsigned int len;
52038 + char *tmp;
52039 +
52040 + if (obj->globbed == NULL)
52041 + return 0;
52042 +
52043 + guser = &obj->globbed;
52044 + while (*guser) {
52045 + g_tmp = (struct acl_object_label *)
52046 + acl_alloc(sizeof (struct acl_object_label));
52047 + if (g_tmp == NULL)
52048 + return -ENOMEM;
52049 +
52050 + if (copy_from_user(g_tmp, *guser,
52051 + sizeof (struct acl_object_label)))
52052 + return -EFAULT;
52053 +
52054 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52055 +
52056 + if (!len || len >= PATH_MAX)
52057 + return -EINVAL;
52058 +
52059 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52060 + return -ENOMEM;
52061 +
52062 + if (copy_from_user(tmp, g_tmp->filename, len))
52063 + return -EFAULT;
52064 + tmp[len-1] = '\0';
52065 + g_tmp->filename = tmp;
52066 +
52067 + *guser = g_tmp;
52068 + guser = &(g_tmp->next);
52069 + }
52070 +
52071 + return 0;
52072 +}
52073 +
52074 +static int
52075 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52076 + struct acl_role_label *role)
52077 +{
52078 + struct acl_object_label *o_tmp;
52079 + unsigned int len;
52080 + int ret;
52081 + char *tmp;
52082 +
52083 + while (userp) {
52084 + if ((o_tmp = (struct acl_object_label *)
52085 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52086 + return -ENOMEM;
52087 +
52088 + if (copy_from_user(o_tmp, userp,
52089 + sizeof (struct acl_object_label)))
52090 + return -EFAULT;
52091 +
52092 + userp = o_tmp->prev;
52093 +
52094 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52095 +
52096 + if (!len || len >= PATH_MAX)
52097 + return -EINVAL;
52098 +
52099 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52100 + return -ENOMEM;
52101 +
52102 + if (copy_from_user(tmp, o_tmp->filename, len))
52103 + return -EFAULT;
52104 + tmp[len-1] = '\0';
52105 + o_tmp->filename = tmp;
52106 +
52107 + insert_acl_obj_label(o_tmp, subj);
52108 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52109 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52110 + return -ENOMEM;
52111 +
52112 + ret = copy_user_glob(o_tmp);
52113 + if (ret)
52114 + return ret;
52115 +
52116 + if (o_tmp->nested) {
52117 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52118 + if (IS_ERR(o_tmp->nested))
52119 + return PTR_ERR(o_tmp->nested);
52120 +
52121 + /* insert into nested subject list */
52122 + o_tmp->nested->next = role->hash->first;
52123 + role->hash->first = o_tmp->nested;
52124 + }
52125 + }
52126 +
52127 + return 0;
52128 +}
52129 +
52130 +static __u32
52131 +count_user_subjs(struct acl_subject_label *userp)
52132 +{
52133 + struct acl_subject_label s_tmp;
52134 + __u32 num = 0;
52135 +
52136 + while (userp) {
52137 + if (copy_from_user(&s_tmp, userp,
52138 + sizeof (struct acl_subject_label)))
52139 + break;
52140 +
52141 + userp = s_tmp.prev;
52142 + /* do not count nested subjects against this count, since
52143 + they are not included in the hash table, but are
52144 + attached to objects. We have already counted
52145 + the subjects in userspace for the allocation
52146 + stack
52147 + */
52148 + if (!(s_tmp.mode & GR_NESTED))
52149 + num++;
52150 + }
52151 +
52152 + return num;
52153 +}
52154 +
52155 +static int
52156 +copy_user_allowedips(struct acl_role_label *rolep)
52157 +{
52158 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52159 +
52160 + ruserip = rolep->allowed_ips;
52161 +
52162 + while (ruserip) {
52163 + rlast = rtmp;
52164 +
52165 + if ((rtmp = (struct role_allowed_ip *)
52166 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52167 + return -ENOMEM;
52168 +
52169 + if (copy_from_user(rtmp, ruserip,
52170 + sizeof (struct role_allowed_ip)))
52171 + return -EFAULT;
52172 +
52173 + ruserip = rtmp->prev;
52174 +
52175 + if (!rlast) {
52176 + rtmp->prev = NULL;
52177 + rolep->allowed_ips = rtmp;
52178 + } else {
52179 + rlast->next = rtmp;
52180 + rtmp->prev = rlast;
52181 + }
52182 +
52183 + if (!ruserip)
52184 + rtmp->next = NULL;
52185 + }
52186 +
52187 + return 0;
52188 +}
52189 +
52190 +static int
52191 +copy_user_transitions(struct acl_role_label *rolep)
52192 +{
52193 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52194 +
52195 + unsigned int len;
52196 + char *tmp;
52197 +
52198 + rusertp = rolep->transitions;
52199 +
52200 + while (rusertp) {
52201 + rlast = rtmp;
52202 +
52203 + if ((rtmp = (struct role_transition *)
52204 + acl_alloc(sizeof (struct role_transition))) == NULL)
52205 + return -ENOMEM;
52206 +
52207 + if (copy_from_user(rtmp, rusertp,
52208 + sizeof (struct role_transition)))
52209 + return -EFAULT;
52210 +
52211 + rusertp = rtmp->prev;
52212 +
52213 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52214 +
52215 + if (!len || len >= GR_SPROLE_LEN)
52216 + return -EINVAL;
52217 +
52218 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52219 + return -ENOMEM;
52220 +
52221 + if (copy_from_user(tmp, rtmp->rolename, len))
52222 + return -EFAULT;
52223 + tmp[len-1] = '\0';
52224 + rtmp->rolename = tmp;
52225 +
52226 + if (!rlast) {
52227 + rtmp->prev = NULL;
52228 + rolep->transitions = rtmp;
52229 + } else {
52230 + rlast->next = rtmp;
52231 + rtmp->prev = rlast;
52232 + }
52233 +
52234 + if (!rusertp)
52235 + rtmp->next = NULL;
52236 + }
52237 +
52238 + return 0;
52239 +}
52240 +
52241 +static struct acl_subject_label *
52242 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52243 +{
52244 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52245 + unsigned int len;
52246 + char *tmp;
52247 + __u32 num_objs;
52248 + struct acl_ip_label **i_tmp, *i_utmp2;
52249 + struct gr_hash_struct ghash;
52250 + struct subject_map *subjmap;
52251 + unsigned int i_num;
52252 + int err;
52253 +
52254 + s_tmp = lookup_subject_map(userp);
52255 +
52256 + /* we've already copied this subject into the kernel, just return
52257 + the reference to it, and don't copy it over again
52258 + */
52259 + if (s_tmp)
52260 + return(s_tmp);
52261 +
52262 + if ((s_tmp = (struct acl_subject_label *)
52263 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52264 + return ERR_PTR(-ENOMEM);
52265 +
52266 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52267 + if (subjmap == NULL)
52268 + return ERR_PTR(-ENOMEM);
52269 +
52270 + subjmap->user = userp;
52271 + subjmap->kernel = s_tmp;
52272 + insert_subj_map_entry(subjmap);
52273 +
52274 + if (copy_from_user(s_tmp, userp,
52275 + sizeof (struct acl_subject_label)))
52276 + return ERR_PTR(-EFAULT);
52277 +
52278 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52279 +
52280 + if (!len || len >= PATH_MAX)
52281 + return ERR_PTR(-EINVAL);
52282 +
52283 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52284 + return ERR_PTR(-ENOMEM);
52285 +
52286 + if (copy_from_user(tmp, s_tmp->filename, len))
52287 + return ERR_PTR(-EFAULT);
52288 + tmp[len-1] = '\0';
52289 + s_tmp->filename = tmp;
52290 +
52291 + if (!strcmp(s_tmp->filename, "/"))
52292 + role->root_label = s_tmp;
52293 +
52294 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52295 + return ERR_PTR(-EFAULT);
52296 +
52297 + /* copy user and group transition tables */
52298 +
52299 + if (s_tmp->user_trans_num) {
52300 + uid_t *uidlist;
52301 +
52302 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52303 + if (uidlist == NULL)
52304 + return ERR_PTR(-ENOMEM);
52305 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52306 + return ERR_PTR(-EFAULT);
52307 +
52308 + s_tmp->user_transitions = uidlist;
52309 + }
52310 +
52311 + if (s_tmp->group_trans_num) {
52312 + gid_t *gidlist;
52313 +
52314 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52315 + if (gidlist == NULL)
52316 + return ERR_PTR(-ENOMEM);
52317 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52318 + return ERR_PTR(-EFAULT);
52319 +
52320 + s_tmp->group_transitions = gidlist;
52321 + }
52322 +
52323 + /* set up object hash table */
52324 + num_objs = count_user_objs(ghash.first);
52325 +
52326 + s_tmp->obj_hash_size = num_objs;
52327 + s_tmp->obj_hash =
52328 + (struct acl_object_label **)
52329 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52330 +
52331 + if (!s_tmp->obj_hash)
52332 + return ERR_PTR(-ENOMEM);
52333 +
52334 + memset(s_tmp->obj_hash, 0,
52335 + s_tmp->obj_hash_size *
52336 + sizeof (struct acl_object_label *));
52337 +
52338 + /* add in objects */
52339 + err = copy_user_objs(ghash.first, s_tmp, role);
52340 +
52341 + if (err)
52342 + return ERR_PTR(err);
52343 +
52344 + /* set pointer for parent subject */
52345 + if (s_tmp->parent_subject) {
52346 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52347 +
52348 + if (IS_ERR(s_tmp2))
52349 + return s_tmp2;
52350 +
52351 + s_tmp->parent_subject = s_tmp2;
52352 + }
52353 +
52354 + /* add in ip acls */
52355 +
52356 + if (!s_tmp->ip_num) {
52357 + s_tmp->ips = NULL;
52358 + goto insert;
52359 + }
52360 +
52361 + i_tmp =
52362 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52363 + sizeof (struct acl_ip_label *));
52364 +
52365 + if (!i_tmp)
52366 + return ERR_PTR(-ENOMEM);
52367 +
52368 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52369 + *(i_tmp + i_num) =
52370 + (struct acl_ip_label *)
52371 + acl_alloc(sizeof (struct acl_ip_label));
52372 + if (!*(i_tmp + i_num))
52373 + return ERR_PTR(-ENOMEM);
52374 +
52375 + if (copy_from_user
52376 + (&i_utmp2, s_tmp->ips + i_num,
52377 + sizeof (struct acl_ip_label *)))
52378 + return ERR_PTR(-EFAULT);
52379 +
52380 + if (copy_from_user
52381 + (*(i_tmp + i_num), i_utmp2,
52382 + sizeof (struct acl_ip_label)))
52383 + return ERR_PTR(-EFAULT);
52384 +
52385 + if ((*(i_tmp + i_num))->iface == NULL)
52386 + continue;
52387 +
52388 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52389 + if (!len || len >= IFNAMSIZ)
52390 + return ERR_PTR(-EINVAL);
52391 + tmp = acl_alloc(len);
52392 + if (tmp == NULL)
52393 + return ERR_PTR(-ENOMEM);
52394 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52395 + return ERR_PTR(-EFAULT);
52396 + (*(i_tmp + i_num))->iface = tmp;
52397 + }
52398 +
52399 + s_tmp->ips = i_tmp;
52400 +
52401 +insert:
52402 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52403 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52404 + return ERR_PTR(-ENOMEM);
52405 +
52406 + return s_tmp;
52407 +}
52408 +
52409 +static int
52410 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52411 +{
52412 + struct acl_subject_label s_pre;
52413 + struct acl_subject_label * ret;
52414 + int err;
52415 +
52416 + while (userp) {
52417 + if (copy_from_user(&s_pre, userp,
52418 + sizeof (struct acl_subject_label)))
52419 + return -EFAULT;
52420 +
52421 + /* do not add nested subjects here, add
52422 + while parsing objects
52423 + */
52424 +
52425 + if (s_pre.mode & GR_NESTED) {
52426 + userp = s_pre.prev;
52427 + continue;
52428 + }
52429 +
52430 + ret = do_copy_user_subj(userp, role);
52431 +
52432 + err = PTR_ERR(ret);
52433 + if (IS_ERR(ret))
52434 + return err;
52435 +
52436 + insert_acl_subj_label(ret, role);
52437 +
52438 + userp = s_pre.prev;
52439 + }
52440 +
52441 + return 0;
52442 +}
52443 +
52444 +static int
52445 +copy_user_acl(struct gr_arg *arg)
52446 +{
52447 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52448 + struct sprole_pw *sptmp;
52449 + struct gr_hash_struct *ghash;
52450 + uid_t *domainlist;
52451 + unsigned int r_num;
52452 + unsigned int len;
52453 + char *tmp;
52454 + int err = 0;
52455 + __u16 i;
52456 + __u32 num_subjs;
52457 +
52458 + /* we need a default and kernel role */
52459 + if (arg->role_db.num_roles < 2)
52460 + return -EINVAL;
52461 +
52462 + /* copy special role authentication info from userspace */
52463 +
52464 + num_sprole_pws = arg->num_sprole_pws;
52465 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52466 +
52467 + if (!acl_special_roles && num_sprole_pws)
52468 + return -ENOMEM;
52469 +
52470 + for (i = 0; i < num_sprole_pws; i++) {
52471 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52472 + if (!sptmp)
52473 + return -ENOMEM;
52474 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52475 + sizeof (struct sprole_pw)))
52476 + return -EFAULT;
52477 +
52478 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52479 +
52480 + if (!len || len >= GR_SPROLE_LEN)
52481 + return -EINVAL;
52482 +
52483 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52484 + return -ENOMEM;
52485 +
52486 + if (copy_from_user(tmp, sptmp->rolename, len))
52487 + return -EFAULT;
52488 +
52489 + tmp[len-1] = '\0';
52490 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52491 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52492 +#endif
52493 + sptmp->rolename = tmp;
52494 + acl_special_roles[i] = sptmp;
52495 + }
52496 +
52497 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52498 +
52499 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52500 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52501 +
52502 + if (!r_tmp)
52503 + return -ENOMEM;
52504 +
52505 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52506 + sizeof (struct acl_role_label *)))
52507 + return -EFAULT;
52508 +
52509 + if (copy_from_user(r_tmp, r_utmp2,
52510 + sizeof (struct acl_role_label)))
52511 + return -EFAULT;
52512 +
52513 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52514 +
52515 + if (!len || len >= PATH_MAX)
52516 + return -EINVAL;
52517 +
52518 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52519 + return -ENOMEM;
52520 +
52521 + if (copy_from_user(tmp, r_tmp->rolename, len))
52522 + return -EFAULT;
52523 +
52524 + tmp[len-1] = '\0';
52525 + r_tmp->rolename = tmp;
52526 +
52527 + if (!strcmp(r_tmp->rolename, "default")
52528 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52529 + default_role = r_tmp;
52530 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52531 + kernel_role = r_tmp;
52532 + }
52533 +
52534 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52535 + return -ENOMEM;
52536 +
52537 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52538 + return -EFAULT;
52539 +
52540 + r_tmp->hash = ghash;
52541 +
52542 + num_subjs = count_user_subjs(r_tmp->hash->first);
52543 +
52544 + r_tmp->subj_hash_size = num_subjs;
52545 + r_tmp->subj_hash =
52546 + (struct acl_subject_label **)
52547 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52548 +
52549 + if (!r_tmp->subj_hash)
52550 + return -ENOMEM;
52551 +
52552 + err = copy_user_allowedips(r_tmp);
52553 + if (err)
52554 + return err;
52555 +
52556 + /* copy domain info */
52557 + if (r_tmp->domain_children != NULL) {
52558 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52559 + if (domainlist == NULL)
52560 + return -ENOMEM;
52561 +
52562 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52563 + return -EFAULT;
52564 +
52565 + r_tmp->domain_children = domainlist;
52566 + }
52567 +
52568 + err = copy_user_transitions(r_tmp);
52569 + if (err)
52570 + return err;
52571 +
52572 + memset(r_tmp->subj_hash, 0,
52573 + r_tmp->subj_hash_size *
52574 + sizeof (struct acl_subject_label *));
52575 +
52576 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52577 +
52578 + if (err)
52579 + return err;
52580 +
52581 + /* set nested subject list to null */
52582 + r_tmp->hash->first = NULL;
52583 +
52584 + insert_acl_role_label(r_tmp);
52585 + }
52586 +
52587 + if (default_role == NULL || kernel_role == NULL)
52588 + return -EINVAL;
52589 +
52590 + return err;
52591 +}
52592 +
52593 +static int
52594 +gracl_init(struct gr_arg *args)
52595 +{
52596 + int error = 0;
52597 +
52598 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52599 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52600 +
52601 + if (init_variables(args)) {
52602 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52603 + error = -ENOMEM;
52604 + free_variables();
52605 + goto out;
52606 + }
52607 +
52608 + error = copy_user_acl(args);
52609 + free_init_variables();
52610 + if (error) {
52611 + free_variables();
52612 + goto out;
52613 + }
52614 +
52615 + if ((error = gr_set_acls(0))) {
52616 + free_variables();
52617 + goto out;
52618 + }
52619 +
52620 + pax_open_kernel();
52621 + gr_status |= GR_READY;
52622 + pax_close_kernel();
52623 +
52624 + out:
52625 + return error;
52626 +}
52627 +
52628 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52629 +
52630 +static int
52631 +glob_match(const char *p, const char *n)
52632 +{
52633 + char c;
52634 +
52635 + while ((c = *p++) != '\0') {
52636 + switch (c) {
52637 + case '?':
52638 + if (*n == '\0')
52639 + return 1;
52640 + else if (*n == '/')
52641 + return 1;
52642 + break;
52643 + case '\\':
52644 + if (*n != c)
52645 + return 1;
52646 + break;
52647 + case '*':
52648 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52649 + if (*n == '/')
52650 + return 1;
52651 + else if (c == '?') {
52652 + if (*n == '\0')
52653 + return 1;
52654 + else
52655 + ++n;
52656 + }
52657 + }
52658 + if (c == '\0') {
52659 + return 0;
52660 + } else {
52661 + const char *endp;
52662 +
52663 + if ((endp = strchr(n, '/')) == NULL)
52664 + endp = n + strlen(n);
52665 +
52666 + if (c == '[') {
52667 + for (--p; n < endp; ++n)
52668 + if (!glob_match(p, n))
52669 + return 0;
52670 + } else if (c == '/') {
52671 + while (*n != '\0' && *n != '/')
52672 + ++n;
52673 + if (*n == '/' && !glob_match(p, n + 1))
52674 + return 0;
52675 + } else {
52676 + for (--p; n < endp; ++n)
52677 + if (*n == c && !glob_match(p, n))
52678 + return 0;
52679 + }
52680 +
52681 + return 1;
52682 + }
52683 + case '[':
52684 + {
52685 + int not;
52686 + char cold;
52687 +
52688 + if (*n == '\0' || *n == '/')
52689 + return 1;
52690 +
52691 + not = (*p == '!' || *p == '^');
52692 + if (not)
52693 + ++p;
52694 +
52695 + c = *p++;
52696 + for (;;) {
52697 + unsigned char fn = (unsigned char)*n;
52698 +
52699 + if (c == '\0')
52700 + return 1;
52701 + else {
52702 + if (c == fn)
52703 + goto matched;
52704 + cold = c;
52705 + c = *p++;
52706 +
52707 + if (c == '-' && *p != ']') {
52708 + unsigned char cend = *p++;
52709 +
52710 + if (cend == '\0')
52711 + return 1;
52712 +
52713 + if (cold <= fn && fn <= cend)
52714 + goto matched;
52715 +
52716 + c = *p++;
52717 + }
52718 + }
52719 +
52720 + if (c == ']')
52721 + break;
52722 + }
52723 + if (!not)
52724 + return 1;
52725 + break;
52726 + matched:
52727 + while (c != ']') {
52728 + if (c == '\0')
52729 + return 1;
52730 +
52731 + c = *p++;
52732 + }
52733 + if (not)
52734 + return 1;
52735 + }
52736 + break;
52737 + default:
52738 + if (c != *n)
52739 + return 1;
52740 + }
52741 +
52742 + ++n;
52743 + }
52744 +
52745 + if (*n == '\0')
52746 + return 0;
52747 +
52748 + if (*n == '/')
52749 + return 0;
52750 +
52751 + return 1;
52752 +}
52753 +
52754 +static struct acl_object_label *
52755 +chk_glob_label(struct acl_object_label *globbed,
52756 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52757 +{
52758 + struct acl_object_label *tmp;
52759 +
52760 + if (*path == NULL)
52761 + *path = gr_to_filename_nolock(dentry, mnt);
52762 +
52763 + tmp = globbed;
52764 +
52765 + while (tmp) {
52766 + if (!glob_match(tmp->filename, *path))
52767 + return tmp;
52768 + tmp = tmp->next;
52769 + }
52770 +
52771 + return NULL;
52772 +}
52773 +
52774 +static struct acl_object_label *
52775 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52776 + const ino_t curr_ino, const dev_t curr_dev,
52777 + const struct acl_subject_label *subj, char **path, const int checkglob)
52778 +{
52779 + struct acl_subject_label *tmpsubj;
52780 + struct acl_object_label *retval;
52781 + struct acl_object_label *retval2;
52782 +
52783 + tmpsubj = (struct acl_subject_label *) subj;
52784 + read_lock(&gr_inode_lock);
52785 + do {
52786 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52787 + if (retval) {
52788 + if (checkglob && retval->globbed) {
52789 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52790 + if (retval2)
52791 + retval = retval2;
52792 + }
52793 + break;
52794 + }
52795 + } while ((tmpsubj = tmpsubj->parent_subject));
52796 + read_unlock(&gr_inode_lock);
52797 +
52798 + return retval;
52799 +}
52800 +
52801 +static __inline__ struct acl_object_label *
52802 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52803 + struct dentry *curr_dentry,
52804 + const struct acl_subject_label *subj, char **path, const int checkglob)
52805 +{
52806 + int newglob = checkglob;
52807 + ino_t inode;
52808 + dev_t device;
52809 +
52810 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52811 + as we don't want a / * rule to match instead of the / object
52812 + don't do this for create lookups that call this function though, since they're looking up
52813 + on the parent and thus need globbing checks on all paths
52814 + */
52815 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52816 + newglob = GR_NO_GLOB;
52817 +
52818 + spin_lock(&curr_dentry->d_lock);
52819 + inode = curr_dentry->d_inode->i_ino;
52820 + device = __get_dev(curr_dentry);
52821 + spin_unlock(&curr_dentry->d_lock);
52822 +
52823 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52824 +}
52825 +
52826 +static struct acl_object_label *
52827 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52828 + const struct acl_subject_label *subj, char *path, const int checkglob)
52829 +{
52830 + struct dentry *dentry = (struct dentry *) l_dentry;
52831 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52832 + struct mount *real_mnt = real_mount(mnt);
52833 + struct acl_object_label *retval;
52834 + struct dentry *parent;
52835 +
52836 + write_seqlock(&rename_lock);
52837 + br_read_lock(vfsmount_lock);
52838 +
52839 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52840 +#ifdef CONFIG_NET
52841 + mnt == sock_mnt ||
52842 +#endif
52843 +#ifdef CONFIG_HUGETLBFS
52844 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52845 +#endif
52846 + /* ignore Eric Biederman */
52847 + IS_PRIVATE(l_dentry->d_inode))) {
52848 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52849 + goto out;
52850 + }
52851 +
52852 + for (;;) {
52853 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52854 + break;
52855 +
52856 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52857 + if (!mnt_has_parent(real_mnt))
52858 + break;
52859 +
52860 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52861 + if (retval != NULL)
52862 + goto out;
52863 +
52864 + dentry = real_mnt->mnt_mountpoint;
52865 + real_mnt = real_mnt->mnt_parent;
52866 + mnt = &real_mnt->mnt;
52867 + continue;
52868 + }
52869 +
52870 + parent = dentry->d_parent;
52871 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52872 + if (retval != NULL)
52873 + goto out;
52874 +
52875 + dentry = parent;
52876 + }
52877 +
52878 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52879 +
52880 + /* real_root is pinned so we don't have to hold a reference */
52881 + if (retval == NULL)
52882 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52883 +out:
52884 + br_read_unlock(vfsmount_lock);
52885 + write_sequnlock(&rename_lock);
52886 +
52887 + BUG_ON(retval == NULL);
52888 +
52889 + return retval;
52890 +}
52891 +
52892 +static __inline__ struct acl_object_label *
52893 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52894 + const struct acl_subject_label *subj)
52895 +{
52896 + char *path = NULL;
52897 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52898 +}
52899 +
52900 +static __inline__ struct acl_object_label *
52901 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52902 + const struct acl_subject_label *subj)
52903 +{
52904 + char *path = NULL;
52905 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52906 +}
52907 +
52908 +static __inline__ struct acl_object_label *
52909 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52910 + const struct acl_subject_label *subj, char *path)
52911 +{
52912 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52913 +}
52914 +
52915 +static struct acl_subject_label *
52916 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52917 + const struct acl_role_label *role)
52918 +{
52919 + struct dentry *dentry = (struct dentry *) l_dentry;
52920 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52921 + struct mount *real_mnt = real_mount(mnt);
52922 + struct acl_subject_label *retval;
52923 + struct dentry *parent;
52924 +
52925 + write_seqlock(&rename_lock);
52926 + br_read_lock(vfsmount_lock);
52927 +
52928 + for (;;) {
52929 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52930 + break;
52931 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52932 + if (!mnt_has_parent(real_mnt))
52933 + break;
52934 +
52935 + spin_lock(&dentry->d_lock);
52936 + read_lock(&gr_inode_lock);
52937 + retval =
52938 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52939 + __get_dev(dentry), role);
52940 + read_unlock(&gr_inode_lock);
52941 + spin_unlock(&dentry->d_lock);
52942 + if (retval != NULL)
52943 + goto out;
52944 +
52945 + dentry = real_mnt->mnt_mountpoint;
52946 + real_mnt = real_mnt->mnt_parent;
52947 + mnt = &real_mnt->mnt;
52948 + continue;
52949 + }
52950 +
52951 + spin_lock(&dentry->d_lock);
52952 + read_lock(&gr_inode_lock);
52953 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52954 + __get_dev(dentry), role);
52955 + read_unlock(&gr_inode_lock);
52956 + parent = dentry->d_parent;
52957 + spin_unlock(&dentry->d_lock);
52958 +
52959 + if (retval != NULL)
52960 + goto out;
52961 +
52962 + dentry = parent;
52963 + }
52964 +
52965 + spin_lock(&dentry->d_lock);
52966 + read_lock(&gr_inode_lock);
52967 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52968 + __get_dev(dentry), role);
52969 + read_unlock(&gr_inode_lock);
52970 + spin_unlock(&dentry->d_lock);
52971 +
52972 + if (unlikely(retval == NULL)) {
52973 + /* real_root is pinned, we don't need to hold a reference */
52974 + read_lock(&gr_inode_lock);
52975 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52976 + __get_dev(real_root.dentry), role);
52977 + read_unlock(&gr_inode_lock);
52978 + }
52979 +out:
52980 + br_read_unlock(vfsmount_lock);
52981 + write_sequnlock(&rename_lock);
52982 +
52983 + BUG_ON(retval == NULL);
52984 +
52985 + return retval;
52986 +}
52987 +
52988 +static void
52989 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52990 +{
52991 + struct task_struct *task = current;
52992 + const struct cred *cred = current_cred();
52993 +
52994 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52995 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52996 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52997 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52998 +
52999 + return;
53000 +}
53001 +
53002 +static void
53003 +gr_log_learn_sysctl(const char *path, const __u32 mode)
53004 +{
53005 + struct task_struct *task = current;
53006 + const struct cred *cred = current_cred();
53007 +
53008 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53009 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53010 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53011 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
53012 +
53013 + return;
53014 +}
53015 +
53016 +static void
53017 +gr_log_learn_id_change(const char type, const unsigned int real,
53018 + const unsigned int effective, const unsigned int fs)
53019 +{
53020 + struct task_struct *task = current;
53021 + const struct cred *cred = current_cred();
53022 +
53023 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53024 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53025 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53026 + type, real, effective, fs, &task->signal->saved_ip);
53027 +
53028 + return;
53029 +}
53030 +
53031 +__u32
53032 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53033 + const struct vfsmount * mnt)
53034 +{
53035 + __u32 retval = mode;
53036 + struct acl_subject_label *curracl;
53037 + struct acl_object_label *currobj;
53038 +
53039 + if (unlikely(!(gr_status & GR_READY)))
53040 + return (mode & ~GR_AUDITS);
53041 +
53042 + curracl = current->acl;
53043 +
53044 + currobj = chk_obj_label(dentry, mnt, curracl);
53045 + retval = currobj->mode & mode;
53046 +
53047 + /* if we're opening a specified transfer file for writing
53048 + (e.g. /dev/initctl), then transfer our role to init
53049 + */
53050 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53051 + current->role->roletype & GR_ROLE_PERSIST)) {
53052 + struct task_struct *task = init_pid_ns.child_reaper;
53053 +
53054 + if (task->role != current->role) {
53055 + task->acl_sp_role = 0;
53056 + task->acl_role_id = current->acl_role_id;
53057 + task->role = current->role;
53058 + rcu_read_lock();
53059 + read_lock(&grsec_exec_file_lock);
53060 + gr_apply_subject_to_task(task);
53061 + read_unlock(&grsec_exec_file_lock);
53062 + rcu_read_unlock();
53063 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53064 + }
53065 + }
53066 +
53067 + if (unlikely
53068 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53069 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53070 + __u32 new_mode = mode;
53071 +
53072 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53073 +
53074 + retval = new_mode;
53075 +
53076 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53077 + new_mode |= GR_INHERIT;
53078 +
53079 + if (!(mode & GR_NOLEARN))
53080 + gr_log_learn(dentry, mnt, new_mode);
53081 + }
53082 +
53083 + return retval;
53084 +}
53085 +
53086 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53087 + const struct dentry *parent,
53088 + const struct vfsmount *mnt)
53089 +{
53090 + struct name_entry *match;
53091 + struct acl_object_label *matchpo;
53092 + struct acl_subject_label *curracl;
53093 + char *path;
53094 +
53095 + if (unlikely(!(gr_status & GR_READY)))
53096 + return NULL;
53097 +
53098 + preempt_disable();
53099 + path = gr_to_filename_rbac(new_dentry, mnt);
53100 + match = lookup_name_entry_create(path);
53101 +
53102 + curracl = current->acl;
53103 +
53104 + if (match) {
53105 + read_lock(&gr_inode_lock);
53106 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53107 + read_unlock(&gr_inode_lock);
53108 +
53109 + if (matchpo) {
53110 + preempt_enable();
53111 + return matchpo;
53112 + }
53113 + }
53114 +
53115 + // lookup parent
53116 +
53117 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53118 +
53119 + preempt_enable();
53120 + return matchpo;
53121 +}
53122 +
53123 +__u32
53124 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53125 + const struct vfsmount * mnt, const __u32 mode)
53126 +{
53127 + struct acl_object_label *matchpo;
53128 + __u32 retval;
53129 +
53130 + if (unlikely(!(gr_status & GR_READY)))
53131 + return (mode & ~GR_AUDITS);
53132 +
53133 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53134 +
53135 + retval = matchpo->mode & mode;
53136 +
53137 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53138 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53139 + __u32 new_mode = mode;
53140 +
53141 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53142 +
53143 + gr_log_learn(new_dentry, mnt, new_mode);
53144 + return new_mode;
53145 + }
53146 +
53147 + return retval;
53148 +}
53149 +
53150 +__u32
53151 +gr_check_link(const struct dentry * new_dentry,
53152 + const struct dentry * parent_dentry,
53153 + const struct vfsmount * parent_mnt,
53154 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53155 +{
53156 + struct acl_object_label *obj;
53157 + __u32 oldmode, newmode;
53158 + __u32 needmode;
53159 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53160 + GR_DELETE | GR_INHERIT;
53161 +
53162 + if (unlikely(!(gr_status & GR_READY)))
53163 + return (GR_CREATE | GR_LINK);
53164 +
53165 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53166 + oldmode = obj->mode;
53167 +
53168 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53169 + newmode = obj->mode;
53170 +
53171 + needmode = newmode & checkmodes;
53172 +
53173 + // old name for hardlink must have at least the permissions of the new name
53174 + if ((oldmode & needmode) != needmode)
53175 + goto bad;
53176 +
53177 + // if old name had restrictions/auditing, make sure the new name does as well
53178 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53179 +
53180 + // don't allow hardlinking of suid/sgid files without permission
53181 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53182 + needmode |= GR_SETID;
53183 +
53184 + if ((newmode & needmode) != needmode)
53185 + goto bad;
53186 +
53187 + // enforce minimum permissions
53188 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53189 + return newmode;
53190 +bad:
53191 + needmode = oldmode;
53192 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53193 + needmode |= GR_SETID;
53194 +
53195 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53196 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53197 + return (GR_CREATE | GR_LINK);
53198 + } else if (newmode & GR_SUPPRESS)
53199 + return GR_SUPPRESS;
53200 + else
53201 + return 0;
53202 +}
53203 +
53204 +int
53205 +gr_check_hidden_task(const struct task_struct *task)
53206 +{
53207 + if (unlikely(!(gr_status & GR_READY)))
53208 + return 0;
53209 +
53210 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53211 + return 1;
53212 +
53213 + return 0;
53214 +}
53215 +
53216 +int
53217 +gr_check_protected_task(const struct task_struct *task)
53218 +{
53219 + if (unlikely(!(gr_status & GR_READY) || !task))
53220 + return 0;
53221 +
53222 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53223 + task->acl != current->acl)
53224 + return 1;
53225 +
53226 + return 0;
53227 +}
53228 +
53229 +int
53230 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53231 +{
53232 + struct task_struct *p;
53233 + int ret = 0;
53234 +
53235 + if (unlikely(!(gr_status & GR_READY) || !pid))
53236 + return ret;
53237 +
53238 + read_lock(&tasklist_lock);
53239 + do_each_pid_task(pid, type, p) {
53240 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53241 + p->acl != current->acl) {
53242 + ret = 1;
53243 + goto out;
53244 + }
53245 + } while_each_pid_task(pid, type, p);
53246 +out:
53247 + read_unlock(&tasklist_lock);
53248 +
53249 + return ret;
53250 +}
53251 +
53252 +void
53253 +gr_copy_label(struct task_struct *tsk)
53254 +{
53255 + /* plain copying of fields is already done by dup_task_struct */
53256 + tsk->signal->used_accept = 0;
53257 + tsk->acl_sp_role = 0;
53258 + //tsk->acl_role_id = current->acl_role_id;
53259 + //tsk->acl = current->acl;
53260 + //tsk->role = current->role;
53261 + tsk->signal->curr_ip = current->signal->curr_ip;
53262 + tsk->signal->saved_ip = current->signal->saved_ip;
53263 + if (current->exec_file)
53264 + get_file(current->exec_file);
53265 + //tsk->exec_file = current->exec_file;
53266 + //tsk->is_writable = current->is_writable;
53267 + if (unlikely(current->signal->used_accept)) {
53268 + current->signal->curr_ip = 0;
53269 + current->signal->saved_ip = 0;
53270 + }
53271 +
53272 + return;
53273 +}
53274 +
53275 +static void
53276 +gr_set_proc_res(struct task_struct *task)
53277 +{
53278 + struct acl_subject_label *proc;
53279 + unsigned short i;
53280 +
53281 + proc = task->acl;
53282 +
53283 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53284 + return;
53285 +
53286 + for (i = 0; i < RLIM_NLIMITS; i++) {
53287 + if (!(proc->resmask & (1 << i)))
53288 + continue;
53289 +
53290 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53291 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53292 + }
53293 +
53294 + return;
53295 +}
53296 +
53297 +extern int __gr_process_user_ban(struct user_struct *user);
53298 +
53299 +int
53300 +gr_check_user_change(int real, int effective, int fs)
53301 +{
53302 + unsigned int i;
53303 + __u16 num;
53304 + uid_t *uidlist;
53305 + int curuid;
53306 + int realok = 0;
53307 + int effectiveok = 0;
53308 + int fsok = 0;
53309 +
53310 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53311 + struct user_struct *user;
53312 +
53313 + if (real == -1)
53314 + goto skipit;
53315 +
53316 + user = find_user(real);
53317 + if (user == NULL)
53318 + goto skipit;
53319 +
53320 + if (__gr_process_user_ban(user)) {
53321 + /* for find_user */
53322 + free_uid(user);
53323 + return 1;
53324 + }
53325 +
53326 + /* for find_user */
53327 + free_uid(user);
53328 +
53329 +skipit:
53330 +#endif
53331 +
53332 + if (unlikely(!(gr_status & GR_READY)))
53333 + return 0;
53334 +
53335 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53336 + gr_log_learn_id_change('u', real, effective, fs);
53337 +
53338 + num = current->acl->user_trans_num;
53339 + uidlist = current->acl->user_transitions;
53340 +
53341 + if (uidlist == NULL)
53342 + return 0;
53343 +
53344 + if (real == -1)
53345 + realok = 1;
53346 + if (effective == -1)
53347 + effectiveok = 1;
53348 + if (fs == -1)
53349 + fsok = 1;
53350 +
53351 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53352 + for (i = 0; i < num; i++) {
53353 + curuid = (int)uidlist[i];
53354 + if (real == curuid)
53355 + realok = 1;
53356 + if (effective == curuid)
53357 + effectiveok = 1;
53358 + if (fs == curuid)
53359 + fsok = 1;
53360 + }
53361 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53362 + for (i = 0; i < num; i++) {
53363 + curuid = (int)uidlist[i];
53364 + if (real == curuid)
53365 + break;
53366 + if (effective == curuid)
53367 + break;
53368 + if (fs == curuid)
53369 + break;
53370 + }
53371 + /* not in deny list */
53372 + if (i == num) {
53373 + realok = 1;
53374 + effectiveok = 1;
53375 + fsok = 1;
53376 + }
53377 + }
53378 +
53379 + if (realok && effectiveok && fsok)
53380 + return 0;
53381 + else {
53382 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53383 + return 1;
53384 + }
53385 +}
53386 +
53387 +int
53388 +gr_check_group_change(int real, int effective, int fs)
53389 +{
53390 + unsigned int i;
53391 + __u16 num;
53392 + gid_t *gidlist;
53393 + int curgid;
53394 + int realok = 0;
53395 + int effectiveok = 0;
53396 + int fsok = 0;
53397 +
53398 + if (unlikely(!(gr_status & GR_READY)))
53399 + return 0;
53400 +
53401 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53402 + gr_log_learn_id_change('g', real, effective, fs);
53403 +
53404 + num = current->acl->group_trans_num;
53405 + gidlist = current->acl->group_transitions;
53406 +
53407 + if (gidlist == NULL)
53408 + return 0;
53409 +
53410 + if (real == -1)
53411 + realok = 1;
53412 + if (effective == -1)
53413 + effectiveok = 1;
53414 + if (fs == -1)
53415 + fsok = 1;
53416 +
53417 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53418 + for (i = 0; i < num; i++) {
53419 + curgid = (int)gidlist[i];
53420 + if (real == curgid)
53421 + realok = 1;
53422 + if (effective == curgid)
53423 + effectiveok = 1;
53424 + if (fs == curgid)
53425 + fsok = 1;
53426 + }
53427 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53428 + for (i = 0; i < num; i++) {
53429 + curgid = (int)gidlist[i];
53430 + if (real == curgid)
53431 + break;
53432 + if (effective == curgid)
53433 + break;
53434 + if (fs == curgid)
53435 + break;
53436 + }
53437 + /* not in deny list */
53438 + if (i == num) {
53439 + realok = 1;
53440 + effectiveok = 1;
53441 + fsok = 1;
53442 + }
53443 + }
53444 +
53445 + if (realok && effectiveok && fsok)
53446 + return 0;
53447 + else {
53448 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53449 + return 1;
53450 + }
53451 +}
53452 +
53453 +extern int gr_acl_is_capable(const int cap);
53454 +
53455 +void
53456 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53457 +{
53458 + struct acl_role_label *role = task->role;
53459 + struct acl_subject_label *subj = NULL;
53460 + struct acl_object_label *obj;
53461 + struct file *filp;
53462 +
53463 + if (unlikely(!(gr_status & GR_READY)))
53464 + return;
53465 +
53466 + filp = task->exec_file;
53467 +
53468 + /* kernel process, we'll give them the kernel role */
53469 + if (unlikely(!filp)) {
53470 + task->role = kernel_role;
53471 + task->acl = kernel_role->root_label;
53472 + return;
53473 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53474 + role = lookup_acl_role_label(task, uid, gid);
53475 +
53476 + /* don't change the role if we're not a privileged process */
53477 + if (role && task->role != role &&
53478 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53479 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53480 + return;
53481 +
53482 + /* perform subject lookup in possibly new role
53483 + we can use this result below in the case where role == task->role
53484 + */
53485 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53486 +
53487 + /* if we changed uid/gid, but result in the same role
53488 + and are using inheritance, don't lose the inherited subject
53489 + if current subject is other than what normal lookup
53490 + would result in, we arrived via inheritance, don't
53491 + lose subject
53492 + */
53493 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53494 + (subj == task->acl)))
53495 + task->acl = subj;
53496 +
53497 + task->role = role;
53498 +
53499 + task->is_writable = 0;
53500 +
53501 + /* ignore additional mmap checks for processes that are writable
53502 + by the default ACL */
53503 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53504 + if (unlikely(obj->mode & GR_WRITE))
53505 + task->is_writable = 1;
53506 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53507 + if (unlikely(obj->mode & GR_WRITE))
53508 + task->is_writable = 1;
53509 +
53510 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53511 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53512 +#endif
53513 +
53514 + gr_set_proc_res(task);
53515 +
53516 + return;
53517 +}
53518 +
53519 +int
53520 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53521 + const int unsafe_flags)
53522 +{
53523 + struct task_struct *task = current;
53524 + struct acl_subject_label *newacl;
53525 + struct acl_object_label *obj;
53526 + __u32 retmode;
53527 +
53528 + if (unlikely(!(gr_status & GR_READY)))
53529 + return 0;
53530 +
53531 + newacl = chk_subj_label(dentry, mnt, task->role);
53532 +
53533 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53534 + did an exec
53535 + */
53536 + rcu_read_lock();
53537 + read_lock(&tasklist_lock);
53538 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53539 + (task->parent->acl->mode & GR_POVERRIDE))) {
53540 + read_unlock(&tasklist_lock);
53541 + rcu_read_unlock();
53542 + goto skip_check;
53543 + }
53544 + read_unlock(&tasklist_lock);
53545 + rcu_read_unlock();
53546 +
53547 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53548 + !(task->role->roletype & GR_ROLE_GOD) &&
53549 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53550 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53551 + if (unsafe_flags & LSM_UNSAFE_SHARE)
53552 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53553 + else
53554 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53555 + return -EACCES;
53556 + }
53557 +
53558 +skip_check:
53559 +
53560 + obj = chk_obj_label(dentry, mnt, task->acl);
53561 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53562 +
53563 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53564 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53565 + if (obj->nested)
53566 + task->acl = obj->nested;
53567 + else
53568 + task->acl = newacl;
53569 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53570 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53571 +
53572 + task->is_writable = 0;
53573 +
53574 + /* ignore additional mmap checks for processes that are writable
53575 + by the default ACL */
53576 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53577 + if (unlikely(obj->mode & GR_WRITE))
53578 + task->is_writable = 1;
53579 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53580 + if (unlikely(obj->mode & GR_WRITE))
53581 + task->is_writable = 1;
53582 +
53583 + gr_set_proc_res(task);
53584 +
53585 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53586 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53587 +#endif
53588 + return 0;
53589 +}
53590 +
53591 +/* always called with valid inodev ptr */
53592 +static void
53593 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53594 +{
53595 + struct acl_object_label *matchpo;
53596 + struct acl_subject_label *matchps;
53597 + struct acl_subject_label *subj;
53598 + struct acl_role_label *role;
53599 + unsigned int x;
53600 +
53601 + FOR_EACH_ROLE_START(role)
53602 + FOR_EACH_SUBJECT_START(role, subj, x)
53603 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53604 + matchpo->mode |= GR_DELETED;
53605 + FOR_EACH_SUBJECT_END(subj,x)
53606 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53607 + if (subj->inode == ino && subj->device == dev)
53608 + subj->mode |= GR_DELETED;
53609 + FOR_EACH_NESTED_SUBJECT_END(subj)
53610 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53611 + matchps->mode |= GR_DELETED;
53612 + FOR_EACH_ROLE_END(role)
53613 +
53614 + inodev->nentry->deleted = 1;
53615 +
53616 + return;
53617 +}
53618 +
53619 +void
53620 +gr_handle_delete(const ino_t ino, const dev_t dev)
53621 +{
53622 + struct inodev_entry *inodev;
53623 +
53624 + if (unlikely(!(gr_status & GR_READY)))
53625 + return;
53626 +
53627 + write_lock(&gr_inode_lock);
53628 + inodev = lookup_inodev_entry(ino, dev);
53629 + if (inodev != NULL)
53630 + do_handle_delete(inodev, ino, dev);
53631 + write_unlock(&gr_inode_lock);
53632 +
53633 + return;
53634 +}
53635 +
53636 +static void
53637 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53638 + const ino_t newinode, const dev_t newdevice,
53639 + struct acl_subject_label *subj)
53640 +{
53641 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53642 + struct acl_object_label *match;
53643 +
53644 + match = subj->obj_hash[index];
53645 +
53646 + while (match && (match->inode != oldinode ||
53647 + match->device != olddevice ||
53648 + !(match->mode & GR_DELETED)))
53649 + match = match->next;
53650 +
53651 + if (match && (match->inode == oldinode)
53652 + && (match->device == olddevice)
53653 + && (match->mode & GR_DELETED)) {
53654 + if (match->prev == NULL) {
53655 + subj->obj_hash[index] = match->next;
53656 + if (match->next != NULL)
53657 + match->next->prev = NULL;
53658 + } else {
53659 + match->prev->next = match->next;
53660 + if (match->next != NULL)
53661 + match->next->prev = match->prev;
53662 + }
53663 + match->prev = NULL;
53664 + match->next = NULL;
53665 + match->inode = newinode;
53666 + match->device = newdevice;
53667 + match->mode &= ~GR_DELETED;
53668 +
53669 + insert_acl_obj_label(match, subj);
53670 + }
53671 +
53672 + return;
53673 +}
53674 +
53675 +static void
53676 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53677 + const ino_t newinode, const dev_t newdevice,
53678 + struct acl_role_label *role)
53679 +{
53680 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53681 + struct acl_subject_label *match;
53682 +
53683 + match = role->subj_hash[index];
53684 +
53685 + while (match && (match->inode != oldinode ||
53686 + match->device != olddevice ||
53687 + !(match->mode & GR_DELETED)))
53688 + match = match->next;
53689 +
53690 + if (match && (match->inode == oldinode)
53691 + && (match->device == olddevice)
53692 + && (match->mode & GR_DELETED)) {
53693 + if (match->prev == NULL) {
53694 + role->subj_hash[index] = match->next;
53695 + if (match->next != NULL)
53696 + match->next->prev = NULL;
53697 + } else {
53698 + match->prev->next = match->next;
53699 + if (match->next != NULL)
53700 + match->next->prev = match->prev;
53701 + }
53702 + match->prev = NULL;
53703 + match->next = NULL;
53704 + match->inode = newinode;
53705 + match->device = newdevice;
53706 + match->mode &= ~GR_DELETED;
53707 +
53708 + insert_acl_subj_label(match, role);
53709 + }
53710 +
53711 + return;
53712 +}
53713 +
53714 +static void
53715 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53716 + const ino_t newinode, const dev_t newdevice)
53717 +{
53718 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53719 + struct inodev_entry *match;
53720 +
53721 + match = inodev_set.i_hash[index];
53722 +
53723 + while (match && (match->nentry->inode != oldinode ||
53724 + match->nentry->device != olddevice || !match->nentry->deleted))
53725 + match = match->next;
53726 +
53727 + if (match && (match->nentry->inode == oldinode)
53728 + && (match->nentry->device == olddevice) &&
53729 + match->nentry->deleted) {
53730 + if (match->prev == NULL) {
53731 + inodev_set.i_hash[index] = match->next;
53732 + if (match->next != NULL)
53733 + match->next->prev = NULL;
53734 + } else {
53735 + match->prev->next = match->next;
53736 + if (match->next != NULL)
53737 + match->next->prev = match->prev;
53738 + }
53739 + match->prev = NULL;
53740 + match->next = NULL;
53741 + match->nentry->inode = newinode;
53742 + match->nentry->device = newdevice;
53743 + match->nentry->deleted = 0;
53744 +
53745 + insert_inodev_entry(match);
53746 + }
53747 +
53748 + return;
53749 +}
53750 +
53751 +static void
53752 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53753 +{
53754 + struct acl_subject_label *subj;
53755 + struct acl_role_label *role;
53756 + unsigned int x;
53757 +
53758 + FOR_EACH_ROLE_START(role)
53759 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53760 +
53761 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53762 + if ((subj->inode == ino) && (subj->device == dev)) {
53763 + subj->inode = ino;
53764 + subj->device = dev;
53765 + }
53766 + FOR_EACH_NESTED_SUBJECT_END(subj)
53767 + FOR_EACH_SUBJECT_START(role, subj, x)
53768 + update_acl_obj_label(matchn->inode, matchn->device,
53769 + ino, dev, subj);
53770 + FOR_EACH_SUBJECT_END(subj,x)
53771 + FOR_EACH_ROLE_END(role)
53772 +
53773 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53774 +
53775 + return;
53776 +}
53777 +
53778 +static void
53779 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53780 + const struct vfsmount *mnt)
53781 +{
53782 + ino_t ino = dentry->d_inode->i_ino;
53783 + dev_t dev = __get_dev(dentry);
53784 +
53785 + __do_handle_create(matchn, ino, dev);
53786 +
53787 + return;
53788 +}
53789 +
53790 +void
53791 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53792 +{
53793 + struct name_entry *matchn;
53794 +
53795 + if (unlikely(!(gr_status & GR_READY)))
53796 + return;
53797 +
53798 + preempt_disable();
53799 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53800 +
53801 + if (unlikely((unsigned long)matchn)) {
53802 + write_lock(&gr_inode_lock);
53803 + do_handle_create(matchn, dentry, mnt);
53804 + write_unlock(&gr_inode_lock);
53805 + }
53806 + preempt_enable();
53807 +
53808 + return;
53809 +}
53810 +
53811 +void
53812 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53813 +{
53814 + struct name_entry *matchn;
53815 +
53816 + if (unlikely(!(gr_status & GR_READY)))
53817 + return;
53818 +
53819 + preempt_disable();
53820 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53821 +
53822 + if (unlikely((unsigned long)matchn)) {
53823 + write_lock(&gr_inode_lock);
53824 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53825 + write_unlock(&gr_inode_lock);
53826 + }
53827 + preempt_enable();
53828 +
53829 + return;
53830 +}
53831 +
53832 +void
53833 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53834 + struct dentry *old_dentry,
53835 + struct dentry *new_dentry,
53836 + struct vfsmount *mnt, const __u8 replace)
53837 +{
53838 + struct name_entry *matchn;
53839 + struct inodev_entry *inodev;
53840 + struct inode *inode = new_dentry->d_inode;
53841 + ino_t old_ino = old_dentry->d_inode->i_ino;
53842 + dev_t old_dev = __get_dev(old_dentry);
53843 +
53844 + /* vfs_rename swaps the name and parent link for old_dentry and
53845 + new_dentry
53846 + at this point, old_dentry has the new name, parent link, and inode
53847 + for the renamed file
53848 + if a file is being replaced by a rename, new_dentry has the inode
53849 + and name for the replaced file
53850 + */
53851 +
53852 + if (unlikely(!(gr_status & GR_READY)))
53853 + return;
53854 +
53855 + preempt_disable();
53856 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53857 +
53858 + /* we wouldn't have to check d_inode if it weren't for
53859 + NFS silly-renaming
53860 + */
53861 +
53862 + write_lock(&gr_inode_lock);
53863 + if (unlikely(replace && inode)) {
53864 + ino_t new_ino = inode->i_ino;
53865 + dev_t new_dev = __get_dev(new_dentry);
53866 +
53867 + inodev = lookup_inodev_entry(new_ino, new_dev);
53868 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53869 + do_handle_delete(inodev, new_ino, new_dev);
53870 + }
53871 +
53872 + inodev = lookup_inodev_entry(old_ino, old_dev);
53873 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53874 + do_handle_delete(inodev, old_ino, old_dev);
53875 +
53876 + if (unlikely((unsigned long)matchn))
53877 + do_handle_create(matchn, old_dentry, mnt);
53878 +
53879 + write_unlock(&gr_inode_lock);
53880 + preempt_enable();
53881 +
53882 + return;
53883 +}
53884 +
53885 +static int
53886 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53887 + unsigned char **sum)
53888 +{
53889 + struct acl_role_label *r;
53890 + struct role_allowed_ip *ipp;
53891 + struct role_transition *trans;
53892 + unsigned int i;
53893 + int found = 0;
53894 + u32 curr_ip = current->signal->curr_ip;
53895 +
53896 + current->signal->saved_ip = curr_ip;
53897 +
53898 + /* check transition table */
53899 +
53900 + for (trans = current->role->transitions; trans; trans = trans->next) {
53901 + if (!strcmp(rolename, trans->rolename)) {
53902 + found = 1;
53903 + break;
53904 + }
53905 + }
53906 +
53907 + if (!found)
53908 + return 0;
53909 +
53910 + /* handle special roles that do not require authentication
53911 + and check ip */
53912 +
53913 + FOR_EACH_ROLE_START(r)
53914 + if (!strcmp(rolename, r->rolename) &&
53915 + (r->roletype & GR_ROLE_SPECIAL)) {
53916 + found = 0;
53917 + if (r->allowed_ips != NULL) {
53918 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53919 + if ((ntohl(curr_ip) & ipp->netmask) ==
53920 + (ntohl(ipp->addr) & ipp->netmask))
53921 + found = 1;
53922 + }
53923 + } else
53924 + found = 2;
53925 + if (!found)
53926 + return 0;
53927 +
53928 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53929 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53930 + *salt = NULL;
53931 + *sum = NULL;
53932 + return 1;
53933 + }
53934 + }
53935 + FOR_EACH_ROLE_END(r)
53936 +
53937 + for (i = 0; i < num_sprole_pws; i++) {
53938 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53939 + *salt = acl_special_roles[i]->salt;
53940 + *sum = acl_special_roles[i]->sum;
53941 + return 1;
53942 + }
53943 + }
53944 +
53945 + return 0;
53946 +}
53947 +
53948 +static void
53949 +assign_special_role(char *rolename)
53950 +{
53951 + struct acl_object_label *obj;
53952 + struct acl_role_label *r;
53953 + struct acl_role_label *assigned = NULL;
53954 + struct task_struct *tsk;
53955 + struct file *filp;
53956 +
53957 + FOR_EACH_ROLE_START(r)
53958 + if (!strcmp(rolename, r->rolename) &&
53959 + (r->roletype & GR_ROLE_SPECIAL)) {
53960 + assigned = r;
53961 + break;
53962 + }
53963 + FOR_EACH_ROLE_END(r)
53964 +
53965 + if (!assigned)
53966 + return;
53967 +
53968 + read_lock(&tasklist_lock);
53969 + read_lock(&grsec_exec_file_lock);
53970 +
53971 + tsk = current->real_parent;
53972 + if (tsk == NULL)
53973 + goto out_unlock;
53974 +
53975 + filp = tsk->exec_file;
53976 + if (filp == NULL)
53977 + goto out_unlock;
53978 +
53979 + tsk->is_writable = 0;
53980 +
53981 + tsk->acl_sp_role = 1;
53982 + tsk->acl_role_id = ++acl_sp_role_value;
53983 + tsk->role = assigned;
53984 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53985 +
53986 + /* ignore additional mmap checks for processes that are writable
53987 + by the default ACL */
53988 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53989 + if (unlikely(obj->mode & GR_WRITE))
53990 + tsk->is_writable = 1;
53991 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53992 + if (unlikely(obj->mode & GR_WRITE))
53993 + tsk->is_writable = 1;
53994 +
53995 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53996 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53997 +#endif
53998 +
53999 +out_unlock:
54000 + read_unlock(&grsec_exec_file_lock);
54001 + read_unlock(&tasklist_lock);
54002 + return;
54003 +}
54004 +
54005 +int gr_check_secure_terminal(struct task_struct *task)
54006 +{
54007 + struct task_struct *p, *p2, *p3;
54008 + struct files_struct *files;
54009 + struct fdtable *fdt;
54010 + struct file *our_file = NULL, *file;
54011 + int i;
54012 +
54013 + if (task->signal->tty == NULL)
54014 + return 1;
54015 +
54016 + files = get_files_struct(task);
54017 + if (files != NULL) {
54018 + rcu_read_lock();
54019 + fdt = files_fdtable(files);
54020 + for (i=0; i < fdt->max_fds; i++) {
54021 + file = fcheck_files(files, i);
54022 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54023 + get_file(file);
54024 + our_file = file;
54025 + }
54026 + }
54027 + rcu_read_unlock();
54028 + put_files_struct(files);
54029 + }
54030 +
54031 + if (our_file == NULL)
54032 + return 1;
54033 +
54034 + read_lock(&tasklist_lock);
54035 + do_each_thread(p2, p) {
54036 + files = get_files_struct(p);
54037 + if (files == NULL ||
54038 + (p->signal && p->signal->tty == task->signal->tty)) {
54039 + if (files != NULL)
54040 + put_files_struct(files);
54041 + continue;
54042 + }
54043 + rcu_read_lock();
54044 + fdt = files_fdtable(files);
54045 + for (i=0; i < fdt->max_fds; i++) {
54046 + file = fcheck_files(files, i);
54047 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54048 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54049 + p3 = task;
54050 + while (p3->pid > 0) {
54051 + if (p3 == p)
54052 + break;
54053 + p3 = p3->real_parent;
54054 + }
54055 + if (p3 == p)
54056 + break;
54057 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54058 + gr_handle_alertkill(p);
54059 + rcu_read_unlock();
54060 + put_files_struct(files);
54061 + read_unlock(&tasklist_lock);
54062 + fput(our_file);
54063 + return 0;
54064 + }
54065 + }
54066 + rcu_read_unlock();
54067 + put_files_struct(files);
54068 + } while_each_thread(p2, p);
54069 + read_unlock(&tasklist_lock);
54070 +
54071 + fput(our_file);
54072 + return 1;
54073 +}
54074 +
54075 +ssize_t
54076 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54077 +{
54078 + struct gr_arg_wrapper uwrap;
54079 + unsigned char *sprole_salt = NULL;
54080 + unsigned char *sprole_sum = NULL;
54081 + int error = sizeof (struct gr_arg_wrapper);
54082 + int error2 = 0;
54083 +
54084 + mutex_lock(&gr_dev_mutex);
54085 +
54086 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54087 + error = -EPERM;
54088 + goto out;
54089 + }
54090 +
54091 + if (count != sizeof (struct gr_arg_wrapper)) {
54092 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54093 + error = -EINVAL;
54094 + goto out;
54095 + }
54096 +
54097 +
54098 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54099 + gr_auth_expires = 0;
54100 + gr_auth_attempts = 0;
54101 + }
54102 +
54103 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54104 + error = -EFAULT;
54105 + goto out;
54106 + }
54107 +
54108 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54109 + error = -EINVAL;
54110 + goto out;
54111 + }
54112 +
54113 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54114 + error = -EFAULT;
54115 + goto out;
54116 + }
54117 +
54118 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54119 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54120 + time_after(gr_auth_expires, get_seconds())) {
54121 + error = -EBUSY;
54122 + goto out;
54123 + }
54124 +
54125 + /* if non-root trying to do anything other than use a special role,
54126 + do not attempt authentication, do not count towards authentication
54127 + locking
54128 + */
54129 +
54130 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54131 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54132 + current_uid()) {
54133 + error = -EPERM;
54134 + goto out;
54135 + }
54136 +
54137 + /* ensure pw and special role name are null terminated */
54138 +
54139 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54140 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54141 +
54142 + /* Okay.
54143 + * We have our enough of the argument structure..(we have yet
54144 + * to copy_from_user the tables themselves) . Copy the tables
54145 + * only if we need them, i.e. for loading operations. */
54146 +
54147 + switch (gr_usermode->mode) {
54148 + case GR_STATUS:
54149 + if (gr_status & GR_READY) {
54150 + error = 1;
54151 + if (!gr_check_secure_terminal(current))
54152 + error = 3;
54153 + } else
54154 + error = 2;
54155 + goto out;
54156 + case GR_SHUTDOWN:
54157 + if ((gr_status & GR_READY)
54158 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54159 + pax_open_kernel();
54160 + gr_status &= ~GR_READY;
54161 + pax_close_kernel();
54162 +
54163 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54164 + free_variables();
54165 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54166 + memset(gr_system_salt, 0, GR_SALT_LEN);
54167 + memset(gr_system_sum, 0, GR_SHA_LEN);
54168 + } else if (gr_status & GR_READY) {
54169 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54170 + error = -EPERM;
54171 + } else {
54172 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54173 + error = -EAGAIN;
54174 + }
54175 + break;
54176 + case GR_ENABLE:
54177 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54178 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54179 + else {
54180 + if (gr_status & GR_READY)
54181 + error = -EAGAIN;
54182 + else
54183 + error = error2;
54184 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54185 + }
54186 + break;
54187 + case GR_RELOAD:
54188 + if (!(gr_status & GR_READY)) {
54189 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54190 + error = -EAGAIN;
54191 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54192 + preempt_disable();
54193 +
54194 + pax_open_kernel();
54195 + gr_status &= ~GR_READY;
54196 + pax_close_kernel();
54197 +
54198 + free_variables();
54199 + if (!(error2 = gracl_init(gr_usermode))) {
54200 + preempt_enable();
54201 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54202 + } else {
54203 + preempt_enable();
54204 + error = error2;
54205 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54206 + }
54207 + } else {
54208 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54209 + error = -EPERM;
54210 + }
54211 + break;
54212 + case GR_SEGVMOD:
54213 + if (unlikely(!(gr_status & GR_READY))) {
54214 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54215 + error = -EAGAIN;
54216 + break;
54217 + }
54218 +
54219 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54220 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54221 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54222 + struct acl_subject_label *segvacl;
54223 + segvacl =
54224 + lookup_acl_subj_label(gr_usermode->segv_inode,
54225 + gr_usermode->segv_device,
54226 + current->role);
54227 + if (segvacl) {
54228 + segvacl->crashes = 0;
54229 + segvacl->expires = 0;
54230 + }
54231 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54232 + gr_remove_uid(gr_usermode->segv_uid);
54233 + }
54234 + } else {
54235 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54236 + error = -EPERM;
54237 + }
54238 + break;
54239 + case GR_SPROLE:
54240 + case GR_SPROLEPAM:
54241 + if (unlikely(!(gr_status & GR_READY))) {
54242 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54243 + error = -EAGAIN;
54244 + break;
54245 + }
54246 +
54247 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54248 + current->role->expires = 0;
54249 + current->role->auth_attempts = 0;
54250 + }
54251 +
54252 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54253 + time_after(current->role->expires, get_seconds())) {
54254 + error = -EBUSY;
54255 + goto out;
54256 + }
54257 +
54258 + if (lookup_special_role_auth
54259 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54260 + && ((!sprole_salt && !sprole_sum)
54261 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54262 + char *p = "";
54263 + assign_special_role(gr_usermode->sp_role);
54264 + read_lock(&tasklist_lock);
54265 + if (current->real_parent)
54266 + p = current->real_parent->role->rolename;
54267 + read_unlock(&tasklist_lock);
54268 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54269 + p, acl_sp_role_value);
54270 + } else {
54271 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54272 + error = -EPERM;
54273 + if(!(current->role->auth_attempts++))
54274 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54275 +
54276 + goto out;
54277 + }
54278 + break;
54279 + case GR_UNSPROLE:
54280 + if (unlikely(!(gr_status & GR_READY))) {
54281 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54282 + error = -EAGAIN;
54283 + break;
54284 + }
54285 +
54286 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54287 + char *p = "";
54288 + int i = 0;
54289 +
54290 + read_lock(&tasklist_lock);
54291 + if (current->real_parent) {
54292 + p = current->real_parent->role->rolename;
54293 + i = current->real_parent->acl_role_id;
54294 + }
54295 + read_unlock(&tasklist_lock);
54296 +
54297 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54298 + gr_set_acls(1);
54299 + } else {
54300 + error = -EPERM;
54301 + goto out;
54302 + }
54303 + break;
54304 + default:
54305 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54306 + error = -EINVAL;
54307 + break;
54308 + }
54309 +
54310 + if (error != -EPERM)
54311 + goto out;
54312 +
54313 + if(!(gr_auth_attempts++))
54314 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54315 +
54316 + out:
54317 + mutex_unlock(&gr_dev_mutex);
54318 + return error;
54319 +}
54320 +
54321 +/* must be called with
54322 + rcu_read_lock();
54323 + read_lock(&tasklist_lock);
54324 + read_lock(&grsec_exec_file_lock);
54325 +*/
54326 +int gr_apply_subject_to_task(struct task_struct *task)
54327 +{
54328 + struct acl_object_label *obj;
54329 + char *tmpname;
54330 + struct acl_subject_label *tmpsubj;
54331 + struct file *filp;
54332 + struct name_entry *nmatch;
54333 +
54334 + filp = task->exec_file;
54335 + if (filp == NULL)
54336 + return 0;
54337 +
54338 + /* the following is to apply the correct subject
54339 + on binaries running when the RBAC system
54340 + is enabled, when the binaries have been
54341 + replaced or deleted since their execution
54342 + -----
54343 + when the RBAC system starts, the inode/dev
54344 + from exec_file will be one the RBAC system
54345 + is unaware of. It only knows the inode/dev
54346 + of the present file on disk, or the absence
54347 + of it.
54348 + */
54349 + preempt_disable();
54350 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54351 +
54352 + nmatch = lookup_name_entry(tmpname);
54353 + preempt_enable();
54354 + tmpsubj = NULL;
54355 + if (nmatch) {
54356 + if (nmatch->deleted)
54357 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54358 + else
54359 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54360 + if (tmpsubj != NULL)
54361 + task->acl = tmpsubj;
54362 + }
54363 + if (tmpsubj == NULL)
54364 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54365 + task->role);
54366 + if (task->acl) {
54367 + task->is_writable = 0;
54368 + /* ignore additional mmap checks for processes that are writable
54369 + by the default ACL */
54370 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54371 + if (unlikely(obj->mode & GR_WRITE))
54372 + task->is_writable = 1;
54373 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54374 + if (unlikely(obj->mode & GR_WRITE))
54375 + task->is_writable = 1;
54376 +
54377 + gr_set_proc_res(task);
54378 +
54379 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54380 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54381 +#endif
54382 + } else {
54383 + return 1;
54384 + }
54385 +
54386 + return 0;
54387 +}
54388 +
54389 +int
54390 +gr_set_acls(const int type)
54391 +{
54392 + struct task_struct *task, *task2;
54393 + struct acl_role_label *role = current->role;
54394 + __u16 acl_role_id = current->acl_role_id;
54395 + const struct cred *cred;
54396 + int ret;
54397 +
54398 + rcu_read_lock();
54399 + read_lock(&tasklist_lock);
54400 + read_lock(&grsec_exec_file_lock);
54401 + do_each_thread(task2, task) {
54402 + /* check to see if we're called from the exit handler,
54403 + if so, only replace ACLs that have inherited the admin
54404 + ACL */
54405 +
54406 + if (type && (task->role != role ||
54407 + task->acl_role_id != acl_role_id))
54408 + continue;
54409 +
54410 + task->acl_role_id = 0;
54411 + task->acl_sp_role = 0;
54412 +
54413 + if (task->exec_file) {
54414 + cred = __task_cred(task);
54415 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54416 + ret = gr_apply_subject_to_task(task);
54417 + if (ret) {
54418 + read_unlock(&grsec_exec_file_lock);
54419 + read_unlock(&tasklist_lock);
54420 + rcu_read_unlock();
54421 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54422 + return ret;
54423 + }
54424 + } else {
54425 + // it's a kernel process
54426 + task->role = kernel_role;
54427 + task->acl = kernel_role->root_label;
54428 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54429 + task->acl->mode &= ~GR_PROCFIND;
54430 +#endif
54431 + }
54432 + } while_each_thread(task2, task);
54433 + read_unlock(&grsec_exec_file_lock);
54434 + read_unlock(&tasklist_lock);
54435 + rcu_read_unlock();
54436 +
54437 + return 0;
54438 +}
54439 +
54440 +void
54441 +gr_learn_resource(const struct task_struct *task,
54442 + const int res, const unsigned long wanted, const int gt)
54443 +{
54444 + struct acl_subject_label *acl;
54445 + const struct cred *cred;
54446 +
54447 + if (unlikely((gr_status & GR_READY) &&
54448 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54449 + goto skip_reslog;
54450 +
54451 +#ifdef CONFIG_GRKERNSEC_RESLOG
54452 + gr_log_resource(task, res, wanted, gt);
54453 +#endif
54454 + skip_reslog:
54455 +
54456 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54457 + return;
54458 +
54459 + acl = task->acl;
54460 +
54461 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54462 + !(acl->resmask & (1 << (unsigned short) res))))
54463 + return;
54464 +
54465 + if (wanted >= acl->res[res].rlim_cur) {
54466 + unsigned long res_add;
54467 +
54468 + res_add = wanted;
54469 + switch (res) {
54470 + case RLIMIT_CPU:
54471 + res_add += GR_RLIM_CPU_BUMP;
54472 + break;
54473 + case RLIMIT_FSIZE:
54474 + res_add += GR_RLIM_FSIZE_BUMP;
54475 + break;
54476 + case RLIMIT_DATA:
54477 + res_add += GR_RLIM_DATA_BUMP;
54478 + break;
54479 + case RLIMIT_STACK:
54480 + res_add += GR_RLIM_STACK_BUMP;
54481 + break;
54482 + case RLIMIT_CORE:
54483 + res_add += GR_RLIM_CORE_BUMP;
54484 + break;
54485 + case RLIMIT_RSS:
54486 + res_add += GR_RLIM_RSS_BUMP;
54487 + break;
54488 + case RLIMIT_NPROC:
54489 + res_add += GR_RLIM_NPROC_BUMP;
54490 + break;
54491 + case RLIMIT_NOFILE:
54492 + res_add += GR_RLIM_NOFILE_BUMP;
54493 + break;
54494 + case RLIMIT_MEMLOCK:
54495 + res_add += GR_RLIM_MEMLOCK_BUMP;
54496 + break;
54497 + case RLIMIT_AS:
54498 + res_add += GR_RLIM_AS_BUMP;
54499 + break;
54500 + case RLIMIT_LOCKS:
54501 + res_add += GR_RLIM_LOCKS_BUMP;
54502 + break;
54503 + case RLIMIT_SIGPENDING:
54504 + res_add += GR_RLIM_SIGPENDING_BUMP;
54505 + break;
54506 + case RLIMIT_MSGQUEUE:
54507 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54508 + break;
54509 + case RLIMIT_NICE:
54510 + res_add += GR_RLIM_NICE_BUMP;
54511 + break;
54512 + case RLIMIT_RTPRIO:
54513 + res_add += GR_RLIM_RTPRIO_BUMP;
54514 + break;
54515 + case RLIMIT_RTTIME:
54516 + res_add += GR_RLIM_RTTIME_BUMP;
54517 + break;
54518 + }
54519 +
54520 + acl->res[res].rlim_cur = res_add;
54521 +
54522 + if (wanted > acl->res[res].rlim_max)
54523 + acl->res[res].rlim_max = res_add;
54524 +
54525 + /* only log the subject filename, since resource logging is supported for
54526 + single-subject learning only */
54527 + rcu_read_lock();
54528 + cred = __task_cred(task);
54529 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54530 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54531 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54532 + "", (unsigned long) res, &task->signal->saved_ip);
54533 + rcu_read_unlock();
54534 + }
54535 +
54536 + return;
54537 +}
54538 +
54539 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54540 +void
54541 +pax_set_initial_flags(struct linux_binprm *bprm)
54542 +{
54543 + struct task_struct *task = current;
54544 + struct acl_subject_label *proc;
54545 + unsigned long flags;
54546 +
54547 + if (unlikely(!(gr_status & GR_READY)))
54548 + return;
54549 +
54550 + flags = pax_get_flags(task);
54551 +
54552 + proc = task->acl;
54553 +
54554 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54555 + flags &= ~MF_PAX_PAGEEXEC;
54556 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54557 + flags &= ~MF_PAX_SEGMEXEC;
54558 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54559 + flags &= ~MF_PAX_RANDMMAP;
54560 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54561 + flags &= ~MF_PAX_EMUTRAMP;
54562 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54563 + flags &= ~MF_PAX_MPROTECT;
54564 +
54565 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54566 + flags |= MF_PAX_PAGEEXEC;
54567 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54568 + flags |= MF_PAX_SEGMEXEC;
54569 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54570 + flags |= MF_PAX_RANDMMAP;
54571 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54572 + flags |= MF_PAX_EMUTRAMP;
54573 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54574 + flags |= MF_PAX_MPROTECT;
54575 +
54576 + pax_set_flags(task, flags);
54577 +
54578 + return;
54579 +}
54580 +#endif
54581 +
54582 +#ifdef CONFIG_SYSCTL
54583 +/* Eric Biederman likes breaking userland ABI and every inode-based security
54584 + system to save 35kb of memory */
54585 +
54586 +/* we modify the passed in filename, but adjust it back before returning */
54587 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54588 +{
54589 + struct name_entry *nmatch;
54590 + char *p, *lastp = NULL;
54591 + struct acl_object_label *obj = NULL, *tmp;
54592 + struct acl_subject_label *tmpsubj;
54593 + char c = '\0';
54594 +
54595 + read_lock(&gr_inode_lock);
54596 +
54597 + p = name + len - 1;
54598 + do {
54599 + nmatch = lookup_name_entry(name);
54600 + if (lastp != NULL)
54601 + *lastp = c;
54602 +
54603 + if (nmatch == NULL)
54604 + goto next_component;
54605 + tmpsubj = current->acl;
54606 + do {
54607 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54608 + if (obj != NULL) {
54609 + tmp = obj->globbed;
54610 + while (tmp) {
54611 + if (!glob_match(tmp->filename, name)) {
54612 + obj = tmp;
54613 + goto found_obj;
54614 + }
54615 + tmp = tmp->next;
54616 + }
54617 + goto found_obj;
54618 + }
54619 + } while ((tmpsubj = tmpsubj->parent_subject));
54620 +next_component:
54621 + /* end case */
54622 + if (p == name)
54623 + break;
54624 +
54625 + while (*p != '/')
54626 + p--;
54627 + if (p == name)
54628 + lastp = p + 1;
54629 + else {
54630 + lastp = p;
54631 + p--;
54632 + }
54633 + c = *lastp;
54634 + *lastp = '\0';
54635 + } while (1);
54636 +found_obj:
54637 + read_unlock(&gr_inode_lock);
54638 + /* obj returned will always be non-null */
54639 + return obj;
54640 +}
54641 +
54642 +/* returns 0 when allowing, non-zero on error
54643 + op of 0 is used for readdir, so we don't log the names of hidden files
54644 +*/
54645 +__u32
54646 +gr_handle_sysctl(const struct ctl_table *table, const int op)
54647 +{
54648 + struct ctl_table *tmp;
54649 + const char *proc_sys = "/proc/sys";
54650 + char *path;
54651 + struct acl_object_label *obj;
54652 + unsigned short len = 0, pos = 0, depth = 0, i;
54653 + __u32 err = 0;
54654 + __u32 mode = 0;
54655 +
54656 + if (unlikely(!(gr_status & GR_READY)))
54657 + return 0;
54658 +
54659 + /* for now, ignore operations on non-sysctl entries if it's not a
54660 + readdir*/
54661 + if (table->child != NULL && op != 0)
54662 + return 0;
54663 +
54664 + mode |= GR_FIND;
54665 + /* it's only a read if it's an entry, read on dirs is for readdir */
54666 + if (op & MAY_READ)
54667 + mode |= GR_READ;
54668 + if (op & MAY_WRITE)
54669 + mode |= GR_WRITE;
54670 +
54671 + preempt_disable();
54672 +
54673 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54674 +
54675 + /* it's only a read/write if it's an actual entry, not a dir
54676 + (which are opened for readdir)
54677 + */
54678 +
54679 + /* convert the requested sysctl entry into a pathname */
54680 +
54681 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54682 + len += strlen(tmp->procname);
54683 + len++;
54684 + depth++;
54685 + }
54686 +
54687 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54688 + /* deny */
54689 + goto out;
54690 + }
54691 +
54692 + memset(path, 0, PAGE_SIZE);
54693 +
54694 + memcpy(path, proc_sys, strlen(proc_sys));
54695 +
54696 + pos += strlen(proc_sys);
54697 +
54698 + for (; depth > 0; depth--) {
54699 + path[pos] = '/';
54700 + pos++;
54701 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54702 + if (depth == i) {
54703 + memcpy(path + pos, tmp->procname,
54704 + strlen(tmp->procname));
54705 + pos += strlen(tmp->procname);
54706 + }
54707 + i++;
54708 + }
54709 + }
54710 +
54711 + obj = gr_lookup_by_name(path, pos);
54712 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
54713 +
54714 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
54715 + ((err & mode) != mode))) {
54716 + __u32 new_mode = mode;
54717 +
54718 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54719 +
54720 + err = 0;
54721 + gr_log_learn_sysctl(path, new_mode);
54722 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
54723 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
54724 + err = -ENOENT;
54725 + } else if (!(err & GR_FIND)) {
54726 + err = -ENOENT;
54727 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
54728 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
54729 + path, (mode & GR_READ) ? " reading" : "",
54730 + (mode & GR_WRITE) ? " writing" : "");
54731 + err = -EACCES;
54732 + } else if ((err & mode) != mode) {
54733 + err = -EACCES;
54734 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
54735 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
54736 + path, (mode & GR_READ) ? " reading" : "",
54737 + (mode & GR_WRITE) ? " writing" : "");
54738 + err = 0;
54739 + } else
54740 + err = 0;
54741 +
54742 + out:
54743 + preempt_enable();
54744 +
54745 + return err;
54746 +}
54747 +#endif
54748 +
54749 +int
54750 +gr_handle_proc_ptrace(struct task_struct *task)
54751 +{
54752 + struct file *filp;
54753 + struct task_struct *tmp = task;
54754 + struct task_struct *curtemp = current;
54755 + __u32 retmode;
54756 +
54757 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54758 + if (unlikely(!(gr_status & GR_READY)))
54759 + return 0;
54760 +#endif
54761 +
54762 + read_lock(&tasklist_lock);
54763 + read_lock(&grsec_exec_file_lock);
54764 + filp = task->exec_file;
54765 +
54766 + while (tmp->pid > 0) {
54767 + if (tmp == curtemp)
54768 + break;
54769 + tmp = tmp->real_parent;
54770 + }
54771 +
54772 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54773 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54774 + read_unlock(&grsec_exec_file_lock);
54775 + read_unlock(&tasklist_lock);
54776 + return 1;
54777 + }
54778 +
54779 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54780 + if (!(gr_status & GR_READY)) {
54781 + read_unlock(&grsec_exec_file_lock);
54782 + read_unlock(&tasklist_lock);
54783 + return 0;
54784 + }
54785 +#endif
54786 +
54787 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54788 + read_unlock(&grsec_exec_file_lock);
54789 + read_unlock(&tasklist_lock);
54790 +
54791 + if (retmode & GR_NOPTRACE)
54792 + return 1;
54793 +
54794 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54795 + && (current->acl != task->acl || (current->acl != current->role->root_label
54796 + && current->pid != task->pid)))
54797 + return 1;
54798 +
54799 + return 0;
54800 +}
54801 +
54802 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54803 +{
54804 + if (unlikely(!(gr_status & GR_READY)))
54805 + return;
54806 +
54807 + if (!(current->role->roletype & GR_ROLE_GOD))
54808 + return;
54809 +
54810 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54811 + p->role->rolename, gr_task_roletype_to_char(p),
54812 + p->acl->filename);
54813 +}
54814 +
54815 +int
54816 +gr_handle_ptrace(struct task_struct *task, const long request)
54817 +{
54818 + struct task_struct *tmp = task;
54819 + struct task_struct *curtemp = current;
54820 + __u32 retmode;
54821 +
54822 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54823 + if (unlikely(!(gr_status & GR_READY)))
54824 + return 0;
54825 +#endif
54826 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54827 + read_lock(&tasklist_lock);
54828 + while (tmp->pid > 0) {
54829 + if (tmp == curtemp)
54830 + break;
54831 + tmp = tmp->real_parent;
54832 + }
54833 +
54834 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54835 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54836 + read_unlock(&tasklist_lock);
54837 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54838 + return 1;
54839 + }
54840 + read_unlock(&tasklist_lock);
54841 + }
54842 +
54843 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54844 + if (!(gr_status & GR_READY))
54845 + return 0;
54846 +#endif
54847 +
54848 + read_lock(&grsec_exec_file_lock);
54849 + if (unlikely(!task->exec_file)) {
54850 + read_unlock(&grsec_exec_file_lock);
54851 + return 0;
54852 + }
54853 +
54854 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54855 + read_unlock(&grsec_exec_file_lock);
54856 +
54857 + if (retmode & GR_NOPTRACE) {
54858 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54859 + return 1;
54860 + }
54861 +
54862 + if (retmode & GR_PTRACERD) {
54863 + switch (request) {
54864 + case PTRACE_SEIZE:
54865 + case PTRACE_POKETEXT:
54866 + case PTRACE_POKEDATA:
54867 + case PTRACE_POKEUSR:
54868 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54869 + case PTRACE_SETREGS:
54870 + case PTRACE_SETFPREGS:
54871 +#endif
54872 +#ifdef CONFIG_X86
54873 + case PTRACE_SETFPXREGS:
54874 +#endif
54875 +#ifdef CONFIG_ALTIVEC
54876 + case PTRACE_SETVRREGS:
54877 +#endif
54878 + return 1;
54879 + default:
54880 + return 0;
54881 + }
54882 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54883 + !(current->role->roletype & GR_ROLE_GOD) &&
54884 + (current->acl != task->acl)) {
54885 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54886 + return 1;
54887 + }
54888 +
54889 + return 0;
54890 +}
54891 +
54892 +static int is_writable_mmap(const struct file *filp)
54893 +{
54894 + struct task_struct *task = current;
54895 + struct acl_object_label *obj, *obj2;
54896 +
54897 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54898 + !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))) {
54899 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54900 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54901 + task->role->root_label);
54902 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54903 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54904 + return 1;
54905 + }
54906 + }
54907 + return 0;
54908 +}
54909 +
54910 +int
54911 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54912 +{
54913 + __u32 mode;
54914 +
54915 + if (unlikely(!file || !(prot & PROT_EXEC)))
54916 + return 1;
54917 +
54918 + if (is_writable_mmap(file))
54919 + return 0;
54920 +
54921 + mode =
54922 + gr_search_file(file->f_path.dentry,
54923 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54924 + file->f_path.mnt);
54925 +
54926 + if (!gr_tpe_allow(file))
54927 + return 0;
54928 +
54929 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54930 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54931 + return 0;
54932 + } else if (unlikely(!(mode & GR_EXEC))) {
54933 + return 0;
54934 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54935 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54936 + return 1;
54937 + }
54938 +
54939 + return 1;
54940 +}
54941 +
54942 +int
54943 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54944 +{
54945 + __u32 mode;
54946 +
54947 + if (unlikely(!file || !(prot & PROT_EXEC)))
54948 + return 1;
54949 +
54950 + if (is_writable_mmap(file))
54951 + return 0;
54952 +
54953 + mode =
54954 + gr_search_file(file->f_path.dentry,
54955 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54956 + file->f_path.mnt);
54957 +
54958 + if (!gr_tpe_allow(file))
54959 + return 0;
54960 +
54961 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54962 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54963 + return 0;
54964 + } else if (unlikely(!(mode & GR_EXEC))) {
54965 + return 0;
54966 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54967 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54968 + return 1;
54969 + }
54970 +
54971 + return 1;
54972 +}
54973 +
54974 +void
54975 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54976 +{
54977 + unsigned long runtime;
54978 + unsigned long cputime;
54979 + unsigned int wday, cday;
54980 + __u8 whr, chr;
54981 + __u8 wmin, cmin;
54982 + __u8 wsec, csec;
54983 + struct timespec timeval;
54984 +
54985 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54986 + !(task->acl->mode & GR_PROCACCT)))
54987 + return;
54988 +
54989 + do_posix_clock_monotonic_gettime(&timeval);
54990 + runtime = timeval.tv_sec - task->start_time.tv_sec;
54991 + wday = runtime / (3600 * 24);
54992 + runtime -= wday * (3600 * 24);
54993 + whr = runtime / 3600;
54994 + runtime -= whr * 3600;
54995 + wmin = runtime / 60;
54996 + runtime -= wmin * 60;
54997 + wsec = runtime;
54998 +
54999 + cputime = (task->utime + task->stime) / HZ;
55000 + cday = cputime / (3600 * 24);
55001 + cputime -= cday * (3600 * 24);
55002 + chr = cputime / 3600;
55003 + cputime -= chr * 3600;
55004 + cmin = cputime / 60;
55005 + cputime -= cmin * 60;
55006 + csec = cputime;
55007 +
55008 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55009 +
55010 + return;
55011 +}
55012 +
55013 +void gr_set_kernel_label(struct task_struct *task)
55014 +{
55015 + if (gr_status & GR_READY) {
55016 + task->role = kernel_role;
55017 + task->acl = kernel_role->root_label;
55018 + }
55019 + return;
55020 +}
55021 +
55022 +#ifdef CONFIG_TASKSTATS
55023 +int gr_is_taskstats_denied(int pid)
55024 +{
55025 + struct task_struct *task;
55026 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55027 + const struct cred *cred;
55028 +#endif
55029 + int ret = 0;
55030 +
55031 + /* restrict taskstats viewing to un-chrooted root users
55032 + who have the 'view' subject flag if the RBAC system is enabled
55033 + */
55034 +
55035 + rcu_read_lock();
55036 + read_lock(&tasklist_lock);
55037 + task = find_task_by_vpid(pid);
55038 + if (task) {
55039 +#ifdef CONFIG_GRKERNSEC_CHROOT
55040 + if (proc_is_chrooted(task))
55041 + ret = -EACCES;
55042 +#endif
55043 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55044 + cred = __task_cred(task);
55045 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55046 + if (cred->uid != 0)
55047 + ret = -EACCES;
55048 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55049 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55050 + ret = -EACCES;
55051 +#endif
55052 +#endif
55053 + if (gr_status & GR_READY) {
55054 + if (!(task->acl->mode & GR_VIEW))
55055 + ret = -EACCES;
55056 + }
55057 + } else
55058 + ret = -ENOENT;
55059 +
55060 + read_unlock(&tasklist_lock);
55061 + rcu_read_unlock();
55062 +
55063 + return ret;
55064 +}
55065 +#endif
55066 +
55067 +/* AUXV entries are filled via a descendant of search_binary_handler
55068 + after we've already applied the subject for the target
55069 +*/
55070 +int gr_acl_enable_at_secure(void)
55071 +{
55072 + if (unlikely(!(gr_status & GR_READY)))
55073 + return 0;
55074 +
55075 + if (current->acl->mode & GR_ATSECURE)
55076 + return 1;
55077 +
55078 + return 0;
55079 +}
55080 +
55081 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55082 +{
55083 + struct task_struct *task = current;
55084 + struct dentry *dentry = file->f_path.dentry;
55085 + struct vfsmount *mnt = file->f_path.mnt;
55086 + struct acl_object_label *obj, *tmp;
55087 + struct acl_subject_label *subj;
55088 + unsigned int bufsize;
55089 + int is_not_root;
55090 + char *path;
55091 + dev_t dev = __get_dev(dentry);
55092 +
55093 + if (unlikely(!(gr_status & GR_READY)))
55094 + return 1;
55095 +
55096 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55097 + return 1;
55098 +
55099 + /* ignore Eric Biederman */
55100 + if (IS_PRIVATE(dentry->d_inode))
55101 + return 1;
55102 +
55103 + subj = task->acl;
55104 + do {
55105 + obj = lookup_acl_obj_label(ino, dev, subj);
55106 + if (obj != NULL)
55107 + return (obj->mode & GR_FIND) ? 1 : 0;
55108 + } while ((subj = subj->parent_subject));
55109 +
55110 + /* this is purely an optimization since we're looking for an object
55111 + for the directory we're doing a readdir on
55112 + if it's possible for any globbed object to match the entry we're
55113 + filling into the directory, then the object we find here will be
55114 + an anchor point with attached globbed objects
55115 + */
55116 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55117 + if (obj->globbed == NULL)
55118 + return (obj->mode & GR_FIND) ? 1 : 0;
55119 +
55120 + is_not_root = ((obj->filename[0] == '/') &&
55121 + (obj->filename[1] == '\0')) ? 0 : 1;
55122 + bufsize = PAGE_SIZE - namelen - is_not_root;
55123 +
55124 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55125 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55126 + return 1;
55127 +
55128 + preempt_disable();
55129 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55130 + bufsize);
55131 +
55132 + bufsize = strlen(path);
55133 +
55134 + /* if base is "/", don't append an additional slash */
55135 + if (is_not_root)
55136 + *(path + bufsize) = '/';
55137 + memcpy(path + bufsize + is_not_root, name, namelen);
55138 + *(path + bufsize + namelen + is_not_root) = '\0';
55139 +
55140 + tmp = obj->globbed;
55141 + while (tmp) {
55142 + if (!glob_match(tmp->filename, path)) {
55143 + preempt_enable();
55144 + return (tmp->mode & GR_FIND) ? 1 : 0;
55145 + }
55146 + tmp = tmp->next;
55147 + }
55148 + preempt_enable();
55149 + return (obj->mode & GR_FIND) ? 1 : 0;
55150 +}
55151 +
55152 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55153 +EXPORT_SYMBOL(gr_acl_is_enabled);
55154 +#endif
55155 +EXPORT_SYMBOL(gr_learn_resource);
55156 +EXPORT_SYMBOL(gr_set_kernel_label);
55157 +#ifdef CONFIG_SECURITY
55158 +EXPORT_SYMBOL(gr_check_user_change);
55159 +EXPORT_SYMBOL(gr_check_group_change);
55160 +#endif
55161 +
55162 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55163 new file mode 100644
55164 index 0000000..34fefda
55165 --- /dev/null
55166 +++ b/grsecurity/gracl_alloc.c
55167 @@ -0,0 +1,105 @@
55168 +#include <linux/kernel.h>
55169 +#include <linux/mm.h>
55170 +#include <linux/slab.h>
55171 +#include <linux/vmalloc.h>
55172 +#include <linux/gracl.h>
55173 +#include <linux/grsecurity.h>
55174 +
55175 +static unsigned long alloc_stack_next = 1;
55176 +static unsigned long alloc_stack_size = 1;
55177 +static void **alloc_stack;
55178 +
55179 +static __inline__ int
55180 +alloc_pop(void)
55181 +{
55182 + if (alloc_stack_next == 1)
55183 + return 0;
55184 +
55185 + kfree(alloc_stack[alloc_stack_next - 2]);
55186 +
55187 + alloc_stack_next--;
55188 +
55189 + return 1;
55190 +}
55191 +
55192 +static __inline__ int
55193 +alloc_push(void *buf)
55194 +{
55195 + if (alloc_stack_next >= alloc_stack_size)
55196 + return 1;
55197 +
55198 + alloc_stack[alloc_stack_next - 1] = buf;
55199 +
55200 + alloc_stack_next++;
55201 +
55202 + return 0;
55203 +}
55204 +
55205 +void *
55206 +acl_alloc(unsigned long len)
55207 +{
55208 + void *ret = NULL;
55209 +
55210 + if (!len || len > PAGE_SIZE)
55211 + goto out;
55212 +
55213 + ret = kmalloc(len, GFP_KERNEL);
55214 +
55215 + if (ret) {
55216 + if (alloc_push(ret)) {
55217 + kfree(ret);
55218 + ret = NULL;
55219 + }
55220 + }
55221 +
55222 +out:
55223 + return ret;
55224 +}
55225 +
55226 +void *
55227 +acl_alloc_num(unsigned long num, unsigned long len)
55228 +{
55229 + if (!len || (num > (PAGE_SIZE / len)))
55230 + return NULL;
55231 +
55232 + return acl_alloc(num * len);
55233 +}
55234 +
55235 +void
55236 +acl_free_all(void)
55237 +{
55238 + if (gr_acl_is_enabled() || !alloc_stack)
55239 + return;
55240 +
55241 + while (alloc_pop()) ;
55242 +
55243 + if (alloc_stack) {
55244 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55245 + kfree(alloc_stack);
55246 + else
55247 + vfree(alloc_stack);
55248 + }
55249 +
55250 + alloc_stack = NULL;
55251 + alloc_stack_size = 1;
55252 + alloc_stack_next = 1;
55253 +
55254 + return;
55255 +}
55256 +
55257 +int
55258 +acl_alloc_stack_init(unsigned long size)
55259 +{
55260 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55261 + alloc_stack =
55262 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55263 + else
55264 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55265 +
55266 + alloc_stack_size = size;
55267 +
55268 + if (!alloc_stack)
55269 + return 0;
55270 + else
55271 + return 1;
55272 +}
55273 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55274 new file mode 100644
55275 index 0000000..6d21049
55276 --- /dev/null
55277 +++ b/grsecurity/gracl_cap.c
55278 @@ -0,0 +1,110 @@
55279 +#include <linux/kernel.h>
55280 +#include <linux/module.h>
55281 +#include <linux/sched.h>
55282 +#include <linux/gracl.h>
55283 +#include <linux/grsecurity.h>
55284 +#include <linux/grinternal.h>
55285 +
55286 +extern const char *captab_log[];
55287 +extern int captab_log_entries;
55288 +
55289 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55290 +{
55291 + struct acl_subject_label *curracl;
55292 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55293 + kernel_cap_t cap_audit = __cap_empty_set;
55294 +
55295 + if (!gr_acl_is_enabled())
55296 + return 1;
55297 +
55298 + curracl = task->acl;
55299 +
55300 + cap_drop = curracl->cap_lower;
55301 + cap_mask = curracl->cap_mask;
55302 + cap_audit = curracl->cap_invert_audit;
55303 +
55304 + while ((curracl = curracl->parent_subject)) {
55305 + /* if the cap isn't specified in the current computed mask but is specified in the
55306 + current level subject, and is lowered in the current level subject, then add
55307 + it to the set of dropped capabilities
55308 + otherwise, add the current level subject's mask to the current computed mask
55309 + */
55310 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55311 + cap_raise(cap_mask, cap);
55312 + if (cap_raised(curracl->cap_lower, cap))
55313 + cap_raise(cap_drop, cap);
55314 + if (cap_raised(curracl->cap_invert_audit, cap))
55315 + cap_raise(cap_audit, cap);
55316 + }
55317 + }
55318 +
55319 + if (!cap_raised(cap_drop, cap)) {
55320 + if (cap_raised(cap_audit, cap))
55321 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55322 + return 1;
55323 + }
55324 +
55325 + curracl = task->acl;
55326 +
55327 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55328 + && cap_raised(cred->cap_effective, cap)) {
55329 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55330 + task->role->roletype, cred->uid,
55331 + cred->gid, task->exec_file ?
55332 + gr_to_filename(task->exec_file->f_path.dentry,
55333 + task->exec_file->f_path.mnt) : curracl->filename,
55334 + curracl->filename, 0UL,
55335 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55336 + return 1;
55337 + }
55338 +
55339 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55340 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55341 +
55342 + return 0;
55343 +}
55344 +
55345 +int
55346 +gr_acl_is_capable(const int cap)
55347 +{
55348 + return gr_task_acl_is_capable(current, current_cred(), cap);
55349 +}
55350 +
55351 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55352 +{
55353 + struct acl_subject_label *curracl;
55354 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55355 +
55356 + if (!gr_acl_is_enabled())
55357 + return 1;
55358 +
55359 + curracl = task->acl;
55360 +
55361 + cap_drop = curracl->cap_lower;
55362 + cap_mask = curracl->cap_mask;
55363 +
55364 + while ((curracl = curracl->parent_subject)) {
55365 + /* if the cap isn't specified in the current computed mask but is specified in the
55366 + current level subject, and is lowered in the current level subject, then add
55367 + it to the set of dropped capabilities
55368 + otherwise, add the current level subject's mask to the current computed mask
55369 + */
55370 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55371 + cap_raise(cap_mask, cap);
55372 + if (cap_raised(curracl->cap_lower, cap))
55373 + cap_raise(cap_drop, cap);
55374 + }
55375 + }
55376 +
55377 + if (!cap_raised(cap_drop, cap))
55378 + return 1;
55379 +
55380 + return 0;
55381 +}
55382 +
55383 +int
55384 +gr_acl_is_capable_nolog(const int cap)
55385 +{
55386 + return gr_task_acl_is_capable_nolog(current, cap);
55387 +}
55388 +
55389 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55390 new file mode 100644
55391 index 0000000..88d0e87
55392 --- /dev/null
55393 +++ b/grsecurity/gracl_fs.c
55394 @@ -0,0 +1,435 @@
55395 +#include <linux/kernel.h>
55396 +#include <linux/sched.h>
55397 +#include <linux/types.h>
55398 +#include <linux/fs.h>
55399 +#include <linux/file.h>
55400 +#include <linux/stat.h>
55401 +#include <linux/grsecurity.h>
55402 +#include <linux/grinternal.h>
55403 +#include <linux/gracl.h>
55404 +
55405 +umode_t
55406 +gr_acl_umask(void)
55407 +{
55408 + if (unlikely(!gr_acl_is_enabled()))
55409 + return 0;
55410 +
55411 + return current->role->umask;
55412 +}
55413 +
55414 +__u32
55415 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55416 + const struct vfsmount * mnt)
55417 +{
55418 + __u32 mode;
55419 +
55420 + if (unlikely(!dentry->d_inode))
55421 + return GR_FIND;
55422 +
55423 + mode =
55424 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55425 +
55426 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55427 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55428 + return mode;
55429 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55430 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55431 + return 0;
55432 + } else if (unlikely(!(mode & GR_FIND)))
55433 + return 0;
55434 +
55435 + return GR_FIND;
55436 +}
55437 +
55438 +__u32
55439 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55440 + int acc_mode)
55441 +{
55442 + __u32 reqmode = GR_FIND;
55443 + __u32 mode;
55444 +
55445 + if (unlikely(!dentry->d_inode))
55446 + return reqmode;
55447 +
55448 + if (acc_mode & MAY_APPEND)
55449 + reqmode |= GR_APPEND;
55450 + else if (acc_mode & MAY_WRITE)
55451 + reqmode |= GR_WRITE;
55452 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55453 + reqmode |= GR_READ;
55454 +
55455 + mode =
55456 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55457 + mnt);
55458 +
55459 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55460 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55461 + reqmode & GR_READ ? " reading" : "",
55462 + reqmode & GR_WRITE ? " writing" : reqmode &
55463 + GR_APPEND ? " appending" : "");
55464 + return reqmode;
55465 + } else
55466 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55467 + {
55468 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55469 + reqmode & GR_READ ? " reading" : "",
55470 + reqmode & GR_WRITE ? " writing" : reqmode &
55471 + GR_APPEND ? " appending" : "");
55472 + return 0;
55473 + } else if (unlikely((mode & reqmode) != reqmode))
55474 + return 0;
55475 +
55476 + return reqmode;
55477 +}
55478 +
55479 +__u32
55480 +gr_acl_handle_creat(const struct dentry * dentry,
55481 + const struct dentry * p_dentry,
55482 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55483 + const int imode)
55484 +{
55485 + __u32 reqmode = GR_WRITE | GR_CREATE;
55486 + __u32 mode;
55487 +
55488 + if (acc_mode & MAY_APPEND)
55489 + reqmode |= GR_APPEND;
55490 + // if a directory was required or the directory already exists, then
55491 + // don't count this open as a read
55492 + if ((acc_mode & MAY_READ) &&
55493 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55494 + reqmode |= GR_READ;
55495 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55496 + reqmode |= GR_SETID;
55497 +
55498 + mode =
55499 + gr_check_create(dentry, p_dentry, p_mnt,
55500 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55501 +
55502 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55503 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55504 + reqmode & GR_READ ? " reading" : "",
55505 + reqmode & GR_WRITE ? " writing" : reqmode &
55506 + GR_APPEND ? " appending" : "");
55507 + return reqmode;
55508 + } else
55509 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55510 + {
55511 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55512 + reqmode & GR_READ ? " reading" : "",
55513 + reqmode & GR_WRITE ? " writing" : reqmode &
55514 + GR_APPEND ? " appending" : "");
55515 + return 0;
55516 + } else if (unlikely((mode & reqmode) != reqmode))
55517 + return 0;
55518 +
55519 + return reqmode;
55520 +}
55521 +
55522 +__u32
55523 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55524 + const int fmode)
55525 +{
55526 + __u32 mode, reqmode = GR_FIND;
55527 +
55528 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55529 + reqmode |= GR_EXEC;
55530 + if (fmode & S_IWOTH)
55531 + reqmode |= GR_WRITE;
55532 + if (fmode & S_IROTH)
55533 + reqmode |= GR_READ;
55534 +
55535 + mode =
55536 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55537 + mnt);
55538 +
55539 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55540 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55541 + reqmode & GR_READ ? " reading" : "",
55542 + reqmode & GR_WRITE ? " writing" : "",
55543 + reqmode & GR_EXEC ? " executing" : "");
55544 + return reqmode;
55545 + } else
55546 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55547 + {
55548 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55549 + reqmode & GR_READ ? " reading" : "",
55550 + reqmode & GR_WRITE ? " writing" : "",
55551 + reqmode & GR_EXEC ? " executing" : "");
55552 + return 0;
55553 + } else if (unlikely((mode & reqmode) != reqmode))
55554 + return 0;
55555 +
55556 + return reqmode;
55557 +}
55558 +
55559 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55560 +{
55561 + __u32 mode;
55562 +
55563 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55564 +
55565 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55566 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55567 + return mode;
55568 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55569 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55570 + return 0;
55571 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55572 + return 0;
55573 +
55574 + return (reqmode);
55575 +}
55576 +
55577 +__u32
55578 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55579 +{
55580 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55581 +}
55582 +
55583 +__u32
55584 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55585 +{
55586 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55587 +}
55588 +
55589 +__u32
55590 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55591 +{
55592 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55593 +}
55594 +
55595 +__u32
55596 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55597 +{
55598 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55599 +}
55600 +
55601 +__u32
55602 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55603 + umode_t *modeptr)
55604 +{
55605 + umode_t mode;
55606 +
55607 + *modeptr &= ~gr_acl_umask();
55608 + mode = *modeptr;
55609 +
55610 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55611 + return 1;
55612 +
55613 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
55614 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55615 + GR_CHMOD_ACL_MSG);
55616 + } else {
55617 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55618 + }
55619 +}
55620 +
55621 +__u32
55622 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55623 +{
55624 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55625 +}
55626 +
55627 +__u32
55628 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55629 +{
55630 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55631 +}
55632 +
55633 +__u32
55634 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55635 +{
55636 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55637 +}
55638 +
55639 +__u32
55640 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55641 +{
55642 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55643 + GR_UNIXCONNECT_ACL_MSG);
55644 +}
55645 +
55646 +/* hardlinks require at minimum create and link permission,
55647 + any additional privilege required is based on the
55648 + privilege of the file being linked to
55649 +*/
55650 +__u32
55651 +gr_acl_handle_link(const struct dentry * new_dentry,
55652 + const struct dentry * parent_dentry,
55653 + const struct vfsmount * parent_mnt,
55654 + const struct dentry * old_dentry,
55655 + const struct vfsmount * old_mnt, const char *to)
55656 +{
55657 + __u32 mode;
55658 + __u32 needmode = GR_CREATE | GR_LINK;
55659 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55660 +
55661 + mode =
55662 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55663 + old_mnt);
55664 +
55665 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55666 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55667 + return mode;
55668 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55669 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55670 + return 0;
55671 + } else if (unlikely((mode & needmode) != needmode))
55672 + return 0;
55673 +
55674 + return 1;
55675 +}
55676 +
55677 +__u32
55678 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55679 + const struct dentry * parent_dentry,
55680 + const struct vfsmount * parent_mnt, const char *from)
55681 +{
55682 + __u32 needmode = GR_WRITE | GR_CREATE;
55683 + __u32 mode;
55684 +
55685 + mode =
55686 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55687 + GR_CREATE | GR_AUDIT_CREATE |
55688 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55689 +
55690 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55691 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55692 + return mode;
55693 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55694 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55695 + return 0;
55696 + } else if (unlikely((mode & needmode) != needmode))
55697 + return 0;
55698 +
55699 + return (GR_WRITE | GR_CREATE);
55700 +}
55701 +
55702 +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)
55703 +{
55704 + __u32 mode;
55705 +
55706 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55707 +
55708 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55709 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55710 + return mode;
55711 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55712 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55713 + return 0;
55714 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55715 + return 0;
55716 +
55717 + return (reqmode);
55718 +}
55719 +
55720 +__u32
55721 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55722 + const struct dentry * parent_dentry,
55723 + const struct vfsmount * parent_mnt,
55724 + const int mode)
55725 +{
55726 + __u32 reqmode = GR_WRITE | GR_CREATE;
55727 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55728 + reqmode |= GR_SETID;
55729 +
55730 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55731 + reqmode, GR_MKNOD_ACL_MSG);
55732 +}
55733 +
55734 +__u32
55735 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55736 + const struct dentry *parent_dentry,
55737 + const struct vfsmount *parent_mnt)
55738 +{
55739 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55740 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55741 +}
55742 +
55743 +#define RENAME_CHECK_SUCCESS(old, new) \
55744 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55745 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55746 +
55747 +int
55748 +gr_acl_handle_rename(struct dentry *new_dentry,
55749 + struct dentry *parent_dentry,
55750 + const struct vfsmount *parent_mnt,
55751 + struct dentry *old_dentry,
55752 + struct inode *old_parent_inode,
55753 + struct vfsmount *old_mnt, const char *newname)
55754 +{
55755 + __u32 comp1, comp2;
55756 + int error = 0;
55757 +
55758 + if (unlikely(!gr_acl_is_enabled()))
55759 + return 0;
55760 +
55761 + if (!new_dentry->d_inode) {
55762 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55763 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55764 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55765 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55766 + GR_DELETE | GR_AUDIT_DELETE |
55767 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55768 + GR_SUPPRESS, old_mnt);
55769 + } else {
55770 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55771 + GR_CREATE | GR_DELETE |
55772 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55773 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55774 + GR_SUPPRESS, parent_mnt);
55775 + comp2 =
55776 + gr_search_file(old_dentry,
55777 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55778 + GR_DELETE | GR_AUDIT_DELETE |
55779 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55780 + }
55781 +
55782 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55783 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55784 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55785 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55786 + && !(comp2 & GR_SUPPRESS)) {
55787 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55788 + error = -EACCES;
55789 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55790 + error = -EACCES;
55791 +
55792 + return error;
55793 +}
55794 +
55795 +void
55796 +gr_acl_handle_exit(void)
55797 +{
55798 + u16 id;
55799 + char *rolename;
55800 + struct file *exec_file;
55801 +
55802 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55803 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55804 + id = current->acl_role_id;
55805 + rolename = current->role->rolename;
55806 + gr_set_acls(1);
55807 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55808 + }
55809 +
55810 + write_lock(&grsec_exec_file_lock);
55811 + exec_file = current->exec_file;
55812 + current->exec_file = NULL;
55813 + write_unlock(&grsec_exec_file_lock);
55814 +
55815 + if (exec_file)
55816 + fput(exec_file);
55817 +}
55818 +
55819 +int
55820 +gr_acl_handle_procpidmem(const struct task_struct *task)
55821 +{
55822 + if (unlikely(!gr_acl_is_enabled()))
55823 + return 0;
55824 +
55825 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55826 + return -EACCES;
55827 +
55828 + return 0;
55829 +}
55830 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55831 new file mode 100644
55832 index 0000000..58800a7
55833 --- /dev/null
55834 +++ b/grsecurity/gracl_ip.c
55835 @@ -0,0 +1,384 @@
55836 +#include <linux/kernel.h>
55837 +#include <asm/uaccess.h>
55838 +#include <asm/errno.h>
55839 +#include <net/sock.h>
55840 +#include <linux/file.h>
55841 +#include <linux/fs.h>
55842 +#include <linux/net.h>
55843 +#include <linux/in.h>
55844 +#include <linux/skbuff.h>
55845 +#include <linux/ip.h>
55846 +#include <linux/udp.h>
55847 +#include <linux/types.h>
55848 +#include <linux/sched.h>
55849 +#include <linux/netdevice.h>
55850 +#include <linux/inetdevice.h>
55851 +#include <linux/gracl.h>
55852 +#include <linux/grsecurity.h>
55853 +#include <linux/grinternal.h>
55854 +
55855 +#define GR_BIND 0x01
55856 +#define GR_CONNECT 0x02
55857 +#define GR_INVERT 0x04
55858 +#define GR_BINDOVERRIDE 0x08
55859 +#define GR_CONNECTOVERRIDE 0x10
55860 +#define GR_SOCK_FAMILY 0x20
55861 +
55862 +static const char * gr_protocols[IPPROTO_MAX] = {
55863 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55864 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55865 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55866 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55867 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55868 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55869 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55870 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55871 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55872 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55873 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55874 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55875 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55876 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55877 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55878 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55879 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55880 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55881 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55882 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55883 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55884 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55885 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55886 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55887 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55888 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55889 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55890 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55891 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55892 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55893 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55894 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55895 + };
55896 +
55897 +static const char * gr_socktypes[SOCK_MAX] = {
55898 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55899 + "unknown:7", "unknown:8", "unknown:9", "packet"
55900 + };
55901 +
55902 +static const char * gr_sockfamilies[AF_MAX+1] = {
55903 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55904 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55905 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55906 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55907 + };
55908 +
55909 +const char *
55910 +gr_proto_to_name(unsigned char proto)
55911 +{
55912 + return gr_protocols[proto];
55913 +}
55914 +
55915 +const char *
55916 +gr_socktype_to_name(unsigned char type)
55917 +{
55918 + return gr_socktypes[type];
55919 +}
55920 +
55921 +const char *
55922 +gr_sockfamily_to_name(unsigned char family)
55923 +{
55924 + return gr_sockfamilies[family];
55925 +}
55926 +
55927 +int
55928 +gr_search_socket(const int domain, const int type, const int protocol)
55929 +{
55930 + struct acl_subject_label *curr;
55931 + const struct cred *cred = current_cred();
55932 +
55933 + if (unlikely(!gr_acl_is_enabled()))
55934 + goto exit;
55935 +
55936 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
55937 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55938 + goto exit; // let the kernel handle it
55939 +
55940 + curr = current->acl;
55941 +
55942 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55943 + /* the family is allowed, if this is PF_INET allow it only if
55944 + the extra sock type/protocol checks pass */
55945 + if (domain == PF_INET)
55946 + goto inet_check;
55947 + goto exit;
55948 + } else {
55949 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55950 + __u32 fakeip = 0;
55951 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55952 + current->role->roletype, cred->uid,
55953 + cred->gid, current->exec_file ?
55954 + gr_to_filename(current->exec_file->f_path.dentry,
55955 + current->exec_file->f_path.mnt) :
55956 + curr->filename, curr->filename,
55957 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55958 + &current->signal->saved_ip);
55959 + goto exit;
55960 + }
55961 + goto exit_fail;
55962 + }
55963 +
55964 +inet_check:
55965 + /* the rest of this checking is for IPv4 only */
55966 + if (!curr->ips)
55967 + goto exit;
55968 +
55969 + if ((curr->ip_type & (1 << type)) &&
55970 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55971 + goto exit;
55972 +
55973 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55974 + /* we don't place acls on raw sockets , and sometimes
55975 + dgram/ip sockets are opened for ioctl and not
55976 + bind/connect, so we'll fake a bind learn log */
55977 + if (type == SOCK_RAW || type == SOCK_PACKET) {
55978 + __u32 fakeip = 0;
55979 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55980 + current->role->roletype, cred->uid,
55981 + cred->gid, current->exec_file ?
55982 + gr_to_filename(current->exec_file->f_path.dentry,
55983 + current->exec_file->f_path.mnt) :
55984 + curr->filename, curr->filename,
55985 + &fakeip, 0, type,
55986 + protocol, GR_CONNECT, &current->signal->saved_ip);
55987 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55988 + __u32 fakeip = 0;
55989 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55990 + current->role->roletype, cred->uid,
55991 + cred->gid, current->exec_file ?
55992 + gr_to_filename(current->exec_file->f_path.dentry,
55993 + current->exec_file->f_path.mnt) :
55994 + curr->filename, curr->filename,
55995 + &fakeip, 0, type,
55996 + protocol, GR_BIND, &current->signal->saved_ip);
55997 + }
55998 + /* we'll log when they use connect or bind */
55999 + goto exit;
56000 + }
56001 +
56002 +exit_fail:
56003 + if (domain == PF_INET)
56004 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56005 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56006 + else
56007 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56008 + gr_socktype_to_name(type), protocol);
56009 +
56010 + return 0;
56011 +exit:
56012 + return 1;
56013 +}
56014 +
56015 +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)
56016 +{
56017 + if ((ip->mode & mode) &&
56018 + (ip_port >= ip->low) &&
56019 + (ip_port <= ip->high) &&
56020 + ((ntohl(ip_addr) & our_netmask) ==
56021 + (ntohl(our_addr) & our_netmask))
56022 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56023 + && (ip->type & (1 << type))) {
56024 + if (ip->mode & GR_INVERT)
56025 + return 2; // specifically denied
56026 + else
56027 + return 1; // allowed
56028 + }
56029 +
56030 + return 0; // not specifically allowed, may continue parsing
56031 +}
56032 +
56033 +static int
56034 +gr_search_connectbind(const int full_mode, struct sock *sk,
56035 + struct sockaddr_in *addr, const int type)
56036 +{
56037 + char iface[IFNAMSIZ] = {0};
56038 + struct acl_subject_label *curr;
56039 + struct acl_ip_label *ip;
56040 + struct inet_sock *isk;
56041 + struct net_device *dev;
56042 + struct in_device *idev;
56043 + unsigned long i;
56044 + int ret;
56045 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56046 + __u32 ip_addr = 0;
56047 + __u32 our_addr;
56048 + __u32 our_netmask;
56049 + char *p;
56050 + __u16 ip_port = 0;
56051 + const struct cred *cred = current_cred();
56052 +
56053 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56054 + return 0;
56055 +
56056 + curr = current->acl;
56057 + isk = inet_sk(sk);
56058 +
56059 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56060 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56061 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56062 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56063 + struct sockaddr_in saddr;
56064 + int err;
56065 +
56066 + saddr.sin_family = AF_INET;
56067 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56068 + saddr.sin_port = isk->inet_sport;
56069 +
56070 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56071 + if (err)
56072 + return err;
56073 +
56074 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56075 + if (err)
56076 + return err;
56077 + }
56078 +
56079 + if (!curr->ips)
56080 + return 0;
56081 +
56082 + ip_addr = addr->sin_addr.s_addr;
56083 + ip_port = ntohs(addr->sin_port);
56084 +
56085 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56086 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56087 + current->role->roletype, cred->uid,
56088 + cred->gid, current->exec_file ?
56089 + gr_to_filename(current->exec_file->f_path.dentry,
56090 + current->exec_file->f_path.mnt) :
56091 + curr->filename, curr->filename,
56092 + &ip_addr, ip_port, type,
56093 + sk->sk_protocol, mode, &current->signal->saved_ip);
56094 + return 0;
56095 + }
56096 +
56097 + for (i = 0; i < curr->ip_num; i++) {
56098 + ip = *(curr->ips + i);
56099 + if (ip->iface != NULL) {
56100 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56101 + p = strchr(iface, ':');
56102 + if (p != NULL)
56103 + *p = '\0';
56104 + dev = dev_get_by_name(sock_net(sk), iface);
56105 + if (dev == NULL)
56106 + continue;
56107 + idev = in_dev_get(dev);
56108 + if (idev == NULL) {
56109 + dev_put(dev);
56110 + continue;
56111 + }
56112 + rcu_read_lock();
56113 + for_ifa(idev) {
56114 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56115 + our_addr = ifa->ifa_address;
56116 + our_netmask = 0xffffffff;
56117 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56118 + if (ret == 1) {
56119 + rcu_read_unlock();
56120 + in_dev_put(idev);
56121 + dev_put(dev);
56122 + return 0;
56123 + } else if (ret == 2) {
56124 + rcu_read_unlock();
56125 + in_dev_put(idev);
56126 + dev_put(dev);
56127 + goto denied;
56128 + }
56129 + }
56130 + } endfor_ifa(idev);
56131 + rcu_read_unlock();
56132 + in_dev_put(idev);
56133 + dev_put(dev);
56134 + } else {
56135 + our_addr = ip->addr;
56136 + our_netmask = ip->netmask;
56137 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56138 + if (ret == 1)
56139 + return 0;
56140 + else if (ret == 2)
56141 + goto denied;
56142 + }
56143 + }
56144 +
56145 +denied:
56146 + if (mode == GR_BIND)
56147 + 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));
56148 + else if (mode == GR_CONNECT)
56149 + 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));
56150 +
56151 + return -EACCES;
56152 +}
56153 +
56154 +int
56155 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56156 +{
56157 + /* always allow disconnection of dgram sockets with connect */
56158 + if (addr->sin_family == AF_UNSPEC)
56159 + return 0;
56160 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56161 +}
56162 +
56163 +int
56164 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56165 +{
56166 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56167 +}
56168 +
56169 +int gr_search_listen(struct socket *sock)
56170 +{
56171 + struct sock *sk = sock->sk;
56172 + struct sockaddr_in addr;
56173 +
56174 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56175 + addr.sin_port = inet_sk(sk)->inet_sport;
56176 +
56177 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56178 +}
56179 +
56180 +int gr_search_accept(struct socket *sock)
56181 +{
56182 + struct sock *sk = sock->sk;
56183 + struct sockaddr_in addr;
56184 +
56185 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56186 + addr.sin_port = inet_sk(sk)->inet_sport;
56187 +
56188 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56189 +}
56190 +
56191 +int
56192 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56193 +{
56194 + if (addr)
56195 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56196 + else {
56197 + struct sockaddr_in sin;
56198 + const struct inet_sock *inet = inet_sk(sk);
56199 +
56200 + sin.sin_addr.s_addr = inet->inet_daddr;
56201 + sin.sin_port = inet->inet_dport;
56202 +
56203 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56204 + }
56205 +}
56206 +
56207 +int
56208 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56209 +{
56210 + struct sockaddr_in sin;
56211 +
56212 + if (unlikely(skb->len < sizeof (struct udphdr)))
56213 + return 0; // skip this packet
56214 +
56215 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56216 + sin.sin_port = udp_hdr(skb)->source;
56217 +
56218 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56219 +}
56220 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56221 new file mode 100644
56222 index 0000000..25f54ef
56223 --- /dev/null
56224 +++ b/grsecurity/gracl_learn.c
56225 @@ -0,0 +1,207 @@
56226 +#include <linux/kernel.h>
56227 +#include <linux/mm.h>
56228 +#include <linux/sched.h>
56229 +#include <linux/poll.h>
56230 +#include <linux/string.h>
56231 +#include <linux/file.h>
56232 +#include <linux/types.h>
56233 +#include <linux/vmalloc.h>
56234 +#include <linux/grinternal.h>
56235 +
56236 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56237 + size_t count, loff_t *ppos);
56238 +extern int gr_acl_is_enabled(void);
56239 +
56240 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56241 +static int gr_learn_attached;
56242 +
56243 +/* use a 512k buffer */
56244 +#define LEARN_BUFFER_SIZE (512 * 1024)
56245 +
56246 +static DEFINE_SPINLOCK(gr_learn_lock);
56247 +static DEFINE_MUTEX(gr_learn_user_mutex);
56248 +
56249 +/* we need to maintain two buffers, so that the kernel context of grlearn
56250 + uses a semaphore around the userspace copying, and the other kernel contexts
56251 + use a spinlock when copying into the buffer, since they cannot sleep
56252 +*/
56253 +static char *learn_buffer;
56254 +static char *learn_buffer_user;
56255 +static int learn_buffer_len;
56256 +static int learn_buffer_user_len;
56257 +
56258 +static ssize_t
56259 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56260 +{
56261 + DECLARE_WAITQUEUE(wait, current);
56262 + ssize_t retval = 0;
56263 +
56264 + add_wait_queue(&learn_wait, &wait);
56265 + set_current_state(TASK_INTERRUPTIBLE);
56266 + do {
56267 + mutex_lock(&gr_learn_user_mutex);
56268 + spin_lock(&gr_learn_lock);
56269 + if (learn_buffer_len)
56270 + break;
56271 + spin_unlock(&gr_learn_lock);
56272 + mutex_unlock(&gr_learn_user_mutex);
56273 + if (file->f_flags & O_NONBLOCK) {
56274 + retval = -EAGAIN;
56275 + goto out;
56276 + }
56277 + if (signal_pending(current)) {
56278 + retval = -ERESTARTSYS;
56279 + goto out;
56280 + }
56281 +
56282 + schedule();
56283 + } while (1);
56284 +
56285 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56286 + learn_buffer_user_len = learn_buffer_len;
56287 + retval = learn_buffer_len;
56288 + learn_buffer_len = 0;
56289 +
56290 + spin_unlock(&gr_learn_lock);
56291 +
56292 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56293 + retval = -EFAULT;
56294 +
56295 + mutex_unlock(&gr_learn_user_mutex);
56296 +out:
56297 + set_current_state(TASK_RUNNING);
56298 + remove_wait_queue(&learn_wait, &wait);
56299 + return retval;
56300 +}
56301 +
56302 +static unsigned int
56303 +poll_learn(struct file * file, poll_table * wait)
56304 +{
56305 + poll_wait(file, &learn_wait, wait);
56306 +
56307 + if (learn_buffer_len)
56308 + return (POLLIN | POLLRDNORM);
56309 +
56310 + return 0;
56311 +}
56312 +
56313 +void
56314 +gr_clear_learn_entries(void)
56315 +{
56316 + char *tmp;
56317 +
56318 + mutex_lock(&gr_learn_user_mutex);
56319 + spin_lock(&gr_learn_lock);
56320 + tmp = learn_buffer;
56321 + learn_buffer = NULL;
56322 + spin_unlock(&gr_learn_lock);
56323 + if (tmp)
56324 + vfree(tmp);
56325 + if (learn_buffer_user != NULL) {
56326 + vfree(learn_buffer_user);
56327 + learn_buffer_user = NULL;
56328 + }
56329 + learn_buffer_len = 0;
56330 + mutex_unlock(&gr_learn_user_mutex);
56331 +
56332 + return;
56333 +}
56334 +
56335 +void
56336 +gr_add_learn_entry(const char *fmt, ...)
56337 +{
56338 + va_list args;
56339 + unsigned int len;
56340 +
56341 + if (!gr_learn_attached)
56342 + return;
56343 +
56344 + spin_lock(&gr_learn_lock);
56345 +
56346 + /* leave a gap at the end so we know when it's "full" but don't have to
56347 + compute the exact length of the string we're trying to append
56348 + */
56349 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56350 + spin_unlock(&gr_learn_lock);
56351 + wake_up_interruptible(&learn_wait);
56352 + return;
56353 + }
56354 + if (learn_buffer == NULL) {
56355 + spin_unlock(&gr_learn_lock);
56356 + return;
56357 + }
56358 +
56359 + va_start(args, fmt);
56360 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56361 + va_end(args);
56362 +
56363 + learn_buffer_len += len + 1;
56364 +
56365 + spin_unlock(&gr_learn_lock);
56366 + wake_up_interruptible(&learn_wait);
56367 +
56368 + return;
56369 +}
56370 +
56371 +static int
56372 +open_learn(struct inode *inode, struct file *file)
56373 +{
56374 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56375 + return -EBUSY;
56376 + if (file->f_mode & FMODE_READ) {
56377 + int retval = 0;
56378 + mutex_lock(&gr_learn_user_mutex);
56379 + if (learn_buffer == NULL)
56380 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56381 + if (learn_buffer_user == NULL)
56382 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56383 + if (learn_buffer == NULL) {
56384 + retval = -ENOMEM;
56385 + goto out_error;
56386 + }
56387 + if (learn_buffer_user == NULL) {
56388 + retval = -ENOMEM;
56389 + goto out_error;
56390 + }
56391 + learn_buffer_len = 0;
56392 + learn_buffer_user_len = 0;
56393 + gr_learn_attached = 1;
56394 +out_error:
56395 + mutex_unlock(&gr_learn_user_mutex);
56396 + return retval;
56397 + }
56398 + return 0;
56399 +}
56400 +
56401 +static int
56402 +close_learn(struct inode *inode, struct file *file)
56403 +{
56404 + if (file->f_mode & FMODE_READ) {
56405 + char *tmp = NULL;
56406 + mutex_lock(&gr_learn_user_mutex);
56407 + spin_lock(&gr_learn_lock);
56408 + tmp = learn_buffer;
56409 + learn_buffer = NULL;
56410 + spin_unlock(&gr_learn_lock);
56411 + if (tmp)
56412 + vfree(tmp);
56413 + if (learn_buffer_user != NULL) {
56414 + vfree(learn_buffer_user);
56415 + learn_buffer_user = NULL;
56416 + }
56417 + learn_buffer_len = 0;
56418 + learn_buffer_user_len = 0;
56419 + gr_learn_attached = 0;
56420 + mutex_unlock(&gr_learn_user_mutex);
56421 + }
56422 +
56423 + return 0;
56424 +}
56425 +
56426 +const struct file_operations grsec_fops = {
56427 + .read = read_learn,
56428 + .write = write_grsec_handler,
56429 + .open = open_learn,
56430 + .release = close_learn,
56431 + .poll = poll_learn,
56432 +};
56433 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56434 new file mode 100644
56435 index 0000000..39645c9
56436 --- /dev/null
56437 +++ b/grsecurity/gracl_res.c
56438 @@ -0,0 +1,68 @@
56439 +#include <linux/kernel.h>
56440 +#include <linux/sched.h>
56441 +#include <linux/gracl.h>
56442 +#include <linux/grinternal.h>
56443 +
56444 +static const char *restab_log[] = {
56445 + [RLIMIT_CPU] = "RLIMIT_CPU",
56446 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56447 + [RLIMIT_DATA] = "RLIMIT_DATA",
56448 + [RLIMIT_STACK] = "RLIMIT_STACK",
56449 + [RLIMIT_CORE] = "RLIMIT_CORE",
56450 + [RLIMIT_RSS] = "RLIMIT_RSS",
56451 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56452 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56453 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56454 + [RLIMIT_AS] = "RLIMIT_AS",
56455 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56456 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56457 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56458 + [RLIMIT_NICE] = "RLIMIT_NICE",
56459 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56460 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56461 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56462 +};
56463 +
56464 +void
56465 +gr_log_resource(const struct task_struct *task,
56466 + const int res, const unsigned long wanted, const int gt)
56467 +{
56468 + const struct cred *cred;
56469 + unsigned long rlim;
56470 +
56471 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56472 + return;
56473 +
56474 + // not yet supported resource
56475 + if (unlikely(!restab_log[res]))
56476 + return;
56477 +
56478 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56479 + rlim = task_rlimit_max(task, res);
56480 + else
56481 + rlim = task_rlimit(task, res);
56482 +
56483 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56484 + return;
56485 +
56486 + rcu_read_lock();
56487 + cred = __task_cred(task);
56488 +
56489 + if (res == RLIMIT_NPROC &&
56490 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56491 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56492 + goto out_rcu_unlock;
56493 + else if (res == RLIMIT_MEMLOCK &&
56494 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56495 + goto out_rcu_unlock;
56496 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56497 + goto out_rcu_unlock;
56498 + rcu_read_unlock();
56499 +
56500 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56501 +
56502 + return;
56503 +out_rcu_unlock:
56504 + rcu_read_unlock();
56505 + return;
56506 +}
56507 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56508 new file mode 100644
56509 index 0000000..5556be3
56510 --- /dev/null
56511 +++ b/grsecurity/gracl_segv.c
56512 @@ -0,0 +1,299 @@
56513 +#include <linux/kernel.h>
56514 +#include <linux/mm.h>
56515 +#include <asm/uaccess.h>
56516 +#include <asm/errno.h>
56517 +#include <asm/mman.h>
56518 +#include <net/sock.h>
56519 +#include <linux/file.h>
56520 +#include <linux/fs.h>
56521 +#include <linux/net.h>
56522 +#include <linux/in.h>
56523 +#include <linux/slab.h>
56524 +#include <linux/types.h>
56525 +#include <linux/sched.h>
56526 +#include <linux/timer.h>
56527 +#include <linux/gracl.h>
56528 +#include <linux/grsecurity.h>
56529 +#include <linux/grinternal.h>
56530 +
56531 +static struct crash_uid *uid_set;
56532 +static unsigned short uid_used;
56533 +static DEFINE_SPINLOCK(gr_uid_lock);
56534 +extern rwlock_t gr_inode_lock;
56535 +extern struct acl_subject_label *
56536 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56537 + struct acl_role_label *role);
56538 +
56539 +#ifdef CONFIG_BTRFS_FS
56540 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56541 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56542 +#endif
56543 +
56544 +static inline dev_t __get_dev(const struct dentry *dentry)
56545 +{
56546 +#ifdef CONFIG_BTRFS_FS
56547 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56548 + return get_btrfs_dev_from_inode(dentry->d_inode);
56549 + else
56550 +#endif
56551 + return dentry->d_inode->i_sb->s_dev;
56552 +}
56553 +
56554 +int
56555 +gr_init_uidset(void)
56556 +{
56557 + uid_set =
56558 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56559 + uid_used = 0;
56560 +
56561 + return uid_set ? 1 : 0;
56562 +}
56563 +
56564 +void
56565 +gr_free_uidset(void)
56566 +{
56567 + if (uid_set)
56568 + kfree(uid_set);
56569 +
56570 + return;
56571 +}
56572 +
56573 +int
56574 +gr_find_uid(const uid_t uid)
56575 +{
56576 + struct crash_uid *tmp = uid_set;
56577 + uid_t buid;
56578 + int low = 0, high = uid_used - 1, mid;
56579 +
56580 + while (high >= low) {
56581 + mid = (low + high) >> 1;
56582 + buid = tmp[mid].uid;
56583 + if (buid == uid)
56584 + return mid;
56585 + if (buid > uid)
56586 + high = mid - 1;
56587 + if (buid < uid)
56588 + low = mid + 1;
56589 + }
56590 +
56591 + return -1;
56592 +}
56593 +
56594 +static __inline__ void
56595 +gr_insertsort(void)
56596 +{
56597 + unsigned short i, j;
56598 + struct crash_uid index;
56599 +
56600 + for (i = 1; i < uid_used; i++) {
56601 + index = uid_set[i];
56602 + j = i;
56603 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56604 + uid_set[j] = uid_set[j - 1];
56605 + j--;
56606 + }
56607 + uid_set[j] = index;
56608 + }
56609 +
56610 + return;
56611 +}
56612 +
56613 +static __inline__ void
56614 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56615 +{
56616 + int loc;
56617 +
56618 + if (uid_used == GR_UIDTABLE_MAX)
56619 + return;
56620 +
56621 + loc = gr_find_uid(uid);
56622 +
56623 + if (loc >= 0) {
56624 + uid_set[loc].expires = expires;
56625 + return;
56626 + }
56627 +
56628 + uid_set[uid_used].uid = uid;
56629 + uid_set[uid_used].expires = expires;
56630 + uid_used++;
56631 +
56632 + gr_insertsort();
56633 +
56634 + return;
56635 +}
56636 +
56637 +void
56638 +gr_remove_uid(const unsigned short loc)
56639 +{
56640 + unsigned short i;
56641 +
56642 + for (i = loc + 1; i < uid_used; i++)
56643 + uid_set[i - 1] = uid_set[i];
56644 +
56645 + uid_used--;
56646 +
56647 + return;
56648 +}
56649 +
56650 +int
56651 +gr_check_crash_uid(const uid_t uid)
56652 +{
56653 + int loc;
56654 + int ret = 0;
56655 +
56656 + if (unlikely(!gr_acl_is_enabled()))
56657 + return 0;
56658 +
56659 + spin_lock(&gr_uid_lock);
56660 + loc = gr_find_uid(uid);
56661 +
56662 + if (loc < 0)
56663 + goto out_unlock;
56664 +
56665 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56666 + gr_remove_uid(loc);
56667 + else
56668 + ret = 1;
56669 +
56670 +out_unlock:
56671 + spin_unlock(&gr_uid_lock);
56672 + return ret;
56673 +}
56674 +
56675 +static __inline__ int
56676 +proc_is_setxid(const struct cred *cred)
56677 +{
56678 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
56679 + cred->uid != cred->fsuid)
56680 + return 1;
56681 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56682 + cred->gid != cred->fsgid)
56683 + return 1;
56684 +
56685 + return 0;
56686 +}
56687 +
56688 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56689 +
56690 +void
56691 +gr_handle_crash(struct task_struct *task, const int sig)
56692 +{
56693 + struct acl_subject_label *curr;
56694 + struct task_struct *tsk, *tsk2;
56695 + const struct cred *cred;
56696 + const struct cred *cred2;
56697 +
56698 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56699 + return;
56700 +
56701 + if (unlikely(!gr_acl_is_enabled()))
56702 + return;
56703 +
56704 + curr = task->acl;
56705 +
56706 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56707 + return;
56708 +
56709 + if (time_before_eq(curr->expires, get_seconds())) {
56710 + curr->expires = 0;
56711 + curr->crashes = 0;
56712 + }
56713 +
56714 + curr->crashes++;
56715 +
56716 + if (!curr->expires)
56717 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56718 +
56719 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56720 + time_after(curr->expires, get_seconds())) {
56721 + rcu_read_lock();
56722 + cred = __task_cred(task);
56723 + if (cred->uid && proc_is_setxid(cred)) {
56724 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56725 + spin_lock(&gr_uid_lock);
56726 + gr_insert_uid(cred->uid, curr->expires);
56727 + spin_unlock(&gr_uid_lock);
56728 + curr->expires = 0;
56729 + curr->crashes = 0;
56730 + read_lock(&tasklist_lock);
56731 + do_each_thread(tsk2, tsk) {
56732 + cred2 = __task_cred(tsk);
56733 + if (tsk != task && cred2->uid == cred->uid)
56734 + gr_fake_force_sig(SIGKILL, tsk);
56735 + } while_each_thread(tsk2, tsk);
56736 + read_unlock(&tasklist_lock);
56737 + } else {
56738 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56739 + read_lock(&tasklist_lock);
56740 + read_lock(&grsec_exec_file_lock);
56741 + do_each_thread(tsk2, tsk) {
56742 + if (likely(tsk != task)) {
56743 + // if this thread has the same subject as the one that triggered
56744 + // RES_CRASH and it's the same binary, kill it
56745 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56746 + gr_fake_force_sig(SIGKILL, tsk);
56747 + }
56748 + } while_each_thread(tsk2, tsk);
56749 + read_unlock(&grsec_exec_file_lock);
56750 + read_unlock(&tasklist_lock);
56751 + }
56752 + rcu_read_unlock();
56753 + }
56754 +
56755 + return;
56756 +}
56757 +
56758 +int
56759 +gr_check_crash_exec(const struct file *filp)
56760 +{
56761 + struct acl_subject_label *curr;
56762 +
56763 + if (unlikely(!gr_acl_is_enabled()))
56764 + return 0;
56765 +
56766 + read_lock(&gr_inode_lock);
56767 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56768 + __get_dev(filp->f_path.dentry),
56769 + current->role);
56770 + read_unlock(&gr_inode_lock);
56771 +
56772 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56773 + (!curr->crashes && !curr->expires))
56774 + return 0;
56775 +
56776 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56777 + time_after(curr->expires, get_seconds()))
56778 + return 1;
56779 + else if (time_before_eq(curr->expires, get_seconds())) {
56780 + curr->crashes = 0;
56781 + curr->expires = 0;
56782 + }
56783 +
56784 + return 0;
56785 +}
56786 +
56787 +void
56788 +gr_handle_alertkill(struct task_struct *task)
56789 +{
56790 + struct acl_subject_label *curracl;
56791 + __u32 curr_ip;
56792 + struct task_struct *p, *p2;
56793 +
56794 + if (unlikely(!gr_acl_is_enabled()))
56795 + return;
56796 +
56797 + curracl = task->acl;
56798 + curr_ip = task->signal->curr_ip;
56799 +
56800 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56801 + read_lock(&tasklist_lock);
56802 + do_each_thread(p2, p) {
56803 + if (p->signal->curr_ip == curr_ip)
56804 + gr_fake_force_sig(SIGKILL, p);
56805 + } while_each_thread(p2, p);
56806 + read_unlock(&tasklist_lock);
56807 + } else if (curracl->mode & GR_KILLPROC)
56808 + gr_fake_force_sig(SIGKILL, task);
56809 +
56810 + return;
56811 +}
56812 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56813 new file mode 100644
56814 index 0000000..9d83a69
56815 --- /dev/null
56816 +++ b/grsecurity/gracl_shm.c
56817 @@ -0,0 +1,40 @@
56818 +#include <linux/kernel.h>
56819 +#include <linux/mm.h>
56820 +#include <linux/sched.h>
56821 +#include <linux/file.h>
56822 +#include <linux/ipc.h>
56823 +#include <linux/gracl.h>
56824 +#include <linux/grsecurity.h>
56825 +#include <linux/grinternal.h>
56826 +
56827 +int
56828 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56829 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56830 +{
56831 + struct task_struct *task;
56832 +
56833 + if (!gr_acl_is_enabled())
56834 + return 1;
56835 +
56836 + rcu_read_lock();
56837 + read_lock(&tasklist_lock);
56838 +
56839 + task = find_task_by_vpid(shm_cprid);
56840 +
56841 + if (unlikely(!task))
56842 + task = find_task_by_vpid(shm_lapid);
56843 +
56844 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56845 + (task->pid == shm_lapid)) &&
56846 + (task->acl->mode & GR_PROTSHM) &&
56847 + (task->acl != current->acl))) {
56848 + read_unlock(&tasklist_lock);
56849 + rcu_read_unlock();
56850 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56851 + return 0;
56852 + }
56853 + read_unlock(&tasklist_lock);
56854 + rcu_read_unlock();
56855 +
56856 + return 1;
56857 +}
56858 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56859 new file mode 100644
56860 index 0000000..bc0be01
56861 --- /dev/null
56862 +++ b/grsecurity/grsec_chdir.c
56863 @@ -0,0 +1,19 @@
56864 +#include <linux/kernel.h>
56865 +#include <linux/sched.h>
56866 +#include <linux/fs.h>
56867 +#include <linux/file.h>
56868 +#include <linux/grsecurity.h>
56869 +#include <linux/grinternal.h>
56870 +
56871 +void
56872 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56873 +{
56874 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56875 + if ((grsec_enable_chdir && grsec_enable_group &&
56876 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56877 + !grsec_enable_group)) {
56878 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56879 + }
56880 +#endif
56881 + return;
56882 +}
56883 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56884 new file mode 100644
56885 index 0000000..9807ee2
56886 --- /dev/null
56887 +++ b/grsecurity/grsec_chroot.c
56888 @@ -0,0 +1,368 @@
56889 +#include <linux/kernel.h>
56890 +#include <linux/module.h>
56891 +#include <linux/sched.h>
56892 +#include <linux/file.h>
56893 +#include <linux/fs.h>
56894 +#include <linux/mount.h>
56895 +#include <linux/types.h>
56896 +#include "../fs/mount.h"
56897 +#include <linux/grsecurity.h>
56898 +#include <linux/grinternal.h>
56899 +
56900 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56901 +{
56902 +#ifdef CONFIG_GRKERNSEC
56903 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56904 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56905 + task->gr_is_chrooted = 1;
56906 + else
56907 + task->gr_is_chrooted = 0;
56908 +
56909 + task->gr_chroot_dentry = path->dentry;
56910 +#endif
56911 + return;
56912 +}
56913 +
56914 +void gr_clear_chroot_entries(struct task_struct *task)
56915 +{
56916 +#ifdef CONFIG_GRKERNSEC
56917 + task->gr_is_chrooted = 0;
56918 + task->gr_chroot_dentry = NULL;
56919 +#endif
56920 + return;
56921 +}
56922 +
56923 +int
56924 +gr_handle_chroot_unix(const pid_t pid)
56925 +{
56926 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56927 + struct task_struct *p;
56928 +
56929 + if (unlikely(!grsec_enable_chroot_unix))
56930 + return 1;
56931 +
56932 + if (likely(!proc_is_chrooted(current)))
56933 + return 1;
56934 +
56935 + rcu_read_lock();
56936 + read_lock(&tasklist_lock);
56937 + p = find_task_by_vpid_unrestricted(pid);
56938 + if (unlikely(p && !have_same_root(current, p))) {
56939 + read_unlock(&tasklist_lock);
56940 + rcu_read_unlock();
56941 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56942 + return 0;
56943 + }
56944 + read_unlock(&tasklist_lock);
56945 + rcu_read_unlock();
56946 +#endif
56947 + return 1;
56948 +}
56949 +
56950 +int
56951 +gr_handle_chroot_nice(void)
56952 +{
56953 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56954 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56955 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56956 + return -EPERM;
56957 + }
56958 +#endif
56959 + return 0;
56960 +}
56961 +
56962 +int
56963 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56964 +{
56965 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56966 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56967 + && proc_is_chrooted(current)) {
56968 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56969 + return -EACCES;
56970 + }
56971 +#endif
56972 + return 0;
56973 +}
56974 +
56975 +int
56976 +gr_handle_chroot_rawio(const struct inode *inode)
56977 +{
56978 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56979 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56980 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56981 + return 1;
56982 +#endif
56983 + return 0;
56984 +}
56985 +
56986 +int
56987 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56988 +{
56989 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56990 + struct task_struct *p;
56991 + int ret = 0;
56992 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56993 + return ret;
56994 +
56995 + read_lock(&tasklist_lock);
56996 + do_each_pid_task(pid, type, p) {
56997 + if (!have_same_root(current, p)) {
56998 + ret = 1;
56999 + goto out;
57000 + }
57001 + } while_each_pid_task(pid, type, p);
57002 +out:
57003 + read_unlock(&tasklist_lock);
57004 + return ret;
57005 +#endif
57006 + return 0;
57007 +}
57008 +
57009 +int
57010 +gr_pid_is_chrooted(struct task_struct *p)
57011 +{
57012 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57013 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57014 + return 0;
57015 +
57016 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57017 + !have_same_root(current, p)) {
57018 + return 1;
57019 + }
57020 +#endif
57021 + return 0;
57022 +}
57023 +
57024 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57025 +
57026 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57027 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57028 +{
57029 + struct path path, currentroot;
57030 + int ret = 0;
57031 +
57032 + path.dentry = (struct dentry *)u_dentry;
57033 + path.mnt = (struct vfsmount *)u_mnt;
57034 + get_fs_root(current->fs, &currentroot);
57035 + if (path_is_under(&path, &currentroot))
57036 + ret = 1;
57037 + path_put(&currentroot);
57038 +
57039 + return ret;
57040 +}
57041 +#endif
57042 +
57043 +int
57044 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57045 +{
57046 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57047 + if (!grsec_enable_chroot_fchdir)
57048 + return 1;
57049 +
57050 + if (!proc_is_chrooted(current))
57051 + return 1;
57052 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57053 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57054 + return 0;
57055 + }
57056 +#endif
57057 + return 1;
57058 +}
57059 +
57060 +int
57061 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57062 + const time_t shm_createtime)
57063 +{
57064 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57065 + struct task_struct *p;
57066 + time_t starttime;
57067 +
57068 + if (unlikely(!grsec_enable_chroot_shmat))
57069 + return 1;
57070 +
57071 + if (likely(!proc_is_chrooted(current)))
57072 + return 1;
57073 +
57074 + rcu_read_lock();
57075 + read_lock(&tasklist_lock);
57076 +
57077 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57078 + starttime = p->start_time.tv_sec;
57079 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57080 + if (have_same_root(current, p)) {
57081 + goto allow;
57082 + } else {
57083 + read_unlock(&tasklist_lock);
57084 + rcu_read_unlock();
57085 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57086 + return 0;
57087 + }
57088 + }
57089 + /* creator exited, pid reuse, fall through to next check */
57090 + }
57091 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57092 + if (unlikely(!have_same_root(current, p))) {
57093 + read_unlock(&tasklist_lock);
57094 + rcu_read_unlock();
57095 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57096 + return 0;
57097 + }
57098 + }
57099 +
57100 +allow:
57101 + read_unlock(&tasklist_lock);
57102 + rcu_read_unlock();
57103 +#endif
57104 + return 1;
57105 +}
57106 +
57107 +void
57108 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57109 +{
57110 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57111 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57112 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57113 +#endif
57114 + return;
57115 +}
57116 +
57117 +int
57118 +gr_handle_chroot_mknod(const struct dentry *dentry,
57119 + const struct vfsmount *mnt, const int mode)
57120 +{
57121 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57122 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57123 + proc_is_chrooted(current)) {
57124 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57125 + return -EPERM;
57126 + }
57127 +#endif
57128 + return 0;
57129 +}
57130 +
57131 +int
57132 +gr_handle_chroot_mount(const struct dentry *dentry,
57133 + const struct vfsmount *mnt, const char *dev_name)
57134 +{
57135 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57136 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57137 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57138 + return -EPERM;
57139 + }
57140 +#endif
57141 + return 0;
57142 +}
57143 +
57144 +int
57145 +gr_handle_chroot_pivot(void)
57146 +{
57147 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57148 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57149 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57150 + return -EPERM;
57151 + }
57152 +#endif
57153 + return 0;
57154 +}
57155 +
57156 +int
57157 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57158 +{
57159 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57160 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57161 + !gr_is_outside_chroot(dentry, mnt)) {
57162 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57163 + return -EPERM;
57164 + }
57165 +#endif
57166 + return 0;
57167 +}
57168 +
57169 +extern const char *captab_log[];
57170 +extern int captab_log_entries;
57171 +
57172 +int
57173 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57174 +{
57175 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57176 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57177 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57178 + if (cap_raised(chroot_caps, cap)) {
57179 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57180 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57181 + }
57182 + return 0;
57183 + }
57184 + }
57185 +#endif
57186 + return 1;
57187 +}
57188 +
57189 +int
57190 +gr_chroot_is_capable(const int cap)
57191 +{
57192 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57193 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57194 +#endif
57195 + return 1;
57196 +}
57197 +
57198 +int
57199 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57200 +{
57201 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57202 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57203 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57204 + if (cap_raised(chroot_caps, cap)) {
57205 + return 0;
57206 + }
57207 + }
57208 +#endif
57209 + return 1;
57210 +}
57211 +
57212 +int
57213 +gr_chroot_is_capable_nolog(const int cap)
57214 +{
57215 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57216 + return gr_task_chroot_is_capable_nolog(current, cap);
57217 +#endif
57218 + return 1;
57219 +}
57220 +
57221 +int
57222 +gr_handle_chroot_sysctl(const int op)
57223 +{
57224 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57225 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57226 + proc_is_chrooted(current))
57227 + return -EACCES;
57228 +#endif
57229 + return 0;
57230 +}
57231 +
57232 +void
57233 +gr_handle_chroot_chdir(struct path *path)
57234 +{
57235 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57236 + if (grsec_enable_chroot_chdir)
57237 + set_fs_pwd(current->fs, path);
57238 +#endif
57239 + return;
57240 +}
57241 +
57242 +int
57243 +gr_handle_chroot_chmod(const struct dentry *dentry,
57244 + const struct vfsmount *mnt, const int mode)
57245 +{
57246 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57247 + /* allow chmod +s on directories, but not files */
57248 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57249 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57250 + proc_is_chrooted(current)) {
57251 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57252 + return -EPERM;
57253 + }
57254 +#endif
57255 + return 0;
57256 +}
57257 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57258 new file mode 100644
57259 index 0000000..213ad8b
57260 --- /dev/null
57261 +++ b/grsecurity/grsec_disabled.c
57262 @@ -0,0 +1,437 @@
57263 +#include <linux/kernel.h>
57264 +#include <linux/module.h>
57265 +#include <linux/sched.h>
57266 +#include <linux/file.h>
57267 +#include <linux/fs.h>
57268 +#include <linux/kdev_t.h>
57269 +#include <linux/net.h>
57270 +#include <linux/in.h>
57271 +#include <linux/ip.h>
57272 +#include <linux/skbuff.h>
57273 +#include <linux/sysctl.h>
57274 +
57275 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57276 +void
57277 +pax_set_initial_flags(struct linux_binprm *bprm)
57278 +{
57279 + return;
57280 +}
57281 +#endif
57282 +
57283 +#ifdef CONFIG_SYSCTL
57284 +__u32
57285 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57286 +{
57287 + return 0;
57288 +}
57289 +#endif
57290 +
57291 +#ifdef CONFIG_TASKSTATS
57292 +int gr_is_taskstats_denied(int pid)
57293 +{
57294 + return 0;
57295 +}
57296 +#endif
57297 +
57298 +int
57299 +gr_acl_is_enabled(void)
57300 +{
57301 + return 0;
57302 +}
57303 +
57304 +void
57305 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57306 +{
57307 + return;
57308 +}
57309 +
57310 +int
57311 +gr_handle_rawio(const struct inode *inode)
57312 +{
57313 + return 0;
57314 +}
57315 +
57316 +void
57317 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57318 +{
57319 + return;
57320 +}
57321 +
57322 +int
57323 +gr_handle_ptrace(struct task_struct *task, const long request)
57324 +{
57325 + return 0;
57326 +}
57327 +
57328 +int
57329 +gr_handle_proc_ptrace(struct task_struct *task)
57330 +{
57331 + return 0;
57332 +}
57333 +
57334 +void
57335 +gr_learn_resource(const struct task_struct *task,
57336 + const int res, const unsigned long wanted, const int gt)
57337 +{
57338 + return;
57339 +}
57340 +
57341 +int
57342 +gr_set_acls(const int type)
57343 +{
57344 + return 0;
57345 +}
57346 +
57347 +int
57348 +gr_check_hidden_task(const struct task_struct *tsk)
57349 +{
57350 + return 0;
57351 +}
57352 +
57353 +int
57354 +gr_check_protected_task(const struct task_struct *task)
57355 +{
57356 + return 0;
57357 +}
57358 +
57359 +int
57360 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57361 +{
57362 + return 0;
57363 +}
57364 +
57365 +void
57366 +gr_copy_label(struct task_struct *tsk)
57367 +{
57368 + return;
57369 +}
57370 +
57371 +void
57372 +gr_set_pax_flags(struct task_struct *task)
57373 +{
57374 + return;
57375 +}
57376 +
57377 +int
57378 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57379 + const int unsafe_share)
57380 +{
57381 + return 0;
57382 +}
57383 +
57384 +void
57385 +gr_handle_delete(const ino_t ino, const dev_t dev)
57386 +{
57387 + return;
57388 +}
57389 +
57390 +void
57391 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57392 +{
57393 + return;
57394 +}
57395 +
57396 +void
57397 +gr_handle_crash(struct task_struct *task, const int sig)
57398 +{
57399 + return;
57400 +}
57401 +
57402 +int
57403 +gr_check_crash_exec(const struct file *filp)
57404 +{
57405 + return 0;
57406 +}
57407 +
57408 +int
57409 +gr_check_crash_uid(const uid_t uid)
57410 +{
57411 + return 0;
57412 +}
57413 +
57414 +void
57415 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57416 + struct dentry *old_dentry,
57417 + struct dentry *new_dentry,
57418 + struct vfsmount *mnt, const __u8 replace)
57419 +{
57420 + return;
57421 +}
57422 +
57423 +int
57424 +gr_search_socket(const int family, const int type, const int protocol)
57425 +{
57426 + return 1;
57427 +}
57428 +
57429 +int
57430 +gr_search_connectbind(const int mode, const struct socket *sock,
57431 + const struct sockaddr_in *addr)
57432 +{
57433 + return 0;
57434 +}
57435 +
57436 +void
57437 +gr_handle_alertkill(struct task_struct *task)
57438 +{
57439 + return;
57440 +}
57441 +
57442 +__u32
57443 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57444 +{
57445 + return 1;
57446 +}
57447 +
57448 +__u32
57449 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57450 + const struct vfsmount * mnt)
57451 +{
57452 + return 1;
57453 +}
57454 +
57455 +__u32
57456 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57457 + int acc_mode)
57458 +{
57459 + return 1;
57460 +}
57461 +
57462 +__u32
57463 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57464 +{
57465 + return 1;
57466 +}
57467 +
57468 +__u32
57469 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57470 +{
57471 + return 1;
57472 +}
57473 +
57474 +int
57475 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57476 + unsigned int *vm_flags)
57477 +{
57478 + return 1;
57479 +}
57480 +
57481 +__u32
57482 +gr_acl_handle_truncate(const struct dentry * dentry,
57483 + const struct vfsmount * mnt)
57484 +{
57485 + return 1;
57486 +}
57487 +
57488 +__u32
57489 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57490 +{
57491 + return 1;
57492 +}
57493 +
57494 +__u32
57495 +gr_acl_handle_access(const struct dentry * dentry,
57496 + const struct vfsmount * mnt, const int fmode)
57497 +{
57498 + return 1;
57499 +}
57500 +
57501 +__u32
57502 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57503 + umode_t *mode)
57504 +{
57505 + return 1;
57506 +}
57507 +
57508 +__u32
57509 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57510 +{
57511 + return 1;
57512 +}
57513 +
57514 +__u32
57515 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57516 +{
57517 + return 1;
57518 +}
57519 +
57520 +void
57521 +grsecurity_init(void)
57522 +{
57523 + return;
57524 +}
57525 +
57526 +umode_t gr_acl_umask(void)
57527 +{
57528 + return 0;
57529 +}
57530 +
57531 +__u32
57532 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57533 + const struct dentry * parent_dentry,
57534 + const struct vfsmount * parent_mnt,
57535 + const int mode)
57536 +{
57537 + return 1;
57538 +}
57539 +
57540 +__u32
57541 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57542 + const struct dentry * parent_dentry,
57543 + const struct vfsmount * parent_mnt)
57544 +{
57545 + return 1;
57546 +}
57547 +
57548 +__u32
57549 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57550 + const struct dentry * parent_dentry,
57551 + const struct vfsmount * parent_mnt, const char *from)
57552 +{
57553 + return 1;
57554 +}
57555 +
57556 +__u32
57557 +gr_acl_handle_link(const struct dentry * new_dentry,
57558 + const struct dentry * parent_dentry,
57559 + const struct vfsmount * parent_mnt,
57560 + const struct dentry * old_dentry,
57561 + const struct vfsmount * old_mnt, const char *to)
57562 +{
57563 + return 1;
57564 +}
57565 +
57566 +int
57567 +gr_acl_handle_rename(const struct dentry *new_dentry,
57568 + const struct dentry *parent_dentry,
57569 + const struct vfsmount *parent_mnt,
57570 + const struct dentry *old_dentry,
57571 + const struct inode *old_parent_inode,
57572 + const struct vfsmount *old_mnt, const char *newname)
57573 +{
57574 + return 0;
57575 +}
57576 +
57577 +int
57578 +gr_acl_handle_filldir(const struct file *file, const char *name,
57579 + const int namelen, const ino_t ino)
57580 +{
57581 + return 1;
57582 +}
57583 +
57584 +int
57585 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57586 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57587 +{
57588 + return 1;
57589 +}
57590 +
57591 +int
57592 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57593 +{
57594 + return 0;
57595 +}
57596 +
57597 +int
57598 +gr_search_accept(const struct socket *sock)
57599 +{
57600 + return 0;
57601 +}
57602 +
57603 +int
57604 +gr_search_listen(const struct socket *sock)
57605 +{
57606 + return 0;
57607 +}
57608 +
57609 +int
57610 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57611 +{
57612 + return 0;
57613 +}
57614 +
57615 +__u32
57616 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57617 +{
57618 + return 1;
57619 +}
57620 +
57621 +__u32
57622 +gr_acl_handle_creat(const struct dentry * dentry,
57623 + const struct dentry * p_dentry,
57624 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57625 + const int imode)
57626 +{
57627 + return 1;
57628 +}
57629 +
57630 +void
57631 +gr_acl_handle_exit(void)
57632 +{
57633 + return;
57634 +}
57635 +
57636 +int
57637 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57638 +{
57639 + return 1;
57640 +}
57641 +
57642 +void
57643 +gr_set_role_label(const uid_t uid, const gid_t gid)
57644 +{
57645 + return;
57646 +}
57647 +
57648 +int
57649 +gr_acl_handle_procpidmem(const struct task_struct *task)
57650 +{
57651 + return 0;
57652 +}
57653 +
57654 +int
57655 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57656 +{
57657 + return 0;
57658 +}
57659 +
57660 +int
57661 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57662 +{
57663 + return 0;
57664 +}
57665 +
57666 +void
57667 +gr_set_kernel_label(struct task_struct *task)
57668 +{
57669 + return;
57670 +}
57671 +
57672 +int
57673 +gr_check_user_change(int real, int effective, int fs)
57674 +{
57675 + return 0;
57676 +}
57677 +
57678 +int
57679 +gr_check_group_change(int real, int effective, int fs)
57680 +{
57681 + return 0;
57682 +}
57683 +
57684 +int gr_acl_enable_at_secure(void)
57685 +{
57686 + return 0;
57687 +}
57688 +
57689 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57690 +{
57691 + return dentry->d_inode->i_sb->s_dev;
57692 +}
57693 +
57694 +EXPORT_SYMBOL(gr_learn_resource);
57695 +EXPORT_SYMBOL(gr_set_kernel_label);
57696 +#ifdef CONFIG_SECURITY
57697 +EXPORT_SYMBOL(gr_check_user_change);
57698 +EXPORT_SYMBOL(gr_check_group_change);
57699 +#endif
57700 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57701 new file mode 100644
57702 index 0000000..abfa971
57703 --- /dev/null
57704 +++ b/grsecurity/grsec_exec.c
57705 @@ -0,0 +1,174 @@
57706 +#include <linux/kernel.h>
57707 +#include <linux/sched.h>
57708 +#include <linux/file.h>
57709 +#include <linux/binfmts.h>
57710 +#include <linux/fs.h>
57711 +#include <linux/types.h>
57712 +#include <linux/grdefs.h>
57713 +#include <linux/grsecurity.h>
57714 +#include <linux/grinternal.h>
57715 +#include <linux/capability.h>
57716 +#include <linux/module.h>
57717 +
57718 +#include <asm/uaccess.h>
57719 +
57720 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57721 +static char gr_exec_arg_buf[132];
57722 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57723 +#endif
57724 +
57725 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57726 +
57727 +void
57728 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57729 +{
57730 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57731 + char *grarg = gr_exec_arg_buf;
57732 + unsigned int i, x, execlen = 0;
57733 + char c;
57734 +
57735 + if (!((grsec_enable_execlog && grsec_enable_group &&
57736 + in_group_p(grsec_audit_gid))
57737 + || (grsec_enable_execlog && !grsec_enable_group)))
57738 + return;
57739 +
57740 + mutex_lock(&gr_exec_arg_mutex);
57741 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57742 +
57743 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57744 + const char __user *p;
57745 + unsigned int len;
57746 +
57747 + p = get_user_arg_ptr(argv, i);
57748 + if (IS_ERR(p))
57749 + goto log;
57750 +
57751 + len = strnlen_user(p, 128 - execlen);
57752 + if (len > 128 - execlen)
57753 + len = 128 - execlen;
57754 + else if (len > 0)
57755 + len--;
57756 + if (copy_from_user(grarg + execlen, p, len))
57757 + goto log;
57758 +
57759 + /* rewrite unprintable characters */
57760 + for (x = 0; x < len; x++) {
57761 + c = *(grarg + execlen + x);
57762 + if (c < 32 || c > 126)
57763 + *(grarg + execlen + x) = ' ';
57764 + }
57765 +
57766 + execlen += len;
57767 + *(grarg + execlen) = ' ';
57768 + *(grarg + execlen + 1) = '\0';
57769 + execlen++;
57770 + }
57771 +
57772 + log:
57773 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57774 + bprm->file->f_path.mnt, grarg);
57775 + mutex_unlock(&gr_exec_arg_mutex);
57776 +#endif
57777 + return;
57778 +}
57779 +
57780 +#ifdef CONFIG_GRKERNSEC
57781 +extern int gr_acl_is_capable(const int cap);
57782 +extern int gr_acl_is_capable_nolog(const int cap);
57783 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57784 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57785 +extern int gr_chroot_is_capable(const int cap);
57786 +extern int gr_chroot_is_capable_nolog(const int cap);
57787 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57788 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57789 +#endif
57790 +
57791 +const char *captab_log[] = {
57792 + "CAP_CHOWN",
57793 + "CAP_DAC_OVERRIDE",
57794 + "CAP_DAC_READ_SEARCH",
57795 + "CAP_FOWNER",
57796 + "CAP_FSETID",
57797 + "CAP_KILL",
57798 + "CAP_SETGID",
57799 + "CAP_SETUID",
57800 + "CAP_SETPCAP",
57801 + "CAP_LINUX_IMMUTABLE",
57802 + "CAP_NET_BIND_SERVICE",
57803 + "CAP_NET_BROADCAST",
57804 + "CAP_NET_ADMIN",
57805 + "CAP_NET_RAW",
57806 + "CAP_IPC_LOCK",
57807 + "CAP_IPC_OWNER",
57808 + "CAP_SYS_MODULE",
57809 + "CAP_SYS_RAWIO",
57810 + "CAP_SYS_CHROOT",
57811 + "CAP_SYS_PTRACE",
57812 + "CAP_SYS_PACCT",
57813 + "CAP_SYS_ADMIN",
57814 + "CAP_SYS_BOOT",
57815 + "CAP_SYS_NICE",
57816 + "CAP_SYS_RESOURCE",
57817 + "CAP_SYS_TIME",
57818 + "CAP_SYS_TTY_CONFIG",
57819 + "CAP_MKNOD",
57820 + "CAP_LEASE",
57821 + "CAP_AUDIT_WRITE",
57822 + "CAP_AUDIT_CONTROL",
57823 + "CAP_SETFCAP",
57824 + "CAP_MAC_OVERRIDE",
57825 + "CAP_MAC_ADMIN",
57826 + "CAP_SYSLOG",
57827 + "CAP_WAKE_ALARM"
57828 +};
57829 +
57830 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57831 +
57832 +int gr_is_capable(const int cap)
57833 +{
57834 +#ifdef CONFIG_GRKERNSEC
57835 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57836 + return 1;
57837 + return 0;
57838 +#else
57839 + return 1;
57840 +#endif
57841 +}
57842 +
57843 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57844 +{
57845 +#ifdef CONFIG_GRKERNSEC
57846 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57847 + return 1;
57848 + return 0;
57849 +#else
57850 + return 1;
57851 +#endif
57852 +}
57853 +
57854 +int gr_is_capable_nolog(const int cap)
57855 +{
57856 +#ifdef CONFIG_GRKERNSEC
57857 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57858 + return 1;
57859 + return 0;
57860 +#else
57861 + return 1;
57862 +#endif
57863 +}
57864 +
57865 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57866 +{
57867 +#ifdef CONFIG_GRKERNSEC
57868 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57869 + return 1;
57870 + return 0;
57871 +#else
57872 + return 1;
57873 +#endif
57874 +}
57875 +
57876 +EXPORT_SYMBOL(gr_is_capable);
57877 +EXPORT_SYMBOL(gr_is_capable_nolog);
57878 +EXPORT_SYMBOL(gr_task_is_capable);
57879 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
57880 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57881 new file mode 100644
57882 index 0000000..d3ee748
57883 --- /dev/null
57884 +++ b/grsecurity/grsec_fifo.c
57885 @@ -0,0 +1,24 @@
57886 +#include <linux/kernel.h>
57887 +#include <linux/sched.h>
57888 +#include <linux/fs.h>
57889 +#include <linux/file.h>
57890 +#include <linux/grinternal.h>
57891 +
57892 +int
57893 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57894 + const struct dentry *dir, const int flag, const int acc_mode)
57895 +{
57896 +#ifdef CONFIG_GRKERNSEC_FIFO
57897 + const struct cred *cred = current_cred();
57898 +
57899 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57900 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57901 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57902 + (cred->fsuid != dentry->d_inode->i_uid)) {
57903 + if (!inode_permission(dentry->d_inode, acc_mode))
57904 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57905 + return -EACCES;
57906 + }
57907 +#endif
57908 + return 0;
57909 +}
57910 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57911 new file mode 100644
57912 index 0000000..8ca18bf
57913 --- /dev/null
57914 +++ b/grsecurity/grsec_fork.c
57915 @@ -0,0 +1,23 @@
57916 +#include <linux/kernel.h>
57917 +#include <linux/sched.h>
57918 +#include <linux/grsecurity.h>
57919 +#include <linux/grinternal.h>
57920 +#include <linux/errno.h>
57921 +
57922 +void
57923 +gr_log_forkfail(const int retval)
57924 +{
57925 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57926 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57927 + switch (retval) {
57928 + case -EAGAIN:
57929 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57930 + break;
57931 + case -ENOMEM:
57932 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57933 + break;
57934 + }
57935 + }
57936 +#endif
57937 + return;
57938 +}
57939 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57940 new file mode 100644
57941 index 0000000..01ddde4
57942 --- /dev/null
57943 +++ b/grsecurity/grsec_init.c
57944 @@ -0,0 +1,277 @@
57945 +#include <linux/kernel.h>
57946 +#include <linux/sched.h>
57947 +#include <linux/mm.h>
57948 +#include <linux/gracl.h>
57949 +#include <linux/slab.h>
57950 +#include <linux/vmalloc.h>
57951 +#include <linux/percpu.h>
57952 +#include <linux/module.h>
57953 +
57954 +int grsec_enable_ptrace_readexec;
57955 +int grsec_enable_setxid;
57956 +int grsec_enable_brute;
57957 +int grsec_enable_link;
57958 +int grsec_enable_dmesg;
57959 +int grsec_enable_harden_ptrace;
57960 +int grsec_enable_fifo;
57961 +int grsec_enable_execlog;
57962 +int grsec_enable_signal;
57963 +int grsec_enable_forkfail;
57964 +int grsec_enable_audit_ptrace;
57965 +int grsec_enable_time;
57966 +int grsec_enable_audit_textrel;
57967 +int grsec_enable_group;
57968 +int grsec_audit_gid;
57969 +int grsec_enable_chdir;
57970 +int grsec_enable_mount;
57971 +int grsec_enable_rofs;
57972 +int grsec_enable_chroot_findtask;
57973 +int grsec_enable_chroot_mount;
57974 +int grsec_enable_chroot_shmat;
57975 +int grsec_enable_chroot_fchdir;
57976 +int grsec_enable_chroot_double;
57977 +int grsec_enable_chroot_pivot;
57978 +int grsec_enable_chroot_chdir;
57979 +int grsec_enable_chroot_chmod;
57980 +int grsec_enable_chroot_mknod;
57981 +int grsec_enable_chroot_nice;
57982 +int grsec_enable_chroot_execlog;
57983 +int grsec_enable_chroot_caps;
57984 +int grsec_enable_chroot_sysctl;
57985 +int grsec_enable_chroot_unix;
57986 +int grsec_enable_tpe;
57987 +int grsec_tpe_gid;
57988 +int grsec_enable_blackhole;
57989 +#ifdef CONFIG_IPV6_MODULE
57990 +EXPORT_SYMBOL(grsec_enable_blackhole);
57991 +#endif
57992 +int grsec_lastack_retries;
57993 +int grsec_enable_tpe_all;
57994 +int grsec_enable_tpe_invert;
57995 +int grsec_enable_socket_all;
57996 +int grsec_socket_all_gid;
57997 +int grsec_enable_socket_client;
57998 +int grsec_socket_client_gid;
57999 +int grsec_enable_socket_server;
58000 +int grsec_socket_server_gid;
58001 +int grsec_resource_logging;
58002 +int grsec_disable_privio;
58003 +int grsec_enable_log_rwxmaps;
58004 +int grsec_lock;
58005 +
58006 +DEFINE_SPINLOCK(grsec_alert_lock);
58007 +unsigned long grsec_alert_wtime = 0;
58008 +unsigned long grsec_alert_fyet = 0;
58009 +
58010 +DEFINE_SPINLOCK(grsec_audit_lock);
58011 +
58012 +DEFINE_RWLOCK(grsec_exec_file_lock);
58013 +
58014 +char *gr_shared_page[4];
58015 +
58016 +char *gr_alert_log_fmt;
58017 +char *gr_audit_log_fmt;
58018 +char *gr_alert_log_buf;
58019 +char *gr_audit_log_buf;
58020 +
58021 +extern struct gr_arg *gr_usermode;
58022 +extern unsigned char *gr_system_salt;
58023 +extern unsigned char *gr_system_sum;
58024 +
58025 +void __init
58026 +grsecurity_init(void)
58027 +{
58028 + int j;
58029 + /* create the per-cpu shared pages */
58030 +
58031 +#ifdef CONFIG_X86
58032 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58033 +#endif
58034 +
58035 + for (j = 0; j < 4; j++) {
58036 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58037 + if (gr_shared_page[j] == NULL) {
58038 + panic("Unable to allocate grsecurity shared page");
58039 + return;
58040 + }
58041 + }
58042 +
58043 + /* allocate log buffers */
58044 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58045 + if (!gr_alert_log_fmt) {
58046 + panic("Unable to allocate grsecurity alert log format buffer");
58047 + return;
58048 + }
58049 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58050 + if (!gr_audit_log_fmt) {
58051 + panic("Unable to allocate grsecurity audit log format buffer");
58052 + return;
58053 + }
58054 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58055 + if (!gr_alert_log_buf) {
58056 + panic("Unable to allocate grsecurity alert log buffer");
58057 + return;
58058 + }
58059 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58060 + if (!gr_audit_log_buf) {
58061 + panic("Unable to allocate grsecurity audit log buffer");
58062 + return;
58063 + }
58064 +
58065 + /* allocate memory for authentication structure */
58066 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58067 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58068 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58069 +
58070 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58071 + panic("Unable to allocate grsecurity authentication structure");
58072 + return;
58073 + }
58074 +
58075 +
58076 +#ifdef CONFIG_GRKERNSEC_IO
58077 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58078 + grsec_disable_privio = 1;
58079 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58080 + grsec_disable_privio = 1;
58081 +#else
58082 + grsec_disable_privio = 0;
58083 +#endif
58084 +#endif
58085 +
58086 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58087 + /* for backward compatibility, tpe_invert always defaults to on if
58088 + enabled in the kernel
58089 + */
58090 + grsec_enable_tpe_invert = 1;
58091 +#endif
58092 +
58093 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58094 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58095 + grsec_lock = 1;
58096 +#endif
58097 +
58098 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58099 + grsec_enable_audit_textrel = 1;
58100 +#endif
58101 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58102 + grsec_enable_log_rwxmaps = 1;
58103 +#endif
58104 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58105 + grsec_enable_group = 1;
58106 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58107 +#endif
58108 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58109 + grsec_enable_ptrace_readexec = 1;
58110 +#endif
58111 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58112 + grsec_enable_chdir = 1;
58113 +#endif
58114 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58115 + grsec_enable_harden_ptrace = 1;
58116 +#endif
58117 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58118 + grsec_enable_mount = 1;
58119 +#endif
58120 +#ifdef CONFIG_GRKERNSEC_LINK
58121 + grsec_enable_link = 1;
58122 +#endif
58123 +#ifdef CONFIG_GRKERNSEC_BRUTE
58124 + grsec_enable_brute = 1;
58125 +#endif
58126 +#ifdef CONFIG_GRKERNSEC_DMESG
58127 + grsec_enable_dmesg = 1;
58128 +#endif
58129 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58130 + grsec_enable_blackhole = 1;
58131 + grsec_lastack_retries = 4;
58132 +#endif
58133 +#ifdef CONFIG_GRKERNSEC_FIFO
58134 + grsec_enable_fifo = 1;
58135 +#endif
58136 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58137 + grsec_enable_execlog = 1;
58138 +#endif
58139 +#ifdef CONFIG_GRKERNSEC_SETXID
58140 + grsec_enable_setxid = 1;
58141 +#endif
58142 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58143 + grsec_enable_signal = 1;
58144 +#endif
58145 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58146 + grsec_enable_forkfail = 1;
58147 +#endif
58148 +#ifdef CONFIG_GRKERNSEC_TIME
58149 + grsec_enable_time = 1;
58150 +#endif
58151 +#ifdef CONFIG_GRKERNSEC_RESLOG
58152 + grsec_resource_logging = 1;
58153 +#endif
58154 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58155 + grsec_enable_chroot_findtask = 1;
58156 +#endif
58157 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58158 + grsec_enable_chroot_unix = 1;
58159 +#endif
58160 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58161 + grsec_enable_chroot_mount = 1;
58162 +#endif
58163 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58164 + grsec_enable_chroot_fchdir = 1;
58165 +#endif
58166 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58167 + grsec_enable_chroot_shmat = 1;
58168 +#endif
58169 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58170 + grsec_enable_audit_ptrace = 1;
58171 +#endif
58172 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58173 + grsec_enable_chroot_double = 1;
58174 +#endif
58175 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58176 + grsec_enable_chroot_pivot = 1;
58177 +#endif
58178 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58179 + grsec_enable_chroot_chdir = 1;
58180 +#endif
58181 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58182 + grsec_enable_chroot_chmod = 1;
58183 +#endif
58184 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58185 + grsec_enable_chroot_mknod = 1;
58186 +#endif
58187 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58188 + grsec_enable_chroot_nice = 1;
58189 +#endif
58190 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58191 + grsec_enable_chroot_execlog = 1;
58192 +#endif
58193 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58194 + grsec_enable_chroot_caps = 1;
58195 +#endif
58196 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58197 + grsec_enable_chroot_sysctl = 1;
58198 +#endif
58199 +#ifdef CONFIG_GRKERNSEC_TPE
58200 + grsec_enable_tpe = 1;
58201 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58202 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58203 + grsec_enable_tpe_all = 1;
58204 +#endif
58205 +#endif
58206 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58207 + grsec_enable_socket_all = 1;
58208 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58209 +#endif
58210 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58211 + grsec_enable_socket_client = 1;
58212 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58213 +#endif
58214 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58215 + grsec_enable_socket_server = 1;
58216 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58217 +#endif
58218 +#endif
58219 +
58220 + return;
58221 +}
58222 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58223 new file mode 100644
58224 index 0000000..3efe141
58225 --- /dev/null
58226 +++ b/grsecurity/grsec_link.c
58227 @@ -0,0 +1,43 @@
58228 +#include <linux/kernel.h>
58229 +#include <linux/sched.h>
58230 +#include <linux/fs.h>
58231 +#include <linux/file.h>
58232 +#include <linux/grinternal.h>
58233 +
58234 +int
58235 +gr_handle_follow_link(const struct inode *parent,
58236 + const struct inode *inode,
58237 + const struct dentry *dentry, const struct vfsmount *mnt)
58238 +{
58239 +#ifdef CONFIG_GRKERNSEC_LINK
58240 + const struct cred *cred = current_cred();
58241 +
58242 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58243 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
58244 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
58245 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58246 + return -EACCES;
58247 + }
58248 +#endif
58249 + return 0;
58250 +}
58251 +
58252 +int
58253 +gr_handle_hardlink(const struct dentry *dentry,
58254 + const struct vfsmount *mnt,
58255 + struct inode *inode, const int mode, const char *to)
58256 +{
58257 +#ifdef CONFIG_GRKERNSEC_LINK
58258 + const struct cred *cred = current_cred();
58259 +
58260 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
58261 + (!S_ISREG(mode) || (mode & S_ISUID) ||
58262 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58263 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58264 + !capable(CAP_FOWNER) && cred->uid) {
58265 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58266 + return -EPERM;
58267 + }
58268 +#endif
58269 + return 0;
58270 +}
58271 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58272 new file mode 100644
58273 index 0000000..a45d2e9
58274 --- /dev/null
58275 +++ b/grsecurity/grsec_log.c
58276 @@ -0,0 +1,322 @@
58277 +#include <linux/kernel.h>
58278 +#include <linux/sched.h>
58279 +#include <linux/file.h>
58280 +#include <linux/tty.h>
58281 +#include <linux/fs.h>
58282 +#include <linux/grinternal.h>
58283 +
58284 +#ifdef CONFIG_TREE_PREEMPT_RCU
58285 +#define DISABLE_PREEMPT() preempt_disable()
58286 +#define ENABLE_PREEMPT() preempt_enable()
58287 +#else
58288 +#define DISABLE_PREEMPT()
58289 +#define ENABLE_PREEMPT()
58290 +#endif
58291 +
58292 +#define BEGIN_LOCKS(x) \
58293 + DISABLE_PREEMPT(); \
58294 + rcu_read_lock(); \
58295 + read_lock(&tasklist_lock); \
58296 + read_lock(&grsec_exec_file_lock); \
58297 + if (x != GR_DO_AUDIT) \
58298 + spin_lock(&grsec_alert_lock); \
58299 + else \
58300 + spin_lock(&grsec_audit_lock)
58301 +
58302 +#define END_LOCKS(x) \
58303 + if (x != GR_DO_AUDIT) \
58304 + spin_unlock(&grsec_alert_lock); \
58305 + else \
58306 + spin_unlock(&grsec_audit_lock); \
58307 + read_unlock(&grsec_exec_file_lock); \
58308 + read_unlock(&tasklist_lock); \
58309 + rcu_read_unlock(); \
58310 + ENABLE_PREEMPT(); \
58311 + if (x == GR_DONT_AUDIT) \
58312 + gr_handle_alertkill(current)
58313 +
58314 +enum {
58315 + FLOODING,
58316 + NO_FLOODING
58317 +};
58318 +
58319 +extern char *gr_alert_log_fmt;
58320 +extern char *gr_audit_log_fmt;
58321 +extern char *gr_alert_log_buf;
58322 +extern char *gr_audit_log_buf;
58323 +
58324 +static int gr_log_start(int audit)
58325 +{
58326 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58327 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58328 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58329 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58330 + unsigned long curr_secs = get_seconds();
58331 +
58332 + if (audit == GR_DO_AUDIT)
58333 + goto set_fmt;
58334 +
58335 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58336 + grsec_alert_wtime = curr_secs;
58337 + grsec_alert_fyet = 0;
58338 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58339 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58340 + grsec_alert_fyet++;
58341 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58342 + grsec_alert_wtime = curr_secs;
58343 + grsec_alert_fyet++;
58344 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58345 + return FLOODING;
58346 + }
58347 + else return FLOODING;
58348 +
58349 +set_fmt:
58350 +#endif
58351 + memset(buf, 0, PAGE_SIZE);
58352 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58353 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58354 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58355 + } else if (current->signal->curr_ip) {
58356 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58357 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58358 + } else if (gr_acl_is_enabled()) {
58359 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58360 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58361 + } else {
58362 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58363 + strcpy(buf, fmt);
58364 + }
58365 +
58366 + return NO_FLOODING;
58367 +}
58368 +
58369 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58370 + __attribute__ ((format (printf, 2, 0)));
58371 +
58372 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58373 +{
58374 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58375 + unsigned int len = strlen(buf);
58376 +
58377 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58378 +
58379 + return;
58380 +}
58381 +
58382 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58383 + __attribute__ ((format (printf, 2, 3)));
58384 +
58385 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58386 +{
58387 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58388 + unsigned int len = strlen(buf);
58389 + va_list ap;
58390 +
58391 + va_start(ap, msg);
58392 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58393 + va_end(ap);
58394 +
58395 + return;
58396 +}
58397 +
58398 +static void gr_log_end(int audit, int append_default)
58399 +{
58400 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58401 +
58402 + if (append_default) {
58403 + unsigned int len = strlen(buf);
58404 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58405 + }
58406 +
58407 + printk("%s\n", buf);
58408 +
58409 + return;
58410 +}
58411 +
58412 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58413 +{
58414 + int logtype;
58415 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58416 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58417 + void *voidptr = NULL;
58418 + int num1 = 0, num2 = 0;
58419 + unsigned long ulong1 = 0, ulong2 = 0;
58420 + struct dentry *dentry = NULL;
58421 + struct vfsmount *mnt = NULL;
58422 + struct file *file = NULL;
58423 + struct task_struct *task = NULL;
58424 + const struct cred *cred, *pcred;
58425 + va_list ap;
58426 +
58427 + BEGIN_LOCKS(audit);
58428 + logtype = gr_log_start(audit);
58429 + if (logtype == FLOODING) {
58430 + END_LOCKS(audit);
58431 + return;
58432 + }
58433 + va_start(ap, argtypes);
58434 + switch (argtypes) {
58435 + case GR_TTYSNIFF:
58436 + task = va_arg(ap, struct task_struct *);
58437 + 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);
58438 + break;
58439 + case GR_SYSCTL_HIDDEN:
58440 + str1 = va_arg(ap, char *);
58441 + gr_log_middle_varargs(audit, msg, result, str1);
58442 + break;
58443 + case GR_RBAC:
58444 + dentry = va_arg(ap, struct dentry *);
58445 + mnt = va_arg(ap, struct vfsmount *);
58446 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58447 + break;
58448 + case GR_RBAC_STR:
58449 + dentry = va_arg(ap, struct dentry *);
58450 + mnt = va_arg(ap, struct vfsmount *);
58451 + str1 = va_arg(ap, char *);
58452 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58453 + break;
58454 + case GR_STR_RBAC:
58455 + str1 = va_arg(ap, char *);
58456 + dentry = va_arg(ap, struct dentry *);
58457 + mnt = va_arg(ap, struct vfsmount *);
58458 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58459 + break;
58460 + case GR_RBAC_MODE2:
58461 + dentry = va_arg(ap, struct dentry *);
58462 + mnt = va_arg(ap, struct vfsmount *);
58463 + str1 = va_arg(ap, char *);
58464 + str2 = va_arg(ap, char *);
58465 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58466 + break;
58467 + case GR_RBAC_MODE3:
58468 + dentry = va_arg(ap, struct dentry *);
58469 + mnt = va_arg(ap, struct vfsmount *);
58470 + str1 = va_arg(ap, char *);
58471 + str2 = va_arg(ap, char *);
58472 + str3 = va_arg(ap, char *);
58473 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58474 + break;
58475 + case GR_FILENAME:
58476 + dentry = va_arg(ap, struct dentry *);
58477 + mnt = va_arg(ap, struct vfsmount *);
58478 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58479 + break;
58480 + case GR_STR_FILENAME:
58481 + str1 = va_arg(ap, char *);
58482 + dentry = va_arg(ap, struct dentry *);
58483 + mnt = va_arg(ap, struct vfsmount *);
58484 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58485 + break;
58486 + case GR_FILENAME_STR:
58487 + dentry = va_arg(ap, struct dentry *);
58488 + mnt = va_arg(ap, struct vfsmount *);
58489 + str1 = va_arg(ap, char *);
58490 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58491 + break;
58492 + case GR_FILENAME_TWO_INT:
58493 + dentry = va_arg(ap, struct dentry *);
58494 + mnt = va_arg(ap, struct vfsmount *);
58495 + num1 = va_arg(ap, int);
58496 + num2 = va_arg(ap, int);
58497 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58498 + break;
58499 + case GR_FILENAME_TWO_INT_STR:
58500 + dentry = va_arg(ap, struct dentry *);
58501 + mnt = va_arg(ap, struct vfsmount *);
58502 + num1 = va_arg(ap, int);
58503 + num2 = va_arg(ap, int);
58504 + str1 = va_arg(ap, char *);
58505 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58506 + break;
58507 + case GR_TEXTREL:
58508 + file = va_arg(ap, struct file *);
58509 + ulong1 = va_arg(ap, unsigned long);
58510 + ulong2 = va_arg(ap, unsigned long);
58511 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58512 + break;
58513 + case GR_PTRACE:
58514 + task = va_arg(ap, struct task_struct *);
58515 + 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);
58516 + break;
58517 + case GR_RESOURCE:
58518 + task = va_arg(ap, struct task_struct *);
58519 + cred = __task_cred(task);
58520 + pcred = __task_cred(task->real_parent);
58521 + ulong1 = va_arg(ap, unsigned long);
58522 + str1 = va_arg(ap, char *);
58523 + ulong2 = va_arg(ap, unsigned long);
58524 + 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);
58525 + break;
58526 + case GR_CAP:
58527 + task = va_arg(ap, struct task_struct *);
58528 + cred = __task_cred(task);
58529 + pcred = __task_cred(task->real_parent);
58530 + str1 = va_arg(ap, char *);
58531 + 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);
58532 + break;
58533 + case GR_SIG:
58534 + str1 = va_arg(ap, char *);
58535 + voidptr = va_arg(ap, void *);
58536 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58537 + break;
58538 + case GR_SIG2:
58539 + task = va_arg(ap, struct task_struct *);
58540 + cred = __task_cred(task);
58541 + pcred = __task_cred(task->real_parent);
58542 + num1 = va_arg(ap, int);
58543 + 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);
58544 + break;
58545 + case GR_CRASH1:
58546 + task = va_arg(ap, struct task_struct *);
58547 + cred = __task_cred(task);
58548 + pcred = __task_cred(task->real_parent);
58549 + ulong1 = va_arg(ap, unsigned long);
58550 + 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);
58551 + break;
58552 + case GR_CRASH2:
58553 + task = va_arg(ap, struct task_struct *);
58554 + cred = __task_cred(task);
58555 + pcred = __task_cred(task->real_parent);
58556 + ulong1 = va_arg(ap, unsigned long);
58557 + 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);
58558 + break;
58559 + case GR_RWXMAP:
58560 + file = va_arg(ap, struct file *);
58561 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58562 + break;
58563 + case GR_PSACCT:
58564 + {
58565 + unsigned int wday, cday;
58566 + __u8 whr, chr;
58567 + __u8 wmin, cmin;
58568 + __u8 wsec, csec;
58569 + char cur_tty[64] = { 0 };
58570 + char parent_tty[64] = { 0 };
58571 +
58572 + task = va_arg(ap, struct task_struct *);
58573 + wday = va_arg(ap, unsigned int);
58574 + cday = va_arg(ap, unsigned int);
58575 + whr = va_arg(ap, int);
58576 + chr = va_arg(ap, int);
58577 + wmin = va_arg(ap, int);
58578 + cmin = va_arg(ap, int);
58579 + wsec = va_arg(ap, int);
58580 + csec = va_arg(ap, int);
58581 + ulong1 = va_arg(ap, unsigned long);
58582 + cred = __task_cred(task);
58583 + pcred = __task_cred(task->real_parent);
58584 +
58585 + 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);
58586 + }
58587 + break;
58588 + default:
58589 + gr_log_middle(audit, msg, ap);
58590 + }
58591 + va_end(ap);
58592 + // these don't need DEFAULTSECARGS printed on the end
58593 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58594 + gr_log_end(audit, 0);
58595 + else
58596 + gr_log_end(audit, 1);
58597 + END_LOCKS(audit);
58598 +}
58599 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58600 new file mode 100644
58601 index 0000000..f536303
58602 --- /dev/null
58603 +++ b/grsecurity/grsec_mem.c
58604 @@ -0,0 +1,40 @@
58605 +#include <linux/kernel.h>
58606 +#include <linux/sched.h>
58607 +#include <linux/mm.h>
58608 +#include <linux/mman.h>
58609 +#include <linux/grinternal.h>
58610 +
58611 +void
58612 +gr_handle_ioperm(void)
58613 +{
58614 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58615 + return;
58616 +}
58617 +
58618 +void
58619 +gr_handle_iopl(void)
58620 +{
58621 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58622 + return;
58623 +}
58624 +
58625 +void
58626 +gr_handle_mem_readwrite(u64 from, u64 to)
58627 +{
58628 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58629 + return;
58630 +}
58631 +
58632 +void
58633 +gr_handle_vm86(void)
58634 +{
58635 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58636 + return;
58637 +}
58638 +
58639 +void
58640 +gr_log_badprocpid(const char *entry)
58641 +{
58642 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58643 + return;
58644 +}
58645 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58646 new file mode 100644
58647 index 0000000..2131422
58648 --- /dev/null
58649 +++ b/grsecurity/grsec_mount.c
58650 @@ -0,0 +1,62 @@
58651 +#include <linux/kernel.h>
58652 +#include <linux/sched.h>
58653 +#include <linux/mount.h>
58654 +#include <linux/grsecurity.h>
58655 +#include <linux/grinternal.h>
58656 +
58657 +void
58658 +gr_log_remount(const char *devname, const int retval)
58659 +{
58660 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58661 + if (grsec_enable_mount && (retval >= 0))
58662 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58663 +#endif
58664 + return;
58665 +}
58666 +
58667 +void
58668 +gr_log_unmount(const char *devname, const int retval)
58669 +{
58670 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58671 + if (grsec_enable_mount && (retval >= 0))
58672 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58673 +#endif
58674 + return;
58675 +}
58676 +
58677 +void
58678 +gr_log_mount(const char *from, const char *to, const int retval)
58679 +{
58680 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58681 + if (grsec_enable_mount && (retval >= 0))
58682 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58683 +#endif
58684 + return;
58685 +}
58686 +
58687 +int
58688 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58689 +{
58690 +#ifdef CONFIG_GRKERNSEC_ROFS
58691 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58692 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58693 + return -EPERM;
58694 + } else
58695 + return 0;
58696 +#endif
58697 + return 0;
58698 +}
58699 +
58700 +int
58701 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58702 +{
58703 +#ifdef CONFIG_GRKERNSEC_ROFS
58704 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58705 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58706 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58707 + return -EPERM;
58708 + } else
58709 + return 0;
58710 +#endif
58711 + return 0;
58712 +}
58713 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58714 new file mode 100644
58715 index 0000000..a3b12a0
58716 --- /dev/null
58717 +++ b/grsecurity/grsec_pax.c
58718 @@ -0,0 +1,36 @@
58719 +#include <linux/kernel.h>
58720 +#include <linux/sched.h>
58721 +#include <linux/mm.h>
58722 +#include <linux/file.h>
58723 +#include <linux/grinternal.h>
58724 +#include <linux/grsecurity.h>
58725 +
58726 +void
58727 +gr_log_textrel(struct vm_area_struct * vma)
58728 +{
58729 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58730 + if (grsec_enable_audit_textrel)
58731 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58732 +#endif
58733 + return;
58734 +}
58735 +
58736 +void
58737 +gr_log_rwxmmap(struct file *file)
58738 +{
58739 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58740 + if (grsec_enable_log_rwxmaps)
58741 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58742 +#endif
58743 + return;
58744 +}
58745 +
58746 +void
58747 +gr_log_rwxmprotect(struct file *file)
58748 +{
58749 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58750 + if (grsec_enable_log_rwxmaps)
58751 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58752 +#endif
58753 + return;
58754 +}
58755 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58756 new file mode 100644
58757 index 0000000..f7f29aa
58758 --- /dev/null
58759 +++ b/grsecurity/grsec_ptrace.c
58760 @@ -0,0 +1,30 @@
58761 +#include <linux/kernel.h>
58762 +#include <linux/sched.h>
58763 +#include <linux/grinternal.h>
58764 +#include <linux/security.h>
58765 +
58766 +void
58767 +gr_audit_ptrace(struct task_struct *task)
58768 +{
58769 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58770 + if (grsec_enable_audit_ptrace)
58771 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58772 +#endif
58773 + return;
58774 +}
58775 +
58776 +int
58777 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
58778 +{
58779 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58780 + const struct dentry *dentry = file->f_path.dentry;
58781 + const struct vfsmount *mnt = file->f_path.mnt;
58782 +
58783 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58784 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58785 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58786 + return -EACCES;
58787 + }
58788 +#endif
58789 + return 0;
58790 +}
58791 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58792 new file mode 100644
58793 index 0000000..7a5b2de
58794 --- /dev/null
58795 +++ b/grsecurity/grsec_sig.c
58796 @@ -0,0 +1,207 @@
58797 +#include <linux/kernel.h>
58798 +#include <linux/sched.h>
58799 +#include <linux/delay.h>
58800 +#include <linux/grsecurity.h>
58801 +#include <linux/grinternal.h>
58802 +#include <linux/hardirq.h>
58803 +
58804 +char *signames[] = {
58805 + [SIGSEGV] = "Segmentation fault",
58806 + [SIGILL] = "Illegal instruction",
58807 + [SIGABRT] = "Abort",
58808 + [SIGBUS] = "Invalid alignment/Bus error"
58809 +};
58810 +
58811 +void
58812 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58813 +{
58814 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58815 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58816 + (sig == SIGABRT) || (sig == SIGBUS))) {
58817 + if (t->pid == current->pid) {
58818 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58819 + } else {
58820 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58821 + }
58822 + }
58823 +#endif
58824 + return;
58825 +}
58826 +
58827 +int
58828 +gr_handle_signal(const struct task_struct *p, const int sig)
58829 +{
58830 +#ifdef CONFIG_GRKERNSEC
58831 + /* ignore the 0 signal for protected task checks */
58832 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58833 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58834 + return -EPERM;
58835 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58836 + return -EPERM;
58837 + }
58838 +#endif
58839 + return 0;
58840 +}
58841 +
58842 +#ifdef CONFIG_GRKERNSEC
58843 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58844 +
58845 +int gr_fake_force_sig(int sig, struct task_struct *t)
58846 +{
58847 + unsigned long int flags;
58848 + int ret, blocked, ignored;
58849 + struct k_sigaction *action;
58850 +
58851 + spin_lock_irqsave(&t->sighand->siglock, flags);
58852 + action = &t->sighand->action[sig-1];
58853 + ignored = action->sa.sa_handler == SIG_IGN;
58854 + blocked = sigismember(&t->blocked, sig);
58855 + if (blocked || ignored) {
58856 + action->sa.sa_handler = SIG_DFL;
58857 + if (blocked) {
58858 + sigdelset(&t->blocked, sig);
58859 + recalc_sigpending_and_wake(t);
58860 + }
58861 + }
58862 + if (action->sa.sa_handler == SIG_DFL)
58863 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58864 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58865 +
58866 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58867 +
58868 + return ret;
58869 +}
58870 +#endif
58871 +
58872 +#ifdef CONFIG_GRKERNSEC_BRUTE
58873 +#define GR_USER_BAN_TIME (15 * 60)
58874 +
58875 +static int __get_dumpable(unsigned long mm_flags)
58876 +{
58877 + int ret;
58878 +
58879 + ret = mm_flags & MMF_DUMPABLE_MASK;
58880 + return (ret >= 2) ? 2 : ret;
58881 +}
58882 +#endif
58883 +
58884 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58885 +{
58886 +#ifdef CONFIG_GRKERNSEC_BRUTE
58887 + uid_t uid = 0;
58888 +
58889 + if (!grsec_enable_brute)
58890 + return;
58891 +
58892 + rcu_read_lock();
58893 + read_lock(&tasklist_lock);
58894 + read_lock(&grsec_exec_file_lock);
58895 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58896 + p->real_parent->brute = 1;
58897 + else {
58898 + const struct cred *cred = __task_cred(p), *cred2;
58899 + struct task_struct *tsk, *tsk2;
58900 +
58901 + if (!__get_dumpable(mm_flags) && cred->uid) {
58902 + struct user_struct *user;
58903 +
58904 + uid = cred->uid;
58905 +
58906 + /* this is put upon execution past expiration */
58907 + user = find_user(uid);
58908 + if (user == NULL)
58909 + goto unlock;
58910 + user->banned = 1;
58911 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58912 + if (user->ban_expires == ~0UL)
58913 + user->ban_expires--;
58914 +
58915 + do_each_thread(tsk2, tsk) {
58916 + cred2 = __task_cred(tsk);
58917 + if (tsk != p && cred2->uid == uid)
58918 + gr_fake_force_sig(SIGKILL, tsk);
58919 + } while_each_thread(tsk2, tsk);
58920 + }
58921 + }
58922 +unlock:
58923 + read_unlock(&grsec_exec_file_lock);
58924 + read_unlock(&tasklist_lock);
58925 + rcu_read_unlock();
58926 +
58927 + if (uid)
58928 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58929 +
58930 +#endif
58931 + return;
58932 +}
58933 +
58934 +void gr_handle_brute_check(void)
58935 +{
58936 +#ifdef CONFIG_GRKERNSEC_BRUTE
58937 + if (current->brute)
58938 + msleep(30 * 1000);
58939 +#endif
58940 + return;
58941 +}
58942 +
58943 +void gr_handle_kernel_exploit(void)
58944 +{
58945 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58946 + const struct cred *cred;
58947 + struct task_struct *tsk, *tsk2;
58948 + struct user_struct *user;
58949 + uid_t uid;
58950 +
58951 + if (in_irq() || in_serving_softirq() || in_nmi())
58952 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58953 +
58954 + uid = current_uid();
58955 +
58956 + if (uid == 0)
58957 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
58958 + else {
58959 + /* kill all the processes of this user, hold a reference
58960 + to their creds struct, and prevent them from creating
58961 + another process until system reset
58962 + */
58963 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58964 + /* we intentionally leak this ref */
58965 + user = get_uid(current->cred->user);
58966 + if (user) {
58967 + user->banned = 1;
58968 + user->ban_expires = ~0UL;
58969 + }
58970 +
58971 + read_lock(&tasklist_lock);
58972 + do_each_thread(tsk2, tsk) {
58973 + cred = __task_cred(tsk);
58974 + if (cred->uid == uid)
58975 + gr_fake_force_sig(SIGKILL, tsk);
58976 + } while_each_thread(tsk2, tsk);
58977 + read_unlock(&tasklist_lock);
58978 + }
58979 +#endif
58980 +}
58981 +
58982 +int __gr_process_user_ban(struct user_struct *user)
58983 +{
58984 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58985 + if (unlikely(user->banned)) {
58986 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58987 + user->banned = 0;
58988 + user->ban_expires = 0;
58989 + free_uid(user);
58990 + } else
58991 + return -EPERM;
58992 + }
58993 +#endif
58994 + return 0;
58995 +}
58996 +
58997 +int gr_process_user_ban(void)
58998 +{
58999 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59000 + return __gr_process_user_ban(current->cred->user);
59001 +#endif
59002 + return 0;
59003 +}
59004 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59005 new file mode 100644
59006 index 0000000..4030d57
59007 --- /dev/null
59008 +++ b/grsecurity/grsec_sock.c
59009 @@ -0,0 +1,244 @@
59010 +#include <linux/kernel.h>
59011 +#include <linux/module.h>
59012 +#include <linux/sched.h>
59013 +#include <linux/file.h>
59014 +#include <linux/net.h>
59015 +#include <linux/in.h>
59016 +#include <linux/ip.h>
59017 +#include <net/sock.h>
59018 +#include <net/inet_sock.h>
59019 +#include <linux/grsecurity.h>
59020 +#include <linux/grinternal.h>
59021 +#include <linux/gracl.h>
59022 +
59023 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59024 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59025 +
59026 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59027 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59028 +
59029 +#ifdef CONFIG_UNIX_MODULE
59030 +EXPORT_SYMBOL(gr_acl_handle_unix);
59031 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59032 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59033 +EXPORT_SYMBOL(gr_handle_create);
59034 +#endif
59035 +
59036 +#ifdef CONFIG_GRKERNSEC
59037 +#define gr_conn_table_size 32749
59038 +struct conn_table_entry {
59039 + struct conn_table_entry *next;
59040 + struct signal_struct *sig;
59041 +};
59042 +
59043 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59044 +DEFINE_SPINLOCK(gr_conn_table_lock);
59045 +
59046 +extern const char * gr_socktype_to_name(unsigned char type);
59047 +extern const char * gr_proto_to_name(unsigned char proto);
59048 +extern const char * gr_sockfamily_to_name(unsigned char family);
59049 +
59050 +static __inline__ int
59051 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59052 +{
59053 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59054 +}
59055 +
59056 +static __inline__ int
59057 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59058 + __u16 sport, __u16 dport)
59059 +{
59060 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59061 + sig->gr_sport == sport && sig->gr_dport == dport))
59062 + return 1;
59063 + else
59064 + return 0;
59065 +}
59066 +
59067 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59068 +{
59069 + struct conn_table_entry **match;
59070 + unsigned int index;
59071 +
59072 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59073 + sig->gr_sport, sig->gr_dport,
59074 + gr_conn_table_size);
59075 +
59076 + newent->sig = sig;
59077 +
59078 + match = &gr_conn_table[index];
59079 + newent->next = *match;
59080 + *match = newent;
59081 +
59082 + return;
59083 +}
59084 +
59085 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59086 +{
59087 + struct conn_table_entry *match, *last = NULL;
59088 + unsigned int index;
59089 +
59090 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59091 + sig->gr_sport, sig->gr_dport,
59092 + gr_conn_table_size);
59093 +
59094 + match = gr_conn_table[index];
59095 + while (match && !conn_match(match->sig,
59096 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59097 + sig->gr_dport)) {
59098 + last = match;
59099 + match = match->next;
59100 + }
59101 +
59102 + if (match) {
59103 + if (last)
59104 + last->next = match->next;
59105 + else
59106 + gr_conn_table[index] = NULL;
59107 + kfree(match);
59108 + }
59109 +
59110 + return;
59111 +}
59112 +
59113 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59114 + __u16 sport, __u16 dport)
59115 +{
59116 + struct conn_table_entry *match;
59117 + unsigned int index;
59118 +
59119 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59120 +
59121 + match = gr_conn_table[index];
59122 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59123 + match = match->next;
59124 +
59125 + if (match)
59126 + return match->sig;
59127 + else
59128 + return NULL;
59129 +}
59130 +
59131 +#endif
59132 +
59133 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59134 +{
59135 +#ifdef CONFIG_GRKERNSEC
59136 + struct signal_struct *sig = task->signal;
59137 + struct conn_table_entry *newent;
59138 +
59139 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59140 + if (newent == NULL)
59141 + return;
59142 + /* no bh lock needed since we are called with bh disabled */
59143 + spin_lock(&gr_conn_table_lock);
59144 + gr_del_task_from_ip_table_nolock(sig);
59145 + sig->gr_saddr = inet->inet_rcv_saddr;
59146 + sig->gr_daddr = inet->inet_daddr;
59147 + sig->gr_sport = inet->inet_sport;
59148 + sig->gr_dport = inet->inet_dport;
59149 + gr_add_to_task_ip_table_nolock(sig, newent);
59150 + spin_unlock(&gr_conn_table_lock);
59151 +#endif
59152 + return;
59153 +}
59154 +
59155 +void gr_del_task_from_ip_table(struct task_struct *task)
59156 +{
59157 +#ifdef CONFIG_GRKERNSEC
59158 + spin_lock_bh(&gr_conn_table_lock);
59159 + gr_del_task_from_ip_table_nolock(task->signal);
59160 + spin_unlock_bh(&gr_conn_table_lock);
59161 +#endif
59162 + return;
59163 +}
59164 +
59165 +void
59166 +gr_attach_curr_ip(const struct sock *sk)
59167 +{
59168 +#ifdef CONFIG_GRKERNSEC
59169 + struct signal_struct *p, *set;
59170 + const struct inet_sock *inet = inet_sk(sk);
59171 +
59172 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59173 + return;
59174 +
59175 + set = current->signal;
59176 +
59177 + spin_lock_bh(&gr_conn_table_lock);
59178 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59179 + inet->inet_dport, inet->inet_sport);
59180 + if (unlikely(p != NULL)) {
59181 + set->curr_ip = p->curr_ip;
59182 + set->used_accept = 1;
59183 + gr_del_task_from_ip_table_nolock(p);
59184 + spin_unlock_bh(&gr_conn_table_lock);
59185 + return;
59186 + }
59187 + spin_unlock_bh(&gr_conn_table_lock);
59188 +
59189 + set->curr_ip = inet->inet_daddr;
59190 + set->used_accept = 1;
59191 +#endif
59192 + return;
59193 +}
59194 +
59195 +int
59196 +gr_handle_sock_all(const int family, const int type, const int protocol)
59197 +{
59198 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59199 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59200 + (family != AF_UNIX)) {
59201 + if (family == AF_INET)
59202 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59203 + else
59204 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59205 + return -EACCES;
59206 + }
59207 +#endif
59208 + return 0;
59209 +}
59210 +
59211 +int
59212 +gr_handle_sock_server(const struct sockaddr *sck)
59213 +{
59214 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59215 + if (grsec_enable_socket_server &&
59216 + in_group_p(grsec_socket_server_gid) &&
59217 + sck && (sck->sa_family != AF_UNIX) &&
59218 + (sck->sa_family != AF_LOCAL)) {
59219 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59220 + return -EACCES;
59221 + }
59222 +#endif
59223 + return 0;
59224 +}
59225 +
59226 +int
59227 +gr_handle_sock_server_other(const struct sock *sck)
59228 +{
59229 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59230 + if (grsec_enable_socket_server &&
59231 + in_group_p(grsec_socket_server_gid) &&
59232 + sck && (sck->sk_family != AF_UNIX) &&
59233 + (sck->sk_family != AF_LOCAL)) {
59234 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59235 + return -EACCES;
59236 + }
59237 +#endif
59238 + return 0;
59239 +}
59240 +
59241 +int
59242 +gr_handle_sock_client(const struct sockaddr *sck)
59243 +{
59244 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59245 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59246 + sck && (sck->sa_family != AF_UNIX) &&
59247 + (sck->sa_family != AF_LOCAL)) {
59248 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59249 + return -EACCES;
59250 + }
59251 +#endif
59252 + return 0;
59253 +}
59254 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59255 new file mode 100644
59256 index 0000000..a1aedd7
59257 --- /dev/null
59258 +++ b/grsecurity/grsec_sysctl.c
59259 @@ -0,0 +1,451 @@
59260 +#include <linux/kernel.h>
59261 +#include <linux/sched.h>
59262 +#include <linux/sysctl.h>
59263 +#include <linux/grsecurity.h>
59264 +#include <linux/grinternal.h>
59265 +
59266 +int
59267 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59268 +{
59269 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59270 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59271 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59272 + return -EACCES;
59273 + }
59274 +#endif
59275 + return 0;
59276 +}
59277 +
59278 +#ifdef CONFIG_GRKERNSEC_ROFS
59279 +static int __maybe_unused one = 1;
59280 +#endif
59281 +
59282 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59283 +struct ctl_table grsecurity_table[] = {
59284 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59285 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59286 +#ifdef CONFIG_GRKERNSEC_IO
59287 + {
59288 + .procname = "disable_priv_io",
59289 + .data = &grsec_disable_privio,
59290 + .maxlen = sizeof(int),
59291 + .mode = 0600,
59292 + .proc_handler = &proc_dointvec,
59293 + },
59294 +#endif
59295 +#endif
59296 +#ifdef CONFIG_GRKERNSEC_LINK
59297 + {
59298 + .procname = "linking_restrictions",
59299 + .data = &grsec_enable_link,
59300 + .maxlen = sizeof(int),
59301 + .mode = 0600,
59302 + .proc_handler = &proc_dointvec,
59303 + },
59304 +#endif
59305 +#ifdef CONFIG_GRKERNSEC_BRUTE
59306 + {
59307 + .procname = "deter_bruteforce",
59308 + .data = &grsec_enable_brute,
59309 + .maxlen = sizeof(int),
59310 + .mode = 0600,
59311 + .proc_handler = &proc_dointvec,
59312 + },
59313 +#endif
59314 +#ifdef CONFIG_GRKERNSEC_FIFO
59315 + {
59316 + .procname = "fifo_restrictions",
59317 + .data = &grsec_enable_fifo,
59318 + .maxlen = sizeof(int),
59319 + .mode = 0600,
59320 + .proc_handler = &proc_dointvec,
59321 + },
59322 +#endif
59323 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59324 + {
59325 + .procname = "ptrace_readexec",
59326 + .data = &grsec_enable_ptrace_readexec,
59327 + .maxlen = sizeof(int),
59328 + .mode = 0600,
59329 + .proc_handler = &proc_dointvec,
59330 + },
59331 +#endif
59332 +#ifdef CONFIG_GRKERNSEC_SETXID
59333 + {
59334 + .procname = "consistent_setxid",
59335 + .data = &grsec_enable_setxid,
59336 + .maxlen = sizeof(int),
59337 + .mode = 0600,
59338 + .proc_handler = &proc_dointvec,
59339 + },
59340 +#endif
59341 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59342 + {
59343 + .procname = "ip_blackhole",
59344 + .data = &grsec_enable_blackhole,
59345 + .maxlen = sizeof(int),
59346 + .mode = 0600,
59347 + .proc_handler = &proc_dointvec,
59348 + },
59349 + {
59350 + .procname = "lastack_retries",
59351 + .data = &grsec_lastack_retries,
59352 + .maxlen = sizeof(int),
59353 + .mode = 0600,
59354 + .proc_handler = &proc_dointvec,
59355 + },
59356 +#endif
59357 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59358 + {
59359 + .procname = "exec_logging",
59360 + .data = &grsec_enable_execlog,
59361 + .maxlen = sizeof(int),
59362 + .mode = 0600,
59363 + .proc_handler = &proc_dointvec,
59364 + },
59365 +#endif
59366 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59367 + {
59368 + .procname = "rwxmap_logging",
59369 + .data = &grsec_enable_log_rwxmaps,
59370 + .maxlen = sizeof(int),
59371 + .mode = 0600,
59372 + .proc_handler = &proc_dointvec,
59373 + },
59374 +#endif
59375 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59376 + {
59377 + .procname = "signal_logging",
59378 + .data = &grsec_enable_signal,
59379 + .maxlen = sizeof(int),
59380 + .mode = 0600,
59381 + .proc_handler = &proc_dointvec,
59382 + },
59383 +#endif
59384 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59385 + {
59386 + .procname = "forkfail_logging",
59387 + .data = &grsec_enable_forkfail,
59388 + .maxlen = sizeof(int),
59389 + .mode = 0600,
59390 + .proc_handler = &proc_dointvec,
59391 + },
59392 +#endif
59393 +#ifdef CONFIG_GRKERNSEC_TIME
59394 + {
59395 + .procname = "timechange_logging",
59396 + .data = &grsec_enable_time,
59397 + .maxlen = sizeof(int),
59398 + .mode = 0600,
59399 + .proc_handler = &proc_dointvec,
59400 + },
59401 +#endif
59402 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59403 + {
59404 + .procname = "chroot_deny_shmat",
59405 + .data = &grsec_enable_chroot_shmat,
59406 + .maxlen = sizeof(int),
59407 + .mode = 0600,
59408 + .proc_handler = &proc_dointvec,
59409 + },
59410 +#endif
59411 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59412 + {
59413 + .procname = "chroot_deny_unix",
59414 + .data = &grsec_enable_chroot_unix,
59415 + .maxlen = sizeof(int),
59416 + .mode = 0600,
59417 + .proc_handler = &proc_dointvec,
59418 + },
59419 +#endif
59420 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59421 + {
59422 + .procname = "chroot_deny_mount",
59423 + .data = &grsec_enable_chroot_mount,
59424 + .maxlen = sizeof(int),
59425 + .mode = 0600,
59426 + .proc_handler = &proc_dointvec,
59427 + },
59428 +#endif
59429 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59430 + {
59431 + .procname = "chroot_deny_fchdir",
59432 + .data = &grsec_enable_chroot_fchdir,
59433 + .maxlen = sizeof(int),
59434 + .mode = 0600,
59435 + .proc_handler = &proc_dointvec,
59436 + },
59437 +#endif
59438 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59439 + {
59440 + .procname = "chroot_deny_chroot",
59441 + .data = &grsec_enable_chroot_double,
59442 + .maxlen = sizeof(int),
59443 + .mode = 0600,
59444 + .proc_handler = &proc_dointvec,
59445 + },
59446 +#endif
59447 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59448 + {
59449 + .procname = "chroot_deny_pivot",
59450 + .data = &grsec_enable_chroot_pivot,
59451 + .maxlen = sizeof(int),
59452 + .mode = 0600,
59453 + .proc_handler = &proc_dointvec,
59454 + },
59455 +#endif
59456 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59457 + {
59458 + .procname = "chroot_enforce_chdir",
59459 + .data = &grsec_enable_chroot_chdir,
59460 + .maxlen = sizeof(int),
59461 + .mode = 0600,
59462 + .proc_handler = &proc_dointvec,
59463 + },
59464 +#endif
59465 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59466 + {
59467 + .procname = "chroot_deny_chmod",
59468 + .data = &grsec_enable_chroot_chmod,
59469 + .maxlen = sizeof(int),
59470 + .mode = 0600,
59471 + .proc_handler = &proc_dointvec,
59472 + },
59473 +#endif
59474 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59475 + {
59476 + .procname = "chroot_deny_mknod",
59477 + .data = &grsec_enable_chroot_mknod,
59478 + .maxlen = sizeof(int),
59479 + .mode = 0600,
59480 + .proc_handler = &proc_dointvec,
59481 + },
59482 +#endif
59483 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59484 + {
59485 + .procname = "chroot_restrict_nice",
59486 + .data = &grsec_enable_chroot_nice,
59487 + .maxlen = sizeof(int),
59488 + .mode = 0600,
59489 + .proc_handler = &proc_dointvec,
59490 + },
59491 +#endif
59492 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59493 + {
59494 + .procname = "chroot_execlog",
59495 + .data = &grsec_enable_chroot_execlog,
59496 + .maxlen = sizeof(int),
59497 + .mode = 0600,
59498 + .proc_handler = &proc_dointvec,
59499 + },
59500 +#endif
59501 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59502 + {
59503 + .procname = "chroot_caps",
59504 + .data = &grsec_enable_chroot_caps,
59505 + .maxlen = sizeof(int),
59506 + .mode = 0600,
59507 + .proc_handler = &proc_dointvec,
59508 + },
59509 +#endif
59510 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59511 + {
59512 + .procname = "chroot_deny_sysctl",
59513 + .data = &grsec_enable_chroot_sysctl,
59514 + .maxlen = sizeof(int),
59515 + .mode = 0600,
59516 + .proc_handler = &proc_dointvec,
59517 + },
59518 +#endif
59519 +#ifdef CONFIG_GRKERNSEC_TPE
59520 + {
59521 + .procname = "tpe",
59522 + .data = &grsec_enable_tpe,
59523 + .maxlen = sizeof(int),
59524 + .mode = 0600,
59525 + .proc_handler = &proc_dointvec,
59526 + },
59527 + {
59528 + .procname = "tpe_gid",
59529 + .data = &grsec_tpe_gid,
59530 + .maxlen = sizeof(int),
59531 + .mode = 0600,
59532 + .proc_handler = &proc_dointvec,
59533 + },
59534 +#endif
59535 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59536 + {
59537 + .procname = "tpe_invert",
59538 + .data = &grsec_enable_tpe_invert,
59539 + .maxlen = sizeof(int),
59540 + .mode = 0600,
59541 + .proc_handler = &proc_dointvec,
59542 + },
59543 +#endif
59544 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59545 + {
59546 + .procname = "tpe_restrict_all",
59547 + .data = &grsec_enable_tpe_all,
59548 + .maxlen = sizeof(int),
59549 + .mode = 0600,
59550 + .proc_handler = &proc_dointvec,
59551 + },
59552 +#endif
59553 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59554 + {
59555 + .procname = "socket_all",
59556 + .data = &grsec_enable_socket_all,
59557 + .maxlen = sizeof(int),
59558 + .mode = 0600,
59559 + .proc_handler = &proc_dointvec,
59560 + },
59561 + {
59562 + .procname = "socket_all_gid",
59563 + .data = &grsec_socket_all_gid,
59564 + .maxlen = sizeof(int),
59565 + .mode = 0600,
59566 + .proc_handler = &proc_dointvec,
59567 + },
59568 +#endif
59569 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59570 + {
59571 + .procname = "socket_client",
59572 + .data = &grsec_enable_socket_client,
59573 + .maxlen = sizeof(int),
59574 + .mode = 0600,
59575 + .proc_handler = &proc_dointvec,
59576 + },
59577 + {
59578 + .procname = "socket_client_gid",
59579 + .data = &grsec_socket_client_gid,
59580 + .maxlen = sizeof(int),
59581 + .mode = 0600,
59582 + .proc_handler = &proc_dointvec,
59583 + },
59584 +#endif
59585 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59586 + {
59587 + .procname = "socket_server",
59588 + .data = &grsec_enable_socket_server,
59589 + .maxlen = sizeof(int),
59590 + .mode = 0600,
59591 + .proc_handler = &proc_dointvec,
59592 + },
59593 + {
59594 + .procname = "socket_server_gid",
59595 + .data = &grsec_socket_server_gid,
59596 + .maxlen = sizeof(int),
59597 + .mode = 0600,
59598 + .proc_handler = &proc_dointvec,
59599 + },
59600 +#endif
59601 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59602 + {
59603 + .procname = "audit_group",
59604 + .data = &grsec_enable_group,
59605 + .maxlen = sizeof(int),
59606 + .mode = 0600,
59607 + .proc_handler = &proc_dointvec,
59608 + },
59609 + {
59610 + .procname = "audit_gid",
59611 + .data = &grsec_audit_gid,
59612 + .maxlen = sizeof(int),
59613 + .mode = 0600,
59614 + .proc_handler = &proc_dointvec,
59615 + },
59616 +#endif
59617 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59618 + {
59619 + .procname = "audit_chdir",
59620 + .data = &grsec_enable_chdir,
59621 + .maxlen = sizeof(int),
59622 + .mode = 0600,
59623 + .proc_handler = &proc_dointvec,
59624 + },
59625 +#endif
59626 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59627 + {
59628 + .procname = "audit_mount",
59629 + .data = &grsec_enable_mount,
59630 + .maxlen = sizeof(int),
59631 + .mode = 0600,
59632 + .proc_handler = &proc_dointvec,
59633 + },
59634 +#endif
59635 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59636 + {
59637 + .procname = "audit_textrel",
59638 + .data = &grsec_enable_audit_textrel,
59639 + .maxlen = sizeof(int),
59640 + .mode = 0600,
59641 + .proc_handler = &proc_dointvec,
59642 + },
59643 +#endif
59644 +#ifdef CONFIG_GRKERNSEC_DMESG
59645 + {
59646 + .procname = "dmesg",
59647 + .data = &grsec_enable_dmesg,
59648 + .maxlen = sizeof(int),
59649 + .mode = 0600,
59650 + .proc_handler = &proc_dointvec,
59651 + },
59652 +#endif
59653 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59654 + {
59655 + .procname = "chroot_findtask",
59656 + .data = &grsec_enable_chroot_findtask,
59657 + .maxlen = sizeof(int),
59658 + .mode = 0600,
59659 + .proc_handler = &proc_dointvec,
59660 + },
59661 +#endif
59662 +#ifdef CONFIG_GRKERNSEC_RESLOG
59663 + {
59664 + .procname = "resource_logging",
59665 + .data = &grsec_resource_logging,
59666 + .maxlen = sizeof(int),
59667 + .mode = 0600,
59668 + .proc_handler = &proc_dointvec,
59669 + },
59670 +#endif
59671 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59672 + {
59673 + .procname = "audit_ptrace",
59674 + .data = &grsec_enable_audit_ptrace,
59675 + .maxlen = sizeof(int),
59676 + .mode = 0600,
59677 + .proc_handler = &proc_dointvec,
59678 + },
59679 +#endif
59680 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59681 + {
59682 + .procname = "harden_ptrace",
59683 + .data = &grsec_enable_harden_ptrace,
59684 + .maxlen = sizeof(int),
59685 + .mode = 0600,
59686 + .proc_handler = &proc_dointvec,
59687 + },
59688 +#endif
59689 + {
59690 + .procname = "grsec_lock",
59691 + .data = &grsec_lock,
59692 + .maxlen = sizeof(int),
59693 + .mode = 0600,
59694 + .proc_handler = &proc_dointvec,
59695 + },
59696 +#endif
59697 +#ifdef CONFIG_GRKERNSEC_ROFS
59698 + {
59699 + .procname = "romount_protect",
59700 + .data = &grsec_enable_rofs,
59701 + .maxlen = sizeof(int),
59702 + .mode = 0600,
59703 + .proc_handler = &proc_dointvec_minmax,
59704 + .extra1 = &one,
59705 + .extra2 = &one,
59706 + },
59707 +#endif
59708 + { }
59709 +};
59710 +#endif
59711 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59712 new file mode 100644
59713 index 0000000..0dc13c3
59714 --- /dev/null
59715 +++ b/grsecurity/grsec_time.c
59716 @@ -0,0 +1,16 @@
59717 +#include <linux/kernel.h>
59718 +#include <linux/sched.h>
59719 +#include <linux/grinternal.h>
59720 +#include <linux/module.h>
59721 +
59722 +void
59723 +gr_log_timechange(void)
59724 +{
59725 +#ifdef CONFIG_GRKERNSEC_TIME
59726 + if (grsec_enable_time)
59727 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59728 +#endif
59729 + return;
59730 +}
59731 +
59732 +EXPORT_SYMBOL(gr_log_timechange);
59733 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59734 new file mode 100644
59735 index 0000000..07e0dc0
59736 --- /dev/null
59737 +++ b/grsecurity/grsec_tpe.c
59738 @@ -0,0 +1,73 @@
59739 +#include <linux/kernel.h>
59740 +#include <linux/sched.h>
59741 +#include <linux/file.h>
59742 +#include <linux/fs.h>
59743 +#include <linux/grinternal.h>
59744 +
59745 +extern int gr_acl_tpe_check(void);
59746 +
59747 +int
59748 +gr_tpe_allow(const struct file *file)
59749 +{
59750 +#ifdef CONFIG_GRKERNSEC
59751 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59752 + const struct cred *cred = current_cred();
59753 + char *msg = NULL;
59754 + char *msg2 = NULL;
59755 +
59756 + // never restrict root
59757 + if (!cred->uid)
59758 + return 1;
59759 +
59760 + if (grsec_enable_tpe) {
59761 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59762 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59763 + msg = "not being in trusted group";
59764 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59765 + msg = "being in untrusted group";
59766 +#else
59767 + if (in_group_p(grsec_tpe_gid))
59768 + msg = "being in untrusted group";
59769 +#endif
59770 + }
59771 + if (!msg && gr_acl_tpe_check())
59772 + msg = "being in untrusted role";
59773 +
59774 + // not in any affected group/role
59775 + if (!msg)
59776 + goto next_check;
59777 +
59778 + if (inode->i_uid)
59779 + msg2 = "file in non-root-owned directory";
59780 + else if (inode->i_mode & S_IWOTH)
59781 + msg2 = "file in world-writable directory";
59782 + else if (inode->i_mode & S_IWGRP)
59783 + msg2 = "file in group-writable directory";
59784 +
59785 + if (msg && msg2) {
59786 + char fullmsg[70] = {0};
59787 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59788 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59789 + return 0;
59790 + }
59791 + msg = NULL;
59792 +next_check:
59793 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59794 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59795 + return 1;
59796 +
59797 + if (inode->i_uid && (inode->i_uid != cred->uid))
59798 + msg = "directory not owned by user";
59799 + else if (inode->i_mode & S_IWOTH)
59800 + msg = "file in world-writable directory";
59801 + else if (inode->i_mode & S_IWGRP)
59802 + msg = "file in group-writable directory";
59803 +
59804 + if (msg) {
59805 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59806 + return 0;
59807 + }
59808 +#endif
59809 +#endif
59810 + return 1;
59811 +}
59812 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59813 new file mode 100644
59814 index 0000000..9f7b1ac
59815 --- /dev/null
59816 +++ b/grsecurity/grsum.c
59817 @@ -0,0 +1,61 @@
59818 +#include <linux/err.h>
59819 +#include <linux/kernel.h>
59820 +#include <linux/sched.h>
59821 +#include <linux/mm.h>
59822 +#include <linux/scatterlist.h>
59823 +#include <linux/crypto.h>
59824 +#include <linux/gracl.h>
59825 +
59826 +
59827 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59828 +#error "crypto and sha256 must be built into the kernel"
59829 +#endif
59830 +
59831 +int
59832 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59833 +{
59834 + char *p;
59835 + struct crypto_hash *tfm;
59836 + struct hash_desc desc;
59837 + struct scatterlist sg;
59838 + unsigned char temp_sum[GR_SHA_LEN];
59839 + volatile int retval = 0;
59840 + volatile int dummy = 0;
59841 + unsigned int i;
59842 +
59843 + sg_init_table(&sg, 1);
59844 +
59845 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59846 + if (IS_ERR(tfm)) {
59847 + /* should never happen, since sha256 should be built in */
59848 + return 1;
59849 + }
59850 +
59851 + desc.tfm = tfm;
59852 + desc.flags = 0;
59853 +
59854 + crypto_hash_init(&desc);
59855 +
59856 + p = salt;
59857 + sg_set_buf(&sg, p, GR_SALT_LEN);
59858 + crypto_hash_update(&desc, &sg, sg.length);
59859 +
59860 + p = entry->pw;
59861 + sg_set_buf(&sg, p, strlen(p));
59862 +
59863 + crypto_hash_update(&desc, &sg, sg.length);
59864 +
59865 + crypto_hash_final(&desc, temp_sum);
59866 +
59867 + memset(entry->pw, 0, GR_PW_LEN);
59868 +
59869 + for (i = 0; i < GR_SHA_LEN; i++)
59870 + if (sum[i] != temp_sum[i])
59871 + retval = 1;
59872 + else
59873 + dummy = 1; // waste a cycle
59874 +
59875 + crypto_free_hash(tfm);
59876 +
59877 + return retval;
59878 +}
59879 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59880 index 6cd5b64..f620d2d 100644
59881 --- a/include/acpi/acpi_bus.h
59882 +++ b/include/acpi/acpi_bus.h
59883 @@ -107,7 +107,7 @@ struct acpi_device_ops {
59884 acpi_op_bind bind;
59885 acpi_op_unbind unbind;
59886 acpi_op_notify notify;
59887 -};
59888 +} __no_const;
59889
59890 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59891
59892 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59893 index b7babf0..71e4e74 100644
59894 --- a/include/asm-generic/atomic-long.h
59895 +++ b/include/asm-generic/atomic-long.h
59896 @@ -22,6 +22,12 @@
59897
59898 typedef atomic64_t atomic_long_t;
59899
59900 +#ifdef CONFIG_PAX_REFCOUNT
59901 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
59902 +#else
59903 +typedef atomic64_t atomic_long_unchecked_t;
59904 +#endif
59905 +
59906 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59907
59908 static inline long atomic_long_read(atomic_long_t *l)
59909 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59910 return (long)atomic64_read(v);
59911 }
59912
59913 +#ifdef CONFIG_PAX_REFCOUNT
59914 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59915 +{
59916 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59917 +
59918 + return (long)atomic64_read_unchecked(v);
59919 +}
59920 +#endif
59921 +
59922 static inline void atomic_long_set(atomic_long_t *l, long i)
59923 {
59924 atomic64_t *v = (atomic64_t *)l;
59925 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59926 atomic64_set(v, i);
59927 }
59928
59929 +#ifdef CONFIG_PAX_REFCOUNT
59930 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59931 +{
59932 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59933 +
59934 + atomic64_set_unchecked(v, i);
59935 +}
59936 +#endif
59937 +
59938 static inline void atomic_long_inc(atomic_long_t *l)
59939 {
59940 atomic64_t *v = (atomic64_t *)l;
59941 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59942 atomic64_inc(v);
59943 }
59944
59945 +#ifdef CONFIG_PAX_REFCOUNT
59946 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59947 +{
59948 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59949 +
59950 + atomic64_inc_unchecked(v);
59951 +}
59952 +#endif
59953 +
59954 static inline void atomic_long_dec(atomic_long_t *l)
59955 {
59956 atomic64_t *v = (atomic64_t *)l;
59957 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59958 atomic64_dec(v);
59959 }
59960
59961 +#ifdef CONFIG_PAX_REFCOUNT
59962 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59963 +{
59964 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59965 +
59966 + atomic64_dec_unchecked(v);
59967 +}
59968 +#endif
59969 +
59970 static inline void atomic_long_add(long i, atomic_long_t *l)
59971 {
59972 atomic64_t *v = (atomic64_t *)l;
59973 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59974 atomic64_add(i, v);
59975 }
59976
59977 +#ifdef CONFIG_PAX_REFCOUNT
59978 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59979 +{
59980 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59981 +
59982 + atomic64_add_unchecked(i, v);
59983 +}
59984 +#endif
59985 +
59986 static inline void atomic_long_sub(long i, atomic_long_t *l)
59987 {
59988 atomic64_t *v = (atomic64_t *)l;
59989 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59990 atomic64_sub(i, v);
59991 }
59992
59993 +#ifdef CONFIG_PAX_REFCOUNT
59994 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59995 +{
59996 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59997 +
59998 + atomic64_sub_unchecked(i, v);
59999 +}
60000 +#endif
60001 +
60002 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60003 {
60004 atomic64_t *v = (atomic64_t *)l;
60005 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60006 return (long)atomic64_inc_return(v);
60007 }
60008
60009 +#ifdef CONFIG_PAX_REFCOUNT
60010 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60011 +{
60012 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60013 +
60014 + return (long)atomic64_inc_return_unchecked(v);
60015 +}
60016 +#endif
60017 +
60018 static inline long atomic_long_dec_return(atomic_long_t *l)
60019 {
60020 atomic64_t *v = (atomic64_t *)l;
60021 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60022
60023 typedef atomic_t atomic_long_t;
60024
60025 +#ifdef CONFIG_PAX_REFCOUNT
60026 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60027 +#else
60028 +typedef atomic_t atomic_long_unchecked_t;
60029 +#endif
60030 +
60031 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60032 static inline long atomic_long_read(atomic_long_t *l)
60033 {
60034 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60035 return (long)atomic_read(v);
60036 }
60037
60038 +#ifdef CONFIG_PAX_REFCOUNT
60039 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60040 +{
60041 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60042 +
60043 + return (long)atomic_read_unchecked(v);
60044 +}
60045 +#endif
60046 +
60047 static inline void atomic_long_set(atomic_long_t *l, long i)
60048 {
60049 atomic_t *v = (atomic_t *)l;
60050 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60051 atomic_set(v, i);
60052 }
60053
60054 +#ifdef CONFIG_PAX_REFCOUNT
60055 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60056 +{
60057 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60058 +
60059 + atomic_set_unchecked(v, i);
60060 +}
60061 +#endif
60062 +
60063 static inline void atomic_long_inc(atomic_long_t *l)
60064 {
60065 atomic_t *v = (atomic_t *)l;
60066 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60067 atomic_inc(v);
60068 }
60069
60070 +#ifdef CONFIG_PAX_REFCOUNT
60071 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60072 +{
60073 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60074 +
60075 + atomic_inc_unchecked(v);
60076 +}
60077 +#endif
60078 +
60079 static inline void atomic_long_dec(atomic_long_t *l)
60080 {
60081 atomic_t *v = (atomic_t *)l;
60082 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60083 atomic_dec(v);
60084 }
60085
60086 +#ifdef CONFIG_PAX_REFCOUNT
60087 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60088 +{
60089 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60090 +
60091 + atomic_dec_unchecked(v);
60092 +}
60093 +#endif
60094 +
60095 static inline void atomic_long_add(long i, atomic_long_t *l)
60096 {
60097 atomic_t *v = (atomic_t *)l;
60098 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60099 atomic_add(i, v);
60100 }
60101
60102 +#ifdef CONFIG_PAX_REFCOUNT
60103 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60104 +{
60105 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60106 +
60107 + atomic_add_unchecked(i, v);
60108 +}
60109 +#endif
60110 +
60111 static inline void atomic_long_sub(long i, atomic_long_t *l)
60112 {
60113 atomic_t *v = (atomic_t *)l;
60114 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60115 atomic_sub(i, v);
60116 }
60117
60118 +#ifdef CONFIG_PAX_REFCOUNT
60119 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60120 +{
60121 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60122 +
60123 + atomic_sub_unchecked(i, v);
60124 +}
60125 +#endif
60126 +
60127 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60128 {
60129 atomic_t *v = (atomic_t *)l;
60130 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60131 return (long)atomic_inc_return(v);
60132 }
60133
60134 +#ifdef CONFIG_PAX_REFCOUNT
60135 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60136 +{
60137 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60138 +
60139 + return (long)atomic_inc_return_unchecked(v);
60140 +}
60141 +#endif
60142 +
60143 static inline long atomic_long_dec_return(atomic_long_t *l)
60144 {
60145 atomic_t *v = (atomic_t *)l;
60146 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60147
60148 #endif /* BITS_PER_LONG == 64 */
60149
60150 +#ifdef CONFIG_PAX_REFCOUNT
60151 +static inline void pax_refcount_needs_these_functions(void)
60152 +{
60153 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60154 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60155 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60156 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60157 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60158 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60159 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60160 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60161 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60162 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60163 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60164 +
60165 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60166 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60167 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60168 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60169 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60170 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60171 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60172 +}
60173 +#else
60174 +#define atomic_read_unchecked(v) atomic_read(v)
60175 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60176 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60177 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60178 +#define atomic_inc_unchecked(v) atomic_inc(v)
60179 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60180 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60181 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60182 +#define atomic_dec_unchecked(v) atomic_dec(v)
60183 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60184 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60185 +
60186 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60187 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60188 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60189 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60190 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60191 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60192 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60193 +#endif
60194 +
60195 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60196 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60197 index b18ce4f..2ee2843 100644
60198 --- a/include/asm-generic/atomic64.h
60199 +++ b/include/asm-generic/atomic64.h
60200 @@ -16,6 +16,8 @@ typedef struct {
60201 long long counter;
60202 } atomic64_t;
60203
60204 +typedef atomic64_t atomic64_unchecked_t;
60205 +
60206 #define ATOMIC64_INIT(i) { (i) }
60207
60208 extern long long atomic64_read(const atomic64_t *v);
60209 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60210 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60211 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60212
60213 +#define atomic64_read_unchecked(v) atomic64_read(v)
60214 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60215 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60216 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60217 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60218 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60219 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60220 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60221 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60222 +
60223 #endif /* _ASM_GENERIC_ATOMIC64_H */
60224 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60225 index 1bfcfe5..e04c5c9 100644
60226 --- a/include/asm-generic/cache.h
60227 +++ b/include/asm-generic/cache.h
60228 @@ -6,7 +6,7 @@
60229 * cache lines need to provide their own cache.h.
60230 */
60231
60232 -#define L1_CACHE_SHIFT 5
60233 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60234 +#define L1_CACHE_SHIFT 5UL
60235 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60236
60237 #endif /* __ASM_GENERIC_CACHE_H */
60238 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60239 index 0d68a1e..b74a761 100644
60240 --- a/include/asm-generic/emergency-restart.h
60241 +++ b/include/asm-generic/emergency-restart.h
60242 @@ -1,7 +1,7 @@
60243 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60244 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60245
60246 -static inline void machine_emergency_restart(void)
60247 +static inline __noreturn void machine_emergency_restart(void)
60248 {
60249 machine_restart(NULL);
60250 }
60251 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60252 index 0232ccb..13d9165 100644
60253 --- a/include/asm-generic/kmap_types.h
60254 +++ b/include/asm-generic/kmap_types.h
60255 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60256 KMAP_D(17) KM_NMI,
60257 KMAP_D(18) KM_NMI_PTE,
60258 KMAP_D(19) KM_KDB,
60259 +KMAP_D(20) KM_CLEARPAGE,
60260 /*
60261 * Remember to update debug_kmap_atomic() when adding new kmap types!
60262 */
60263 -KMAP_D(20) KM_TYPE_NR
60264 +KMAP_D(21) KM_TYPE_NR
60265 };
60266
60267 #undef KMAP_D
60268 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60269 index 9ceb03b..2efbcbd 100644
60270 --- a/include/asm-generic/local.h
60271 +++ b/include/asm-generic/local.h
60272 @@ -39,6 +39,7 @@ typedef struct
60273 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60274 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60275 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60276 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60277
60278 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60279 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60280 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60281 index 725612b..9cc513a 100644
60282 --- a/include/asm-generic/pgtable-nopmd.h
60283 +++ b/include/asm-generic/pgtable-nopmd.h
60284 @@ -1,14 +1,19 @@
60285 #ifndef _PGTABLE_NOPMD_H
60286 #define _PGTABLE_NOPMD_H
60287
60288 -#ifndef __ASSEMBLY__
60289 -
60290 #include <asm-generic/pgtable-nopud.h>
60291
60292 -struct mm_struct;
60293 -
60294 #define __PAGETABLE_PMD_FOLDED
60295
60296 +#define PMD_SHIFT PUD_SHIFT
60297 +#define PTRS_PER_PMD 1
60298 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60299 +#define PMD_MASK (~(PMD_SIZE-1))
60300 +
60301 +#ifndef __ASSEMBLY__
60302 +
60303 +struct mm_struct;
60304 +
60305 /*
60306 * Having the pmd type consist of a pud gets the size right, and allows
60307 * us to conceptually access the pud entry that this pmd is folded into
60308 @@ -16,11 +21,6 @@ struct mm_struct;
60309 */
60310 typedef struct { pud_t pud; } pmd_t;
60311
60312 -#define PMD_SHIFT PUD_SHIFT
60313 -#define PTRS_PER_PMD 1
60314 -#define PMD_SIZE (1UL << PMD_SHIFT)
60315 -#define PMD_MASK (~(PMD_SIZE-1))
60316 -
60317 /*
60318 * The "pud_xxx()" functions here are trivial for a folded two-level
60319 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60320 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60321 index 810431d..ccc3638 100644
60322 --- a/include/asm-generic/pgtable-nopud.h
60323 +++ b/include/asm-generic/pgtable-nopud.h
60324 @@ -1,10 +1,15 @@
60325 #ifndef _PGTABLE_NOPUD_H
60326 #define _PGTABLE_NOPUD_H
60327
60328 -#ifndef __ASSEMBLY__
60329 -
60330 #define __PAGETABLE_PUD_FOLDED
60331
60332 +#define PUD_SHIFT PGDIR_SHIFT
60333 +#define PTRS_PER_PUD 1
60334 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60335 +#define PUD_MASK (~(PUD_SIZE-1))
60336 +
60337 +#ifndef __ASSEMBLY__
60338 +
60339 /*
60340 * Having the pud type consist of a pgd gets the size right, and allows
60341 * us to conceptually access the pgd entry that this pud is folded into
60342 @@ -12,11 +17,6 @@
60343 */
60344 typedef struct { pgd_t pgd; } pud_t;
60345
60346 -#define PUD_SHIFT PGDIR_SHIFT
60347 -#define PTRS_PER_PUD 1
60348 -#define PUD_SIZE (1UL << PUD_SHIFT)
60349 -#define PUD_MASK (~(PUD_SIZE-1))
60350 -
60351 /*
60352 * The "pgd_xxx()" functions here are trivial for a folded two-level
60353 * setup: the pud is never bad, and a pud always exists (as it's folded
60354 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60355 index a03c098..7e5b223 100644
60356 --- a/include/asm-generic/pgtable.h
60357 +++ b/include/asm-generic/pgtable.h
60358 @@ -502,6 +502,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60359 #endif
60360 }
60361
60362 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60363 +static inline unsigned long pax_open_kernel(void) { return 0; }
60364 +#endif
60365 +
60366 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60367 +static inline unsigned long pax_close_kernel(void) { return 0; }
60368 +#endif
60369 +
60370 #endif /* CONFIG_MMU */
60371
60372 #endif /* !__ASSEMBLY__ */
60373 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
60374 index 9788568..510dece 100644
60375 --- a/include/asm-generic/uaccess.h
60376 +++ b/include/asm-generic/uaccess.h
60377 @@ -76,6 +76,8 @@ extern unsigned long search_exception_table(unsigned long);
60378 */
60379 #ifndef __copy_from_user
60380 static inline __must_check long __copy_from_user(void *to,
60381 + const void __user * from, unsigned long n) __size_overflow(3);
60382 +static inline __must_check long __copy_from_user(void *to,
60383 const void __user * from, unsigned long n)
60384 {
60385 if (__builtin_constant_p(n)) {
60386 @@ -106,6 +108,8 @@ static inline __must_check long __copy_from_user(void *to,
60387
60388 #ifndef __copy_to_user
60389 static inline __must_check long __copy_to_user(void __user *to,
60390 + const void *from, unsigned long n) __size_overflow(3);
60391 +static inline __must_check long __copy_to_user(void __user *to,
60392 const void *from, unsigned long n)
60393 {
60394 if (__builtin_constant_p(n)) {
60395 @@ -224,6 +228,7 @@ extern int __put_user_bad(void) __attribute__((noreturn));
60396 -EFAULT; \
60397 })
60398
60399 +static inline int __get_user_fn(size_t size, const void __user *ptr, void *x) __size_overflow(1);
60400 static inline int __get_user_fn(size_t size, const void __user *ptr, void *x)
60401 {
60402 size = __copy_from_user(x, ptr, size);
60403 @@ -240,6 +245,7 @@ extern int __get_user_bad(void) __attribute__((noreturn));
60404 #define __copy_to_user_inatomic __copy_to_user
60405 #endif
60406
60407 +static inline long copy_from_user(void *to, const void __user * from, unsigned long n) __size_overflow(3);
60408 static inline long copy_from_user(void *to,
60409 const void __user * from, unsigned long n)
60410 {
60411 @@ -250,6 +256,7 @@ static inline long copy_from_user(void *to,
60412 return n;
60413 }
60414
60415 +static inline long copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
60416 static inline long copy_to_user(void __user *to,
60417 const void *from, unsigned long n)
60418 {
60419 @@ -314,6 +321,8 @@ static inline long strlen_user(const char __user *src)
60420 */
60421 #ifndef __clear_user
60422 static inline __must_check unsigned long
60423 +__clear_user(void __user *to, unsigned long n) __size_overflow(2);
60424 +static inline __must_check unsigned long
60425 __clear_user(void __user *to, unsigned long n)
60426 {
60427 memset((void __force *)to, 0, n);
60428 @@ -322,6 +331,8 @@ __clear_user(void __user *to, unsigned long n)
60429 #endif
60430
60431 static inline __must_check unsigned long
60432 +clear_user(void __user *to, unsigned long n) __size_overflow(2);
60433 +static inline __must_check unsigned long
60434 clear_user(void __user *to, unsigned long n)
60435 {
60436 might_sleep();
60437 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60438 index b5e2e4c..6a5373e 100644
60439 --- a/include/asm-generic/vmlinux.lds.h
60440 +++ b/include/asm-generic/vmlinux.lds.h
60441 @@ -217,6 +217,7 @@
60442 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60443 VMLINUX_SYMBOL(__start_rodata) = .; \
60444 *(.rodata) *(.rodata.*) \
60445 + *(.data..read_only) \
60446 *(__vermagic) /* Kernel version magic */ \
60447 . = ALIGN(8); \
60448 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60449 @@ -722,17 +723,18 @@
60450 * section in the linker script will go there too. @phdr should have
60451 * a leading colon.
60452 *
60453 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60454 + * Note that this macros defines per_cpu_load as an absolute symbol.
60455 * If there is no need to put the percpu section at a predetermined
60456 * address, use PERCPU_SECTION.
60457 */
60458 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60459 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60460 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60461 + per_cpu_load = .; \
60462 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60463 - LOAD_OFFSET) { \
60464 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60465 PERCPU_INPUT(cacheline) \
60466 } phdr \
60467 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60468 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60469
60470 /**
60471 * PERCPU_SECTION - define output section for percpu area, simple version
60472 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60473 index 92f0981..d44a37c 100644
60474 --- a/include/drm/drmP.h
60475 +++ b/include/drm/drmP.h
60476 @@ -72,6 +72,7 @@
60477 #include <linux/workqueue.h>
60478 #include <linux/poll.h>
60479 #include <asm/pgalloc.h>
60480 +#include <asm/local.h>
60481 #include "drm.h"
60482
60483 #include <linux/idr.h>
60484 @@ -1038,7 +1039,7 @@ struct drm_device {
60485
60486 /** \name Usage Counters */
60487 /*@{ */
60488 - int open_count; /**< Outstanding files open */
60489 + local_t open_count; /**< Outstanding files open */
60490 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60491 atomic_t vma_count; /**< Outstanding vma areas open */
60492 int buf_use; /**< Buffers in use -- cannot alloc */
60493 @@ -1049,7 +1050,7 @@ struct drm_device {
60494 /*@{ */
60495 unsigned long counters;
60496 enum drm_stat_type types[15];
60497 - atomic_t counts[15];
60498 + atomic_unchecked_t counts[15];
60499 /*@} */
60500
60501 struct list_head filelist;
60502 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60503 index 37515d1..34fa8b0 100644
60504 --- a/include/drm/drm_crtc_helper.h
60505 +++ b/include/drm/drm_crtc_helper.h
60506 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
60507
60508 /* disable crtc when not in use - more explicit than dpms off */
60509 void (*disable)(struct drm_crtc *crtc);
60510 -};
60511 +} __no_const;
60512
60513 struct drm_encoder_helper_funcs {
60514 void (*dpms)(struct drm_encoder *encoder, int mode);
60515 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
60516 struct drm_connector *connector);
60517 /* disable encoder when not in use - more explicit than dpms off */
60518 void (*disable)(struct drm_encoder *encoder);
60519 -};
60520 +} __no_const;
60521
60522 struct drm_connector_helper_funcs {
60523 int (*get_modes)(struct drm_connector *connector);
60524 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60525 index 26c1f78..6722682 100644
60526 --- a/include/drm/ttm/ttm_memory.h
60527 +++ b/include/drm/ttm/ttm_memory.h
60528 @@ -47,7 +47,7 @@
60529
60530 struct ttm_mem_shrink {
60531 int (*do_shrink) (struct ttm_mem_shrink *);
60532 -};
60533 +} __no_const;
60534
60535 /**
60536 * struct ttm_mem_global - Global memory accounting structure.
60537 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60538 index e86dfca..40cc55f 100644
60539 --- a/include/linux/a.out.h
60540 +++ b/include/linux/a.out.h
60541 @@ -39,6 +39,14 @@ enum machine_type {
60542 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60543 };
60544
60545 +/* Constants for the N_FLAGS field */
60546 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60547 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60548 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60549 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60550 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60551 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60552 +
60553 #if !defined (N_MAGIC)
60554 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60555 #endif
60556 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60557 index f4ff882..84b53a6 100644
60558 --- a/include/linux/atmdev.h
60559 +++ b/include/linux/atmdev.h
60560 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60561 #endif
60562
60563 struct k_atm_aal_stats {
60564 -#define __HANDLE_ITEM(i) atomic_t i
60565 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60566 __AAL_STAT_ITEMS
60567 #undef __HANDLE_ITEM
60568 };
60569 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60570 index 0092102..8a801b4 100644
60571 --- a/include/linux/binfmts.h
60572 +++ b/include/linux/binfmts.h
60573 @@ -89,6 +89,7 @@ struct linux_binfmt {
60574 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60575 int (*load_shlib)(struct file *);
60576 int (*core_dump)(struct coredump_params *cprm);
60577 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60578 unsigned long min_coredump; /* minimal dump size */
60579 };
60580
60581 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60582 index 606cf33..b72c577 100644
60583 --- a/include/linux/blkdev.h
60584 +++ b/include/linux/blkdev.h
60585 @@ -1379,7 +1379,7 @@ struct block_device_operations {
60586 /* this callback is with swap_lock and sometimes page table lock held */
60587 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60588 struct module *owner;
60589 -};
60590 +} __do_const;
60591
60592 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60593 unsigned long);
60594 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60595 index 4d1a074..88f929a 100644
60596 --- a/include/linux/blktrace_api.h
60597 +++ b/include/linux/blktrace_api.h
60598 @@ -162,7 +162,7 @@ struct blk_trace {
60599 struct dentry *dir;
60600 struct dentry *dropped_file;
60601 struct dentry *msg_file;
60602 - atomic_t dropped;
60603 + atomic_unchecked_t dropped;
60604 };
60605
60606 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60607 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60608 index 83195fb..0b0f77d 100644
60609 --- a/include/linux/byteorder/little_endian.h
60610 +++ b/include/linux/byteorder/little_endian.h
60611 @@ -42,51 +42,51 @@
60612
60613 static inline __le64 __cpu_to_le64p(const __u64 *p)
60614 {
60615 - return (__force __le64)*p;
60616 + return (__force const __le64)*p;
60617 }
60618 static inline __u64 __le64_to_cpup(const __le64 *p)
60619 {
60620 - return (__force __u64)*p;
60621 + return (__force const __u64)*p;
60622 }
60623 static inline __le32 __cpu_to_le32p(const __u32 *p)
60624 {
60625 - return (__force __le32)*p;
60626 + return (__force const __le32)*p;
60627 }
60628 static inline __u32 __le32_to_cpup(const __le32 *p)
60629 {
60630 - return (__force __u32)*p;
60631 + return (__force const __u32)*p;
60632 }
60633 static inline __le16 __cpu_to_le16p(const __u16 *p)
60634 {
60635 - return (__force __le16)*p;
60636 + return (__force const __le16)*p;
60637 }
60638 static inline __u16 __le16_to_cpup(const __le16 *p)
60639 {
60640 - return (__force __u16)*p;
60641 + return (__force const __u16)*p;
60642 }
60643 static inline __be64 __cpu_to_be64p(const __u64 *p)
60644 {
60645 - return (__force __be64)__swab64p(p);
60646 + return (__force const __be64)__swab64p(p);
60647 }
60648 static inline __u64 __be64_to_cpup(const __be64 *p)
60649 {
60650 - return __swab64p((__u64 *)p);
60651 + return __swab64p((const __u64 *)p);
60652 }
60653 static inline __be32 __cpu_to_be32p(const __u32 *p)
60654 {
60655 - return (__force __be32)__swab32p(p);
60656 + return (__force const __be32)__swab32p(p);
60657 }
60658 static inline __u32 __be32_to_cpup(const __be32 *p)
60659 {
60660 - return __swab32p((__u32 *)p);
60661 + return __swab32p((const __u32 *)p);
60662 }
60663 static inline __be16 __cpu_to_be16p(const __u16 *p)
60664 {
60665 - return (__force __be16)__swab16p(p);
60666 + return (__force const __be16)__swab16p(p);
60667 }
60668 static inline __u16 __be16_to_cpup(const __be16 *p)
60669 {
60670 - return __swab16p((__u16 *)p);
60671 + return __swab16p((const __u16 *)p);
60672 }
60673 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60674 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60675 diff --git a/include/linux/cache.h b/include/linux/cache.h
60676 index 4c57065..4307975 100644
60677 --- a/include/linux/cache.h
60678 +++ b/include/linux/cache.h
60679 @@ -16,6 +16,10 @@
60680 #define __read_mostly
60681 #endif
60682
60683 +#ifndef __read_only
60684 +#define __read_only __read_mostly
60685 +#endif
60686 +
60687 #ifndef ____cacheline_aligned
60688 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60689 #endif
60690 diff --git a/include/linux/capability.h b/include/linux/capability.h
60691 index 12d52de..b5f7fa7 100644
60692 --- a/include/linux/capability.h
60693 +++ b/include/linux/capability.h
60694 @@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
60695 extern bool capable(int cap);
60696 extern bool ns_capable(struct user_namespace *ns, int cap);
60697 extern bool nsown_capable(int cap);
60698 +extern bool capable_nolog(int cap);
60699 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60700
60701 /* audit system wants to get cap info from files as well */
60702 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60703 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60704 index 04ffb2e..6799180 100644
60705 --- a/include/linux/cleancache.h
60706 +++ b/include/linux/cleancache.h
60707 @@ -31,7 +31,7 @@ struct cleancache_ops {
60708 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
60709 void (*flush_inode)(int, struct cleancache_filekey);
60710 void (*flush_fs)(int);
60711 -};
60712 +} __no_const;
60713
60714 extern struct cleancache_ops
60715 cleancache_register_ops(struct cleancache_ops *ops);
60716 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60717 index 2f40791..567b215 100644
60718 --- a/include/linux/compiler-gcc4.h
60719 +++ b/include/linux/compiler-gcc4.h
60720 @@ -32,6 +32,15 @@
60721 #define __linktime_error(message) __attribute__((__error__(message)))
60722
60723 #if __GNUC_MINOR__ >= 5
60724 +
60725 +#ifdef CONSTIFY_PLUGIN
60726 +#define __no_const __attribute__((no_const))
60727 +#define __do_const __attribute__((do_const))
60728 +#endif
60729 +
60730 +#ifdef SIZE_OVERFLOW_PLUGIN
60731 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60732 +#endif
60733 /*
60734 * Mark a position in code as unreachable. This can be used to
60735 * suppress control flow warnings after asm blocks that transfer
60736 @@ -47,6 +56,11 @@
60737 #define __noclone __attribute__((__noclone__))
60738
60739 #endif
60740 +
60741 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60742 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60743 +#define __bos0(ptr) __bos((ptr), 0)
60744 +#define __bos1(ptr) __bos((ptr), 1)
60745 #endif
60746
60747 #if __GNUC_MINOR__ > 0
60748 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60749 index 4a24354..ecaff7a 100644
60750 --- a/include/linux/compiler.h
60751 +++ b/include/linux/compiler.h
60752 @@ -5,31 +5,62 @@
60753
60754 #ifdef __CHECKER__
60755 # define __user __attribute__((noderef, address_space(1)))
60756 +# define __force_user __force __user
60757 # define __kernel __attribute__((address_space(0)))
60758 +# define __force_kernel __force __kernel
60759 # define __safe __attribute__((safe))
60760 # define __force __attribute__((force))
60761 # define __nocast __attribute__((nocast))
60762 # define __iomem __attribute__((noderef, address_space(2)))
60763 +# define __force_iomem __force __iomem
60764 # define __acquires(x) __attribute__((context(x,0,1)))
60765 # define __releases(x) __attribute__((context(x,1,0)))
60766 # define __acquire(x) __context__(x,1)
60767 # define __release(x) __context__(x,-1)
60768 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60769 # define __percpu __attribute__((noderef, address_space(3)))
60770 +# define __force_percpu __force __percpu
60771 #ifdef CONFIG_SPARSE_RCU_POINTER
60772 # define __rcu __attribute__((noderef, address_space(4)))
60773 +# define __force_rcu __force __rcu
60774 #else
60775 # define __rcu
60776 +# define __force_rcu
60777 #endif
60778 extern void __chk_user_ptr(const volatile void __user *);
60779 extern void __chk_io_ptr(const volatile void __iomem *);
60780 +#elif defined(CHECKER_PLUGIN)
60781 +//# define __user
60782 +//# define __force_user
60783 +//# define __kernel
60784 +//# define __force_kernel
60785 +# define __safe
60786 +# define __force
60787 +# define __nocast
60788 +# define __iomem
60789 +# define __force_iomem
60790 +# define __chk_user_ptr(x) (void)0
60791 +# define __chk_io_ptr(x) (void)0
60792 +# define __builtin_warning(x, y...) (1)
60793 +# define __acquires(x)
60794 +# define __releases(x)
60795 +# define __acquire(x) (void)0
60796 +# define __release(x) (void)0
60797 +# define __cond_lock(x,c) (c)
60798 +# define __percpu
60799 +# define __force_percpu
60800 +# define __rcu
60801 +# define __force_rcu
60802 #else
60803 # define __user
60804 +# define __force_user
60805 # define __kernel
60806 +# define __force_kernel
60807 # define __safe
60808 # define __force
60809 # define __nocast
60810 # define __iomem
60811 +# define __force_iomem
60812 # define __chk_user_ptr(x) (void)0
60813 # define __chk_io_ptr(x) (void)0
60814 # define __builtin_warning(x, y...) (1)
60815 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60816 # define __release(x) (void)0
60817 # define __cond_lock(x,c) (c)
60818 # define __percpu
60819 +# define __force_percpu
60820 # define __rcu
60821 +# define __force_rcu
60822 #endif
60823
60824 #ifdef __KERNEL__
60825 @@ -264,6 +297,17 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60826 # define __attribute_const__ /* unimplemented */
60827 #endif
60828
60829 +#ifndef __no_const
60830 +# define __no_const
60831 +#endif
60832 +
60833 +#ifndef __do_const
60834 +# define __do_const
60835 +#endif
60836 +
60837 +#ifndef __size_overflow
60838 +# define __size_overflow(...)
60839 +#endif
60840 /*
60841 * Tell gcc if a function is cold. The compiler will assume any path
60842 * directly leading to the call is unlikely.
60843 @@ -273,6 +317,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60844 #define __cold
60845 #endif
60846
60847 +#ifndef __alloc_size
60848 +#define __alloc_size(...)
60849 +#endif
60850 +
60851 +#ifndef __bos
60852 +#define __bos(ptr, arg)
60853 +#endif
60854 +
60855 +#ifndef __bos0
60856 +#define __bos0(ptr)
60857 +#endif
60858 +
60859 +#ifndef __bos1
60860 +#define __bos1(ptr)
60861 +#endif
60862 +
60863 /* Simple shorthand for a section definition */
60864 #ifndef __section
60865 # define __section(S) __attribute__ ((__section__(#S)))
60866 @@ -308,6 +368,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60867 * use is to mediate communication between process-level code and irq/NMI
60868 * handlers, all running on the same CPU.
60869 */
60870 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60871 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60872 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60873
60874 #endif /* __LINUX_COMPILER_H */
60875 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
60876 index e9eaec5..bfeb9bb 100644
60877 --- a/include/linux/cpuset.h
60878 +++ b/include/linux/cpuset.h
60879 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
60880 * nodemask.
60881 */
60882 smp_mb();
60883 - --ACCESS_ONCE(current->mems_allowed_change_disable);
60884 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
60885 }
60886
60887 static inline void set_mems_allowed(nodemask_t nodemask)
60888 diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h
60889 index b936763..48685ee 100644
60890 --- a/include/linux/crash_dump.h
60891 +++ b/include/linux/crash_dump.h
60892 @@ -14,7 +14,7 @@ extern unsigned long long elfcorehdr_addr;
60893 extern unsigned long long elfcorehdr_size;
60894
60895 extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
60896 - unsigned long, int);
60897 + unsigned long, int) __size_overflow(3);
60898
60899 /* Architecture code defines this if there are other possible ELF
60900 * machine types, e.g. on bi-arch capable hardware. */
60901 diff --git a/include/linux/cred.h b/include/linux/cred.h
60902 index adadf71..6af5560 100644
60903 --- a/include/linux/cred.h
60904 +++ b/include/linux/cred.h
60905 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60906 static inline void validate_process_creds(void)
60907 {
60908 }
60909 +static inline void validate_task_creds(struct task_struct *task)
60910 +{
60911 +}
60912 #endif
60913
60914 /**
60915 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60916 index 8a94217..15d49e3 100644
60917 --- a/include/linux/crypto.h
60918 +++ b/include/linux/crypto.h
60919 @@ -365,7 +365,7 @@ struct cipher_tfm {
60920 const u8 *key, unsigned int keylen);
60921 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60922 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60923 -};
60924 +} __no_const;
60925
60926 struct hash_tfm {
60927 int (*init)(struct hash_desc *desc);
60928 @@ -386,13 +386,13 @@ struct compress_tfm {
60929 int (*cot_decompress)(struct crypto_tfm *tfm,
60930 const u8 *src, unsigned int slen,
60931 u8 *dst, unsigned int *dlen);
60932 -};
60933 +} __no_const;
60934
60935 struct rng_tfm {
60936 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60937 unsigned int dlen);
60938 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60939 -};
60940 +} __no_const;
60941
60942 #define crt_ablkcipher crt_u.ablkcipher
60943 #define crt_aead crt_u.aead
60944 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60945 index 7925bf0..d5143d2 100644
60946 --- a/include/linux/decompress/mm.h
60947 +++ b/include/linux/decompress/mm.h
60948 @@ -77,7 +77,7 @@ static void free(void *where)
60949 * warnings when not needed (indeed large_malloc / large_free are not
60950 * needed by inflate */
60951
60952 -#define malloc(a) kmalloc(a, GFP_KERNEL)
60953 +#define malloc(a) kmalloc((a), GFP_KERNEL)
60954 #define free(a) kfree(a)
60955
60956 #define large_malloc(a) vmalloc(a)
60957 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60958 index e13117c..e9fc938 100644
60959 --- a/include/linux/dma-mapping.h
60960 +++ b/include/linux/dma-mapping.h
60961 @@ -46,7 +46,7 @@ struct dma_map_ops {
60962 u64 (*get_required_mask)(struct device *dev);
60963 #endif
60964 int is_phys;
60965 -};
60966 +} __do_const;
60967
60968 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60969
60970 diff --git a/include/linux/efi.h b/include/linux/efi.h
60971 index 7cce0ea..c2085e4 100644
60972 --- a/include/linux/efi.h
60973 +++ b/include/linux/efi.h
60974 @@ -591,7 +591,7 @@ struct efivar_operations {
60975 efi_get_variable_t *get_variable;
60976 efi_get_next_variable_t *get_next_variable;
60977 efi_set_variable_t *set_variable;
60978 -};
60979 +} __no_const;
60980
60981 struct efivars {
60982 /*
60983 diff --git a/include/linux/elf.h b/include/linux/elf.h
60984 index 999b4f5..57753b4 100644
60985 --- a/include/linux/elf.h
60986 +++ b/include/linux/elf.h
60987 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60988 #define PT_GNU_EH_FRAME 0x6474e550
60989
60990 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60991 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60992 +
60993 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60994 +
60995 +/* Constants for the e_flags field */
60996 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60997 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60998 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60999 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61000 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61001 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61002
61003 /*
61004 * Extended Numbering
61005 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61006 #define DT_DEBUG 21
61007 #define DT_TEXTREL 22
61008 #define DT_JMPREL 23
61009 +#define DT_FLAGS 30
61010 + #define DF_TEXTREL 0x00000004
61011 #define DT_ENCODING 32
61012 #define OLD_DT_LOOS 0x60000000
61013 #define DT_LOOS 0x6000000d
61014 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61015 #define PF_W 0x2
61016 #define PF_X 0x1
61017
61018 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61019 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61020 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61021 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61022 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61023 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61024 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61025 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61026 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61027 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61028 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61029 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61030 +
61031 typedef struct elf32_phdr{
61032 Elf32_Word p_type;
61033 Elf32_Off p_offset;
61034 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61035 #define EI_OSABI 7
61036 #define EI_PAD 8
61037
61038 +#define EI_PAX 14
61039 +
61040 #define ELFMAG0 0x7f /* EI_MAG */
61041 #define ELFMAG1 'E'
61042 #define ELFMAG2 'L'
61043 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61044 #define elf_note elf32_note
61045 #define elf_addr_t Elf32_Off
61046 #define Elf_Half Elf32_Half
61047 +#define elf_dyn Elf32_Dyn
61048
61049 #else
61050
61051 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61052 #define elf_note elf64_note
61053 #define elf_addr_t Elf64_Off
61054 #define Elf_Half Elf64_Half
61055 +#define elf_dyn Elf64_Dyn
61056
61057 #endif
61058
61059 diff --git a/include/linux/filter.h b/include/linux/filter.h
61060 index 8eeb205..d59bfa2 100644
61061 --- a/include/linux/filter.h
61062 +++ b/include/linux/filter.h
61063 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
61064
61065 struct sk_buff;
61066 struct sock;
61067 +struct bpf_jit_work;
61068
61069 struct sk_filter
61070 {
61071 @@ -141,6 +142,9 @@ struct sk_filter
61072 unsigned int len; /* Number of filter blocks */
61073 unsigned int (*bpf_func)(const struct sk_buff *skb,
61074 const struct sock_filter *filter);
61075 +#ifdef CONFIG_BPF_JIT
61076 + struct bpf_jit_work *work;
61077 +#endif
61078 struct rcu_head rcu;
61079 struct sock_filter insns[0];
61080 };
61081 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61082 index 84ccf8e..2e9b14c 100644
61083 --- a/include/linux/firewire.h
61084 +++ b/include/linux/firewire.h
61085 @@ -428,7 +428,7 @@ struct fw_iso_context {
61086 union {
61087 fw_iso_callback_t sc;
61088 fw_iso_mc_callback_t mc;
61089 - } callback;
61090 + } __no_const callback;
61091 void *callback_data;
61092 };
61093
61094 diff --git a/include/linux/fs.h b/include/linux/fs.h
61095 index f4b6e06..d6ba573 100644
61096 --- a/include/linux/fs.h
61097 +++ b/include/linux/fs.h
61098 @@ -1628,7 +1628,8 @@ struct file_operations {
61099 int (*setlease)(struct file *, long, struct file_lock **);
61100 long (*fallocate)(struct file *file, int mode, loff_t offset,
61101 loff_t len);
61102 -};
61103 +} __do_const;
61104 +typedef struct file_operations __no_const file_operations_no_const;
61105
61106 struct inode_operations {
61107 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
61108 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61109 index 003dc0f..3c4ea97 100644
61110 --- a/include/linux/fs_struct.h
61111 +++ b/include/linux/fs_struct.h
61112 @@ -6,7 +6,7 @@
61113 #include <linux/seqlock.h>
61114
61115 struct fs_struct {
61116 - int users;
61117 + atomic_t users;
61118 spinlock_t lock;
61119 seqcount_t seq;
61120 int umask;
61121 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61122 index ce31408..b1ad003 100644
61123 --- a/include/linux/fscache-cache.h
61124 +++ b/include/linux/fscache-cache.h
61125 @@ -102,7 +102,7 @@ struct fscache_operation {
61126 fscache_operation_release_t release;
61127 };
61128
61129 -extern atomic_t fscache_op_debug_id;
61130 +extern atomic_unchecked_t fscache_op_debug_id;
61131 extern void fscache_op_work_func(struct work_struct *work);
61132
61133 extern void fscache_enqueue_operation(struct fscache_operation *);
61134 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61135 {
61136 INIT_WORK(&op->work, fscache_op_work_func);
61137 atomic_set(&op->usage, 1);
61138 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61139 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61140 op->processor = processor;
61141 op->release = release;
61142 INIT_LIST_HEAD(&op->pend_link);
61143 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61144 index 2a53f10..0187fdf 100644
61145 --- a/include/linux/fsnotify.h
61146 +++ b/include/linux/fsnotify.h
61147 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61148 */
61149 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61150 {
61151 - return kstrdup(name, GFP_KERNEL);
61152 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61153 }
61154
61155 /*
61156 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61157 index 91d0e0a3..035666b 100644
61158 --- a/include/linux/fsnotify_backend.h
61159 +++ b/include/linux/fsnotify_backend.h
61160 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61161 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61162 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61163 };
61164 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61165
61166 /*
61167 * A group is a "thing" that wants to receive notification about filesystem
61168 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61169 index c3da42d..c70e0df 100644
61170 --- a/include/linux/ftrace_event.h
61171 +++ b/include/linux/ftrace_event.h
61172 @@ -97,7 +97,7 @@ struct trace_event_functions {
61173 trace_print_func raw;
61174 trace_print_func hex;
61175 trace_print_func binary;
61176 -};
61177 +} __no_const;
61178
61179 struct trace_event {
61180 struct hlist_node node;
61181 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61182 extern int trace_add_event_call(struct ftrace_event_call *call);
61183 extern void trace_remove_event_call(struct ftrace_event_call *call);
61184
61185 -#define is_signed_type(type) (((type)(-1)) < 0)
61186 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61187
61188 int trace_set_clr_event(const char *system, const char *event, int set);
61189
61190 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61191 index e61d319..0da8505 100644
61192 --- a/include/linux/genhd.h
61193 +++ b/include/linux/genhd.h
61194 @@ -185,7 +185,7 @@ struct gendisk {
61195 struct kobject *slave_dir;
61196
61197 struct timer_rand_state *random;
61198 - atomic_t sync_io; /* RAID */
61199 + atomic_unchecked_t sync_io; /* RAID */
61200 struct disk_events *ev;
61201 #ifdef CONFIG_BLK_DEV_INTEGRITY
61202 struct blk_integrity *integrity;
61203 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61204 new file mode 100644
61205 index 0000000..8a130b6
61206 --- /dev/null
61207 +++ b/include/linux/gracl.h
61208 @@ -0,0 +1,319 @@
61209 +#ifndef GR_ACL_H
61210 +#define GR_ACL_H
61211 +
61212 +#include <linux/grdefs.h>
61213 +#include <linux/resource.h>
61214 +#include <linux/capability.h>
61215 +#include <linux/dcache.h>
61216 +#include <asm/resource.h>
61217 +
61218 +/* Major status information */
61219 +
61220 +#define GR_VERSION "grsecurity 2.9"
61221 +#define GRSECURITY_VERSION 0x2900
61222 +
61223 +enum {
61224 + GR_SHUTDOWN = 0,
61225 + GR_ENABLE = 1,
61226 + GR_SPROLE = 2,
61227 + GR_RELOAD = 3,
61228 + GR_SEGVMOD = 4,
61229 + GR_STATUS = 5,
61230 + GR_UNSPROLE = 6,
61231 + GR_PASSSET = 7,
61232 + GR_SPROLEPAM = 8,
61233 +};
61234 +
61235 +/* Password setup definitions
61236 + * kernel/grhash.c */
61237 +enum {
61238 + GR_PW_LEN = 128,
61239 + GR_SALT_LEN = 16,
61240 + GR_SHA_LEN = 32,
61241 +};
61242 +
61243 +enum {
61244 + GR_SPROLE_LEN = 64,
61245 +};
61246 +
61247 +enum {
61248 + GR_NO_GLOB = 0,
61249 + GR_REG_GLOB,
61250 + GR_CREATE_GLOB
61251 +};
61252 +
61253 +#define GR_NLIMITS 32
61254 +
61255 +/* Begin Data Structures */
61256 +
61257 +struct sprole_pw {
61258 + unsigned char *rolename;
61259 + unsigned char salt[GR_SALT_LEN];
61260 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61261 +};
61262 +
61263 +struct name_entry {
61264 + __u32 key;
61265 + ino_t inode;
61266 + dev_t device;
61267 + char *name;
61268 + __u16 len;
61269 + __u8 deleted;
61270 + struct name_entry *prev;
61271 + struct name_entry *next;
61272 +};
61273 +
61274 +struct inodev_entry {
61275 + struct name_entry *nentry;
61276 + struct inodev_entry *prev;
61277 + struct inodev_entry *next;
61278 +};
61279 +
61280 +struct acl_role_db {
61281 + struct acl_role_label **r_hash;
61282 + __u32 r_size;
61283 +};
61284 +
61285 +struct inodev_db {
61286 + struct inodev_entry **i_hash;
61287 + __u32 i_size;
61288 +};
61289 +
61290 +struct name_db {
61291 + struct name_entry **n_hash;
61292 + __u32 n_size;
61293 +};
61294 +
61295 +struct crash_uid {
61296 + uid_t uid;
61297 + unsigned long expires;
61298 +};
61299 +
61300 +struct gr_hash_struct {
61301 + void **table;
61302 + void **nametable;
61303 + void *first;
61304 + __u32 table_size;
61305 + __u32 used_size;
61306 + int type;
61307 +};
61308 +
61309 +/* Userspace Grsecurity ACL data structures */
61310 +
61311 +struct acl_subject_label {
61312 + char *filename;
61313 + ino_t inode;
61314 + dev_t device;
61315 + __u32 mode;
61316 + kernel_cap_t cap_mask;
61317 + kernel_cap_t cap_lower;
61318 + kernel_cap_t cap_invert_audit;
61319 +
61320 + struct rlimit res[GR_NLIMITS];
61321 + __u32 resmask;
61322 +
61323 + __u8 user_trans_type;
61324 + __u8 group_trans_type;
61325 + uid_t *user_transitions;
61326 + gid_t *group_transitions;
61327 + __u16 user_trans_num;
61328 + __u16 group_trans_num;
61329 +
61330 + __u32 sock_families[2];
61331 + __u32 ip_proto[8];
61332 + __u32 ip_type;
61333 + struct acl_ip_label **ips;
61334 + __u32 ip_num;
61335 + __u32 inaddr_any_override;
61336 +
61337 + __u32 crashes;
61338 + unsigned long expires;
61339 +
61340 + struct acl_subject_label *parent_subject;
61341 + struct gr_hash_struct *hash;
61342 + struct acl_subject_label *prev;
61343 + struct acl_subject_label *next;
61344 +
61345 + struct acl_object_label **obj_hash;
61346 + __u32 obj_hash_size;
61347 + __u16 pax_flags;
61348 +};
61349 +
61350 +struct role_allowed_ip {
61351 + __u32 addr;
61352 + __u32 netmask;
61353 +
61354 + struct role_allowed_ip *prev;
61355 + struct role_allowed_ip *next;
61356 +};
61357 +
61358 +struct role_transition {
61359 + char *rolename;
61360 +
61361 + struct role_transition *prev;
61362 + struct role_transition *next;
61363 +};
61364 +
61365 +struct acl_role_label {
61366 + char *rolename;
61367 + uid_t uidgid;
61368 + __u16 roletype;
61369 +
61370 + __u16 auth_attempts;
61371 + unsigned long expires;
61372 +
61373 + struct acl_subject_label *root_label;
61374 + struct gr_hash_struct *hash;
61375 +
61376 + struct acl_role_label *prev;
61377 + struct acl_role_label *next;
61378 +
61379 + struct role_transition *transitions;
61380 + struct role_allowed_ip *allowed_ips;
61381 + uid_t *domain_children;
61382 + __u16 domain_child_num;
61383 +
61384 + umode_t umask;
61385 +
61386 + struct acl_subject_label **subj_hash;
61387 + __u32 subj_hash_size;
61388 +};
61389 +
61390 +struct user_acl_role_db {
61391 + struct acl_role_label **r_table;
61392 + __u32 num_pointers; /* Number of allocations to track */
61393 + __u32 num_roles; /* Number of roles */
61394 + __u32 num_domain_children; /* Number of domain children */
61395 + __u32 num_subjects; /* Number of subjects */
61396 + __u32 num_objects; /* Number of objects */
61397 +};
61398 +
61399 +struct acl_object_label {
61400 + char *filename;
61401 + ino_t inode;
61402 + dev_t device;
61403 + __u32 mode;
61404 +
61405 + struct acl_subject_label *nested;
61406 + struct acl_object_label *globbed;
61407 +
61408 + /* next two structures not used */
61409 +
61410 + struct acl_object_label *prev;
61411 + struct acl_object_label *next;
61412 +};
61413 +
61414 +struct acl_ip_label {
61415 + char *iface;
61416 + __u32 addr;
61417 + __u32 netmask;
61418 + __u16 low, high;
61419 + __u8 mode;
61420 + __u32 type;
61421 + __u32 proto[8];
61422 +
61423 + /* next two structures not used */
61424 +
61425 + struct acl_ip_label *prev;
61426 + struct acl_ip_label *next;
61427 +};
61428 +
61429 +struct gr_arg {
61430 + struct user_acl_role_db role_db;
61431 + unsigned char pw[GR_PW_LEN];
61432 + unsigned char salt[GR_SALT_LEN];
61433 + unsigned char sum[GR_SHA_LEN];
61434 + unsigned char sp_role[GR_SPROLE_LEN];
61435 + struct sprole_pw *sprole_pws;
61436 + dev_t segv_device;
61437 + ino_t segv_inode;
61438 + uid_t segv_uid;
61439 + __u16 num_sprole_pws;
61440 + __u16 mode;
61441 +};
61442 +
61443 +struct gr_arg_wrapper {
61444 + struct gr_arg *arg;
61445 + __u32 version;
61446 + __u32 size;
61447 +};
61448 +
61449 +struct subject_map {
61450 + struct acl_subject_label *user;
61451 + struct acl_subject_label *kernel;
61452 + struct subject_map *prev;
61453 + struct subject_map *next;
61454 +};
61455 +
61456 +struct acl_subj_map_db {
61457 + struct subject_map **s_hash;
61458 + __u32 s_size;
61459 +};
61460 +
61461 +/* End Data Structures Section */
61462 +
61463 +/* Hash functions generated by empirical testing by Brad Spengler
61464 + Makes good use of the low bits of the inode. Generally 0-1 times
61465 + in loop for successful match. 0-3 for unsuccessful match.
61466 + Shift/add algorithm with modulus of table size and an XOR*/
61467 +
61468 +static __inline__ unsigned int
61469 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61470 +{
61471 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61472 +}
61473 +
61474 + static __inline__ unsigned int
61475 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61476 +{
61477 + return ((const unsigned long)userp % sz);
61478 +}
61479 +
61480 +static __inline__ unsigned int
61481 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61482 +{
61483 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61484 +}
61485 +
61486 +static __inline__ unsigned int
61487 +nhash(const char *name, const __u16 len, const unsigned int sz)
61488 +{
61489 + return full_name_hash((const unsigned char *)name, len) % sz;
61490 +}
61491 +
61492 +#define FOR_EACH_ROLE_START(role) \
61493 + role = role_list; \
61494 + while (role) {
61495 +
61496 +#define FOR_EACH_ROLE_END(role) \
61497 + role = role->prev; \
61498 + }
61499 +
61500 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61501 + subj = NULL; \
61502 + iter = 0; \
61503 + while (iter < role->subj_hash_size) { \
61504 + if (subj == NULL) \
61505 + subj = role->subj_hash[iter]; \
61506 + if (subj == NULL) { \
61507 + iter++; \
61508 + continue; \
61509 + }
61510 +
61511 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61512 + subj = subj->next; \
61513 + if (subj == NULL) \
61514 + iter++; \
61515 + }
61516 +
61517 +
61518 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61519 + subj = role->hash->first; \
61520 + while (subj != NULL) {
61521 +
61522 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61523 + subj = subj->next; \
61524 + }
61525 +
61526 +#endif
61527 +
61528 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61529 new file mode 100644
61530 index 0000000..323ecf2
61531 --- /dev/null
61532 +++ b/include/linux/gralloc.h
61533 @@ -0,0 +1,9 @@
61534 +#ifndef __GRALLOC_H
61535 +#define __GRALLOC_H
61536 +
61537 +void acl_free_all(void);
61538 +int acl_alloc_stack_init(unsigned long size);
61539 +void *acl_alloc(unsigned long len);
61540 +void *acl_alloc_num(unsigned long num, unsigned long len);
61541 +
61542 +#endif
61543 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61544 new file mode 100644
61545 index 0000000..b30e9bc
61546 --- /dev/null
61547 +++ b/include/linux/grdefs.h
61548 @@ -0,0 +1,140 @@
61549 +#ifndef GRDEFS_H
61550 +#define GRDEFS_H
61551 +
61552 +/* Begin grsecurity status declarations */
61553 +
61554 +enum {
61555 + GR_READY = 0x01,
61556 + GR_STATUS_INIT = 0x00 // disabled state
61557 +};
61558 +
61559 +/* Begin ACL declarations */
61560 +
61561 +/* Role flags */
61562 +
61563 +enum {
61564 + GR_ROLE_USER = 0x0001,
61565 + GR_ROLE_GROUP = 0x0002,
61566 + GR_ROLE_DEFAULT = 0x0004,
61567 + GR_ROLE_SPECIAL = 0x0008,
61568 + GR_ROLE_AUTH = 0x0010,
61569 + GR_ROLE_NOPW = 0x0020,
61570 + GR_ROLE_GOD = 0x0040,
61571 + GR_ROLE_LEARN = 0x0080,
61572 + GR_ROLE_TPE = 0x0100,
61573 + GR_ROLE_DOMAIN = 0x0200,
61574 + GR_ROLE_PAM = 0x0400,
61575 + GR_ROLE_PERSIST = 0x0800
61576 +};
61577 +
61578 +/* ACL Subject and Object mode flags */
61579 +enum {
61580 + GR_DELETED = 0x80000000
61581 +};
61582 +
61583 +/* ACL Object-only mode flags */
61584 +enum {
61585 + GR_READ = 0x00000001,
61586 + GR_APPEND = 0x00000002,
61587 + GR_WRITE = 0x00000004,
61588 + GR_EXEC = 0x00000008,
61589 + GR_FIND = 0x00000010,
61590 + GR_INHERIT = 0x00000020,
61591 + GR_SETID = 0x00000040,
61592 + GR_CREATE = 0x00000080,
61593 + GR_DELETE = 0x00000100,
61594 + GR_LINK = 0x00000200,
61595 + GR_AUDIT_READ = 0x00000400,
61596 + GR_AUDIT_APPEND = 0x00000800,
61597 + GR_AUDIT_WRITE = 0x00001000,
61598 + GR_AUDIT_EXEC = 0x00002000,
61599 + GR_AUDIT_FIND = 0x00004000,
61600 + GR_AUDIT_INHERIT= 0x00008000,
61601 + GR_AUDIT_SETID = 0x00010000,
61602 + GR_AUDIT_CREATE = 0x00020000,
61603 + GR_AUDIT_DELETE = 0x00040000,
61604 + GR_AUDIT_LINK = 0x00080000,
61605 + GR_PTRACERD = 0x00100000,
61606 + GR_NOPTRACE = 0x00200000,
61607 + GR_SUPPRESS = 0x00400000,
61608 + GR_NOLEARN = 0x00800000,
61609 + GR_INIT_TRANSFER= 0x01000000
61610 +};
61611 +
61612 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61613 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61614 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61615 +
61616 +/* ACL subject-only mode flags */
61617 +enum {
61618 + GR_KILL = 0x00000001,
61619 + GR_VIEW = 0x00000002,
61620 + GR_PROTECTED = 0x00000004,
61621 + GR_LEARN = 0x00000008,
61622 + GR_OVERRIDE = 0x00000010,
61623 + /* just a placeholder, this mode is only used in userspace */
61624 + GR_DUMMY = 0x00000020,
61625 + GR_PROTSHM = 0x00000040,
61626 + GR_KILLPROC = 0x00000080,
61627 + GR_KILLIPPROC = 0x00000100,
61628 + /* just a placeholder, this mode is only used in userspace */
61629 + GR_NOTROJAN = 0x00000200,
61630 + GR_PROTPROCFD = 0x00000400,
61631 + GR_PROCACCT = 0x00000800,
61632 + GR_RELAXPTRACE = 0x00001000,
61633 + GR_NESTED = 0x00002000,
61634 + GR_INHERITLEARN = 0x00004000,
61635 + GR_PROCFIND = 0x00008000,
61636 + GR_POVERRIDE = 0x00010000,
61637 + GR_KERNELAUTH = 0x00020000,
61638 + GR_ATSECURE = 0x00040000,
61639 + GR_SHMEXEC = 0x00080000
61640 +};
61641 +
61642 +enum {
61643 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61644 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61645 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61646 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61647 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61648 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61649 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61650 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61651 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61652 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61653 +};
61654 +
61655 +enum {
61656 + GR_ID_USER = 0x01,
61657 + GR_ID_GROUP = 0x02,
61658 +};
61659 +
61660 +enum {
61661 + GR_ID_ALLOW = 0x01,
61662 + GR_ID_DENY = 0x02,
61663 +};
61664 +
61665 +#define GR_CRASH_RES 31
61666 +#define GR_UIDTABLE_MAX 500
61667 +
61668 +/* begin resource learning section */
61669 +enum {
61670 + GR_RLIM_CPU_BUMP = 60,
61671 + GR_RLIM_FSIZE_BUMP = 50000,
61672 + GR_RLIM_DATA_BUMP = 10000,
61673 + GR_RLIM_STACK_BUMP = 1000,
61674 + GR_RLIM_CORE_BUMP = 10000,
61675 + GR_RLIM_RSS_BUMP = 500000,
61676 + GR_RLIM_NPROC_BUMP = 1,
61677 + GR_RLIM_NOFILE_BUMP = 5,
61678 + GR_RLIM_MEMLOCK_BUMP = 50000,
61679 + GR_RLIM_AS_BUMP = 500000,
61680 + GR_RLIM_LOCKS_BUMP = 2,
61681 + GR_RLIM_SIGPENDING_BUMP = 5,
61682 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61683 + GR_RLIM_NICE_BUMP = 1,
61684 + GR_RLIM_RTPRIO_BUMP = 1,
61685 + GR_RLIM_RTTIME_BUMP = 1000000
61686 +};
61687 +
61688 +#endif
61689 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61690 new file mode 100644
61691 index 0000000..da390f1
61692 --- /dev/null
61693 +++ b/include/linux/grinternal.h
61694 @@ -0,0 +1,221 @@
61695 +#ifndef __GRINTERNAL_H
61696 +#define __GRINTERNAL_H
61697 +
61698 +#ifdef CONFIG_GRKERNSEC
61699 +
61700 +#include <linux/fs.h>
61701 +#include <linux/mnt_namespace.h>
61702 +#include <linux/nsproxy.h>
61703 +#include <linux/gracl.h>
61704 +#include <linux/grdefs.h>
61705 +#include <linux/grmsg.h>
61706 +
61707 +void gr_add_learn_entry(const char *fmt, ...)
61708 + __attribute__ ((format (printf, 1, 2)));
61709 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61710 + const struct vfsmount *mnt);
61711 +__u32 gr_check_create(const struct dentry *new_dentry,
61712 + const struct dentry *parent,
61713 + const struct vfsmount *mnt, const __u32 mode);
61714 +int gr_check_protected_task(const struct task_struct *task);
61715 +__u32 to_gr_audit(const __u32 reqmode);
61716 +int gr_set_acls(const int type);
61717 +int gr_apply_subject_to_task(struct task_struct *task);
61718 +int gr_acl_is_enabled(void);
61719 +char gr_roletype_to_char(void);
61720 +
61721 +void gr_handle_alertkill(struct task_struct *task);
61722 +char *gr_to_filename(const struct dentry *dentry,
61723 + const struct vfsmount *mnt);
61724 +char *gr_to_filename1(const struct dentry *dentry,
61725 + const struct vfsmount *mnt);
61726 +char *gr_to_filename2(const struct dentry *dentry,
61727 + const struct vfsmount *mnt);
61728 +char *gr_to_filename3(const struct dentry *dentry,
61729 + const struct vfsmount *mnt);
61730 +
61731 +extern int grsec_enable_ptrace_readexec;
61732 +extern int grsec_enable_harden_ptrace;
61733 +extern int grsec_enable_link;
61734 +extern int grsec_enable_fifo;
61735 +extern int grsec_enable_execve;
61736 +extern int grsec_enable_shm;
61737 +extern int grsec_enable_execlog;
61738 +extern int grsec_enable_signal;
61739 +extern int grsec_enable_audit_ptrace;
61740 +extern int grsec_enable_forkfail;
61741 +extern int grsec_enable_time;
61742 +extern int grsec_enable_rofs;
61743 +extern int grsec_enable_chroot_shmat;
61744 +extern int grsec_enable_chroot_mount;
61745 +extern int grsec_enable_chroot_double;
61746 +extern int grsec_enable_chroot_pivot;
61747 +extern int grsec_enable_chroot_chdir;
61748 +extern int grsec_enable_chroot_chmod;
61749 +extern int grsec_enable_chroot_mknod;
61750 +extern int grsec_enable_chroot_fchdir;
61751 +extern int grsec_enable_chroot_nice;
61752 +extern int grsec_enable_chroot_execlog;
61753 +extern int grsec_enable_chroot_caps;
61754 +extern int grsec_enable_chroot_sysctl;
61755 +extern int grsec_enable_chroot_unix;
61756 +extern int grsec_enable_tpe;
61757 +extern int grsec_tpe_gid;
61758 +extern int grsec_enable_tpe_all;
61759 +extern int grsec_enable_tpe_invert;
61760 +extern int grsec_enable_socket_all;
61761 +extern int grsec_socket_all_gid;
61762 +extern int grsec_enable_socket_client;
61763 +extern int grsec_socket_client_gid;
61764 +extern int grsec_enable_socket_server;
61765 +extern int grsec_socket_server_gid;
61766 +extern int grsec_audit_gid;
61767 +extern int grsec_enable_group;
61768 +extern int grsec_enable_audit_textrel;
61769 +extern int grsec_enable_log_rwxmaps;
61770 +extern int grsec_enable_mount;
61771 +extern int grsec_enable_chdir;
61772 +extern int grsec_resource_logging;
61773 +extern int grsec_enable_blackhole;
61774 +extern int grsec_lastack_retries;
61775 +extern int grsec_enable_brute;
61776 +extern int grsec_lock;
61777 +
61778 +extern spinlock_t grsec_alert_lock;
61779 +extern unsigned long grsec_alert_wtime;
61780 +extern unsigned long grsec_alert_fyet;
61781 +
61782 +extern spinlock_t grsec_audit_lock;
61783 +
61784 +extern rwlock_t grsec_exec_file_lock;
61785 +
61786 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61787 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61788 + (tsk)->exec_file->f_vfsmnt) : "/")
61789 +
61790 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61791 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61792 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61793 +
61794 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61795 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61796 + (tsk)->exec_file->f_vfsmnt) : "/")
61797 +
61798 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61799 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61800 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61801 +
61802 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61803 +
61804 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61805 +
61806 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61807 + (task)->pid, (cred)->uid, \
61808 + (cred)->euid, (cred)->gid, (cred)->egid, \
61809 + gr_parent_task_fullpath(task), \
61810 + (task)->real_parent->comm, (task)->real_parent->pid, \
61811 + (pcred)->uid, (pcred)->euid, \
61812 + (pcred)->gid, (pcred)->egid
61813 +
61814 +#define GR_CHROOT_CAPS {{ \
61815 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61816 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61817 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61818 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61819 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61820 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61821 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61822 +
61823 +#define security_learn(normal_msg,args...) \
61824 +({ \
61825 + read_lock(&grsec_exec_file_lock); \
61826 + gr_add_learn_entry(normal_msg "\n", ## args); \
61827 + read_unlock(&grsec_exec_file_lock); \
61828 +})
61829 +
61830 +enum {
61831 + GR_DO_AUDIT,
61832 + GR_DONT_AUDIT,
61833 + /* used for non-audit messages that we shouldn't kill the task on */
61834 + GR_DONT_AUDIT_GOOD
61835 +};
61836 +
61837 +enum {
61838 + GR_TTYSNIFF,
61839 + GR_RBAC,
61840 + GR_RBAC_STR,
61841 + GR_STR_RBAC,
61842 + GR_RBAC_MODE2,
61843 + GR_RBAC_MODE3,
61844 + GR_FILENAME,
61845 + GR_SYSCTL_HIDDEN,
61846 + GR_NOARGS,
61847 + GR_ONE_INT,
61848 + GR_ONE_INT_TWO_STR,
61849 + GR_ONE_STR,
61850 + GR_STR_INT,
61851 + GR_TWO_STR_INT,
61852 + GR_TWO_INT,
61853 + GR_TWO_U64,
61854 + GR_THREE_INT,
61855 + GR_FIVE_INT_TWO_STR,
61856 + GR_TWO_STR,
61857 + GR_THREE_STR,
61858 + GR_FOUR_STR,
61859 + GR_STR_FILENAME,
61860 + GR_FILENAME_STR,
61861 + GR_FILENAME_TWO_INT,
61862 + GR_FILENAME_TWO_INT_STR,
61863 + GR_TEXTREL,
61864 + GR_PTRACE,
61865 + GR_RESOURCE,
61866 + GR_CAP,
61867 + GR_SIG,
61868 + GR_SIG2,
61869 + GR_CRASH1,
61870 + GR_CRASH2,
61871 + GR_PSACCT,
61872 + GR_RWXMAP
61873 +};
61874 +
61875 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61876 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61877 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61878 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61879 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61880 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61881 +#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)
61882 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61883 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61884 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61885 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61886 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61887 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61888 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61889 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61890 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61891 +#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)
61892 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61893 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61894 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61895 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61896 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61897 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61898 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61899 +#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)
61900 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61901 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61902 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61903 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61904 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61905 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61906 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61907 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61908 +#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)
61909 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61910 +
61911 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61912 +
61913 +#endif
61914 +
61915 +#endif
61916 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61917 new file mode 100644
61918 index 0000000..ae576a1
61919 --- /dev/null
61920 +++ b/include/linux/grmsg.h
61921 @@ -0,0 +1,109 @@
61922 +#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"
61923 +#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"
61924 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61925 +#define GR_STOPMOD_MSG "denied modification of module state by "
61926 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61927 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61928 +#define GR_IOPERM_MSG "denied use of ioperm() by "
61929 +#define GR_IOPL_MSG "denied use of iopl() by "
61930 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61931 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61932 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61933 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61934 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61935 +#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"
61936 +#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"
61937 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61938 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61939 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61940 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61941 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61942 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61943 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61944 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61945 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61946 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61947 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61948 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61949 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61950 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61951 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61952 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61953 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61954 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61955 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61956 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61957 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61958 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61959 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61960 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61961 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61962 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61963 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61964 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61965 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61966 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61967 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61968 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61969 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61970 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61971 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61972 +#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"
61973 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61974 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61975 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61976 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61977 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61978 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61979 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61980 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61981 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61982 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61983 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61984 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61985 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61986 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61987 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61988 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61989 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61990 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61991 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61992 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61993 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
61994 +#define GR_NICE_CHROOT_MSG "denied priority change by "
61995 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61996 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61997 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61998 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61999 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62000 +#define GR_TIME_MSG "time set by "
62001 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62002 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62003 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62004 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62005 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62006 +#define GR_BIND_MSG "denied bind() by "
62007 +#define GR_CONNECT_MSG "denied connect() by "
62008 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62009 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62010 +#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"
62011 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62012 +#define GR_CAP_ACL_MSG "use of %s denied for "
62013 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62014 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62015 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62016 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62017 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62018 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62019 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62020 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62021 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62022 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62023 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62024 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62025 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62026 +#define GR_VM86_MSG "denied use of vm86 by "
62027 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62028 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62029 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62030 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62031 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62032 new file mode 100644
62033 index 0000000..acd05db
62034 --- /dev/null
62035 +++ b/include/linux/grsecurity.h
62036 @@ -0,0 +1,232 @@
62037 +#ifndef GR_SECURITY_H
62038 +#define GR_SECURITY_H
62039 +#include <linux/fs.h>
62040 +#include <linux/fs_struct.h>
62041 +#include <linux/binfmts.h>
62042 +#include <linux/gracl.h>
62043 +
62044 +/* notify of brain-dead configs */
62045 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62046 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62047 +#endif
62048 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62049 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62050 +#endif
62051 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62052 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62053 +#endif
62054 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62055 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62056 +#endif
62057 +
62058 +#include <linux/compat.h>
62059 +
62060 +struct user_arg_ptr {
62061 +#ifdef CONFIG_COMPAT
62062 + bool is_compat;
62063 +#endif
62064 + union {
62065 + const char __user *const __user *native;
62066 +#ifdef CONFIG_COMPAT
62067 + compat_uptr_t __user *compat;
62068 +#endif
62069 + } ptr;
62070 +};
62071 +
62072 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62073 +void gr_handle_brute_check(void);
62074 +void gr_handle_kernel_exploit(void);
62075 +int gr_process_user_ban(void);
62076 +
62077 +char gr_roletype_to_char(void);
62078 +
62079 +int gr_acl_enable_at_secure(void);
62080 +
62081 +int gr_check_user_change(int real, int effective, int fs);
62082 +int gr_check_group_change(int real, int effective, int fs);
62083 +
62084 +void gr_del_task_from_ip_table(struct task_struct *p);
62085 +
62086 +int gr_pid_is_chrooted(struct task_struct *p);
62087 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62088 +int gr_handle_chroot_nice(void);
62089 +int gr_handle_chroot_sysctl(const int op);
62090 +int gr_handle_chroot_setpriority(struct task_struct *p,
62091 + const int niceval);
62092 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62093 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62094 + const struct vfsmount *mnt);
62095 +void gr_handle_chroot_chdir(struct path *path);
62096 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62097 + const struct vfsmount *mnt, const int mode);
62098 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62099 + const struct vfsmount *mnt, const int mode);
62100 +int gr_handle_chroot_mount(const struct dentry *dentry,
62101 + const struct vfsmount *mnt,
62102 + const char *dev_name);
62103 +int gr_handle_chroot_pivot(void);
62104 +int gr_handle_chroot_unix(const pid_t pid);
62105 +
62106 +int gr_handle_rawio(const struct inode *inode);
62107 +
62108 +void gr_handle_ioperm(void);
62109 +void gr_handle_iopl(void);
62110 +
62111 +umode_t gr_acl_umask(void);
62112 +
62113 +int gr_tpe_allow(const struct file *file);
62114 +
62115 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62116 +void gr_clear_chroot_entries(struct task_struct *task);
62117 +
62118 +void gr_log_forkfail(const int retval);
62119 +void gr_log_timechange(void);
62120 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62121 +void gr_log_chdir(const struct dentry *dentry,
62122 + const struct vfsmount *mnt);
62123 +void gr_log_chroot_exec(const struct dentry *dentry,
62124 + const struct vfsmount *mnt);
62125 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62126 +void gr_log_remount(const char *devname, const int retval);
62127 +void gr_log_unmount(const char *devname, const int retval);
62128 +void gr_log_mount(const char *from, const char *to, const int retval);
62129 +void gr_log_textrel(struct vm_area_struct *vma);
62130 +void gr_log_rwxmmap(struct file *file);
62131 +void gr_log_rwxmprotect(struct file *file);
62132 +
62133 +int gr_handle_follow_link(const struct inode *parent,
62134 + const struct inode *inode,
62135 + const struct dentry *dentry,
62136 + const struct vfsmount *mnt);
62137 +int gr_handle_fifo(const struct dentry *dentry,
62138 + const struct vfsmount *mnt,
62139 + const struct dentry *dir, const int flag,
62140 + const int acc_mode);
62141 +int gr_handle_hardlink(const struct dentry *dentry,
62142 + const struct vfsmount *mnt,
62143 + struct inode *inode,
62144 + const int mode, const char *to);
62145 +
62146 +int gr_is_capable(const int cap);
62147 +int gr_is_capable_nolog(const int cap);
62148 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62149 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62150 +
62151 +void gr_learn_resource(const struct task_struct *task, const int limit,
62152 + const unsigned long wanted, const int gt);
62153 +void gr_copy_label(struct task_struct *tsk);
62154 +void gr_handle_crash(struct task_struct *task, const int sig);
62155 +int gr_handle_signal(const struct task_struct *p, const int sig);
62156 +int gr_check_crash_uid(const uid_t uid);
62157 +int gr_check_protected_task(const struct task_struct *task);
62158 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62159 +int gr_acl_handle_mmap(const struct file *file,
62160 + const unsigned long prot);
62161 +int gr_acl_handle_mprotect(const struct file *file,
62162 + const unsigned long prot);
62163 +int gr_check_hidden_task(const struct task_struct *tsk);
62164 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62165 + const struct vfsmount *mnt);
62166 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62167 + const struct vfsmount *mnt);
62168 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62169 + const struct vfsmount *mnt, const int fmode);
62170 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62171 + const struct vfsmount *mnt, umode_t *mode);
62172 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62173 + const struct vfsmount *mnt);
62174 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62175 + const struct vfsmount *mnt);
62176 +int gr_handle_ptrace(struct task_struct *task, const long request);
62177 +int gr_handle_proc_ptrace(struct task_struct *task);
62178 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62179 + const struct vfsmount *mnt);
62180 +int gr_check_crash_exec(const struct file *filp);
62181 +int gr_acl_is_enabled(void);
62182 +void gr_set_kernel_label(struct task_struct *task);
62183 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62184 + const gid_t gid);
62185 +int gr_set_proc_label(const struct dentry *dentry,
62186 + const struct vfsmount *mnt,
62187 + const int unsafe_flags);
62188 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62189 + const struct vfsmount *mnt);
62190 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62191 + const struct vfsmount *mnt, int acc_mode);
62192 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62193 + const struct dentry *p_dentry,
62194 + const struct vfsmount *p_mnt,
62195 + int open_flags, int acc_mode, const int imode);
62196 +void gr_handle_create(const struct dentry *dentry,
62197 + const struct vfsmount *mnt);
62198 +void gr_handle_proc_create(const struct dentry *dentry,
62199 + const struct inode *inode);
62200 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62201 + const struct dentry *parent_dentry,
62202 + const struct vfsmount *parent_mnt,
62203 + const int mode);
62204 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62205 + const struct dentry *parent_dentry,
62206 + const struct vfsmount *parent_mnt);
62207 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62208 + const struct vfsmount *mnt);
62209 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62210 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62211 + const struct vfsmount *mnt);
62212 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62213 + const struct dentry *parent_dentry,
62214 + const struct vfsmount *parent_mnt,
62215 + const char *from);
62216 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62217 + const struct dentry *parent_dentry,
62218 + const struct vfsmount *parent_mnt,
62219 + const struct dentry *old_dentry,
62220 + const struct vfsmount *old_mnt, const char *to);
62221 +int gr_acl_handle_rename(struct dentry *new_dentry,
62222 + struct dentry *parent_dentry,
62223 + const struct vfsmount *parent_mnt,
62224 + struct dentry *old_dentry,
62225 + struct inode *old_parent_inode,
62226 + struct vfsmount *old_mnt, const char *newname);
62227 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62228 + struct dentry *old_dentry,
62229 + struct dentry *new_dentry,
62230 + struct vfsmount *mnt, const __u8 replace);
62231 +__u32 gr_check_link(const struct dentry *new_dentry,
62232 + const struct dentry *parent_dentry,
62233 + const struct vfsmount *parent_mnt,
62234 + const struct dentry *old_dentry,
62235 + const struct vfsmount *old_mnt);
62236 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62237 + const unsigned int namelen, const ino_t ino);
62238 +
62239 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62240 + const struct vfsmount *mnt);
62241 +void gr_acl_handle_exit(void);
62242 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62243 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62244 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62245 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62246 +void gr_audit_ptrace(struct task_struct *task);
62247 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62248 +
62249 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62250 +
62251 +#ifdef CONFIG_GRKERNSEC
62252 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62253 +void gr_handle_vm86(void);
62254 +void gr_handle_mem_readwrite(u64 from, u64 to);
62255 +
62256 +void gr_log_badprocpid(const char *entry);
62257 +
62258 +extern int grsec_enable_dmesg;
62259 +extern int grsec_disable_privio;
62260 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62261 +extern int grsec_enable_chroot_findtask;
62262 +#endif
62263 +#ifdef CONFIG_GRKERNSEC_SETXID
62264 +extern int grsec_enable_setxid;
62265 +#endif
62266 +#endif
62267 +
62268 +#endif
62269 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62270 new file mode 100644
62271 index 0000000..e7ffaaf
62272 --- /dev/null
62273 +++ b/include/linux/grsock.h
62274 @@ -0,0 +1,19 @@
62275 +#ifndef __GRSOCK_H
62276 +#define __GRSOCK_H
62277 +
62278 +extern void gr_attach_curr_ip(const struct sock *sk);
62279 +extern int gr_handle_sock_all(const int family, const int type,
62280 + const int protocol);
62281 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62282 +extern int gr_handle_sock_server_other(const struct sock *sck);
62283 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62284 +extern int gr_search_connect(struct socket * sock,
62285 + struct sockaddr_in * addr);
62286 +extern int gr_search_bind(struct socket * sock,
62287 + struct sockaddr_in * addr);
62288 +extern int gr_search_listen(struct socket * sock);
62289 +extern int gr_search_accept(struct socket * sock);
62290 +extern int gr_search_socket(const int domain, const int type,
62291 + const int protocol);
62292 +
62293 +#endif
62294 diff --git a/include/linux/hid.h b/include/linux/hid.h
62295 index 3a95da6..51986f1 100644
62296 --- a/include/linux/hid.h
62297 +++ b/include/linux/hid.h
62298 @@ -696,7 +696,7 @@ struct hid_ll_driver {
62299 unsigned int code, int value);
62300
62301 int (*parse)(struct hid_device *hdev);
62302 -};
62303 +} __no_const;
62304
62305 #define PM_HINT_FULLON 1<<5
62306 #define PM_HINT_NORMAL 1<<1
62307 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62308 index 3a93f73..b19d0b3 100644
62309 --- a/include/linux/highmem.h
62310 +++ b/include/linux/highmem.h
62311 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
62312 kunmap_atomic(kaddr, KM_USER0);
62313 }
62314
62315 +static inline void sanitize_highpage(struct page *page)
62316 +{
62317 + void *kaddr;
62318 + unsigned long flags;
62319 +
62320 + local_irq_save(flags);
62321 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
62322 + clear_page(kaddr);
62323 + kunmap_atomic(kaddr, KM_CLEARPAGE);
62324 + local_irq_restore(flags);
62325 +}
62326 +
62327 static inline void zero_user_segments(struct page *page,
62328 unsigned start1, unsigned end1,
62329 unsigned start2, unsigned end2)
62330 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62331 index 8e25a91..551b161 100644
62332 --- a/include/linux/i2c.h
62333 +++ b/include/linux/i2c.h
62334 @@ -364,6 +364,7 @@ struct i2c_algorithm {
62335 /* To determine what the adapter supports */
62336 u32 (*functionality) (struct i2c_adapter *);
62337 };
62338 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62339
62340 /*
62341 * i2c_adapter is the structure used to identify a physical i2c bus along
62342 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62343 index a6deef4..c56a7f2 100644
62344 --- a/include/linux/i2o.h
62345 +++ b/include/linux/i2o.h
62346 @@ -564,7 +564,7 @@ struct i2o_controller {
62347 struct i2o_device *exec; /* Executive */
62348 #if BITS_PER_LONG == 64
62349 spinlock_t context_list_lock; /* lock for context_list */
62350 - atomic_t context_list_counter; /* needed for unique contexts */
62351 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62352 struct list_head context_list; /* list of context id's
62353 and pointers */
62354 #endif
62355 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62356 index 58404b0..439ed95 100644
62357 --- a/include/linux/if_team.h
62358 +++ b/include/linux/if_team.h
62359 @@ -64,6 +64,7 @@ struct team_mode_ops {
62360 void (*port_leave)(struct team *team, struct team_port *port);
62361 void (*port_change_mac)(struct team *team, struct team_port *port);
62362 };
62363 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62364
62365 enum team_option_type {
62366 TEAM_OPTION_TYPE_U32,
62367 @@ -112,7 +113,7 @@ struct team {
62368 struct list_head option_list;
62369
62370 const struct team_mode *mode;
62371 - struct team_mode_ops ops;
62372 + team_mode_ops_no_const ops;
62373 long mode_priv[TEAM_MODE_PRIV_LONGS];
62374 };
62375
62376 diff --git a/include/linux/init.h b/include/linux/init.h
62377 index 6b95109..4aca62c 100644
62378 --- a/include/linux/init.h
62379 +++ b/include/linux/init.h
62380 @@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
62381
62382 /* Each module must use one module_init(). */
62383 #define module_init(initfn) \
62384 - static inline initcall_t __inittest(void) \
62385 + static inline __used initcall_t __inittest(void) \
62386 { return initfn; } \
62387 int init_module(void) __attribute__((alias(#initfn)));
62388
62389 /* This is only required if you want to be unloadable. */
62390 #define module_exit(exitfn) \
62391 - static inline exitcall_t __exittest(void) \
62392 + static inline __used exitcall_t __exittest(void) \
62393 { return exitfn; } \
62394 void cleanup_module(void) __attribute__((alias(#exitfn)));
62395
62396 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62397 index 9c66b1a..a3fdded 100644
62398 --- a/include/linux/init_task.h
62399 +++ b/include/linux/init_task.h
62400 @@ -127,6 +127,12 @@ extern struct cred init_cred;
62401
62402 #define INIT_TASK_COMM "swapper"
62403
62404 +#ifdef CONFIG_X86
62405 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62406 +#else
62407 +#define INIT_TASK_THREAD_INFO
62408 +#endif
62409 +
62410 /*
62411 * INIT_TASK is used to set up the first task table, touch at
62412 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62413 @@ -165,6 +171,7 @@ extern struct cred init_cred;
62414 RCU_INIT_POINTER(.cred, &init_cred), \
62415 .comm = INIT_TASK_COMM, \
62416 .thread = INIT_THREAD, \
62417 + INIT_TASK_THREAD_INFO \
62418 .fs = &init_fs, \
62419 .files = &init_files, \
62420 .signal = &init_signals, \
62421 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62422 index e6ca56d..8583707 100644
62423 --- a/include/linux/intel-iommu.h
62424 +++ b/include/linux/intel-iommu.h
62425 @@ -296,7 +296,7 @@ struct iommu_flush {
62426 u8 fm, u64 type);
62427 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62428 unsigned int size_order, u64 type);
62429 -};
62430 +} __no_const;
62431
62432 enum {
62433 SR_DMAR_FECTL_REG,
62434 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62435 index a64b00e..464d8bc 100644
62436 --- a/include/linux/interrupt.h
62437 +++ b/include/linux/interrupt.h
62438 @@ -441,7 +441,7 @@ enum
62439 /* map softirq index to softirq name. update 'softirq_to_name' in
62440 * kernel/softirq.c when adding a new softirq.
62441 */
62442 -extern char *softirq_to_name[NR_SOFTIRQS];
62443 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62444
62445 /* softirq mask and active fields moved to irq_cpustat_t in
62446 * asm/hardirq.h to get better cache usage. KAO
62447 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62448
62449 struct softirq_action
62450 {
62451 - void (*action)(struct softirq_action *);
62452 + void (*action)(void);
62453 };
62454
62455 asmlinkage void do_softirq(void);
62456 asmlinkage void __do_softirq(void);
62457 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62458 +extern void open_softirq(int nr, void (*action)(void));
62459 extern void softirq_init(void);
62460 static inline void __raise_softirq_irqoff(unsigned int nr)
62461 {
62462 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62463 index 3875719..4cd454c 100644
62464 --- a/include/linux/kallsyms.h
62465 +++ b/include/linux/kallsyms.h
62466 @@ -15,7 +15,8 @@
62467
62468 struct module;
62469
62470 -#ifdef CONFIG_KALLSYMS
62471 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62472 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62473 /* Lookup the address for a symbol. Returns 0 if not found. */
62474 unsigned long kallsyms_lookup_name(const char *name);
62475
62476 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62477 /* Stupid that this does nothing, but I didn't create this mess. */
62478 #define __print_symbol(fmt, addr)
62479 #endif /*CONFIG_KALLSYMS*/
62480 +#else /* when included by kallsyms.c, vsnprintf.c, or
62481 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62482 +extern void __print_symbol(const char *fmt, unsigned long address);
62483 +extern int sprint_backtrace(char *buffer, unsigned long address);
62484 +extern int sprint_symbol(char *buffer, unsigned long address);
62485 +const char *kallsyms_lookup(unsigned long addr,
62486 + unsigned long *symbolsize,
62487 + unsigned long *offset,
62488 + char **modname, char *namebuf);
62489 +#endif
62490
62491 /* This macro allows us to keep printk typechecking */
62492 static __printf(1, 2)
62493 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62494 index c4d2fc1..5df9c19 100644
62495 --- a/include/linux/kgdb.h
62496 +++ b/include/linux/kgdb.h
62497 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62498 extern int kgdb_io_module_registered;
62499
62500 extern atomic_t kgdb_setting_breakpoint;
62501 -extern atomic_t kgdb_cpu_doing_single_step;
62502 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62503
62504 extern struct task_struct *kgdb_usethread;
62505 extern struct task_struct *kgdb_contthread;
62506 @@ -252,7 +252,7 @@ struct kgdb_arch {
62507 void (*disable_hw_break)(struct pt_regs *regs);
62508 void (*remove_all_hw_break)(void);
62509 void (*correct_hw_break)(void);
62510 -};
62511 +} __do_const;
62512
62513 /**
62514 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62515 @@ -277,7 +277,7 @@ struct kgdb_io {
62516 void (*pre_exception) (void);
62517 void (*post_exception) (void);
62518 int is_console;
62519 -};
62520 +} __do_const;
62521
62522 extern struct kgdb_arch arch_kgdb_ops;
62523
62524 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62525 index 0fb48ef..1b680b2 100644
62526 --- a/include/linux/kmod.h
62527 +++ b/include/linux/kmod.h
62528 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62529 * usually useless though. */
62530 extern __printf(2, 3)
62531 int __request_module(bool wait, const char *name, ...);
62532 +extern __printf(3, 4)
62533 +int ___request_module(bool wait, char *param_name, const char *name, ...);
62534 #define request_module(mod...) __request_module(true, mod)
62535 #define request_module_nowait(mod...) __request_module(false, mod)
62536 #define try_then_request_module(x, mod...) \
62537 diff --git a/include/linux/kref.h b/include/linux/kref.h
62538 index 9c07dce..a92fa71 100644
62539 --- a/include/linux/kref.h
62540 +++ b/include/linux/kref.h
62541 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62542 static inline int kref_sub(struct kref *kref, unsigned int count,
62543 void (*release)(struct kref *kref))
62544 {
62545 - WARN_ON(release == NULL);
62546 + BUG_ON(release == NULL);
62547
62548 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62549 release(kref);
62550 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62551 index bc21720..098aefa 100644
62552 --- a/include/linux/kvm_host.h
62553 +++ b/include/linux/kvm_host.h
62554 @@ -326,7 +326,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62555 void vcpu_load(struct kvm_vcpu *vcpu);
62556 void vcpu_put(struct kvm_vcpu *vcpu);
62557
62558 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62559 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62560 struct module *module);
62561 void kvm_exit(void);
62562
62563 @@ -416,20 +416,20 @@ void kvm_get_pfn(pfn_t pfn);
62564 int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
62565 int len);
62566 int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
62567 - unsigned long len);
62568 -int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
62569 + unsigned long len) __size_overflow(4);
62570 +int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len) __size_overflow(2,4);
62571 int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62572 - void *data, unsigned long len);
62573 + void *data, unsigned long len) __size_overflow(4);
62574 int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
62575 int offset, int len);
62576 int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
62577 - unsigned long len);
62578 + unsigned long len) __size_overflow(2,4);
62579 int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62580 - void *data, unsigned long len);
62581 + void *data, unsigned long len) __size_overflow(4);
62582 int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62583 gpa_t gpa);
62584 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
62585 -int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
62586 +int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len) __size_overflow(2,3);
62587 struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
62588 int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
62589 unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn);
62590 @@ -485,7 +485,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62591 struct kvm_guest_debug *dbg);
62592 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62593
62594 -int kvm_arch_init(void *opaque);
62595 +int kvm_arch_init(const void *opaque);
62596 void kvm_arch_exit(void);
62597
62598 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62599 @@ -727,7 +727,7 @@ int kvm_setup_default_irq_routing(struct kvm *kvm);
62600 int kvm_set_irq_routing(struct kvm *kvm,
62601 const struct kvm_irq_routing_entry *entries,
62602 unsigned nr,
62603 - unsigned flags);
62604 + unsigned flags) __size_overflow(3);
62605 void kvm_free_irq_routing(struct kvm *kvm);
62606
62607 #else
62608 diff --git a/include/linux/libata.h b/include/linux/libata.h
62609 index cafc09a..d7e7829 100644
62610 --- a/include/linux/libata.h
62611 +++ b/include/linux/libata.h
62612 @@ -909,7 +909,7 @@ struct ata_port_operations {
62613 * fields must be pointers.
62614 */
62615 const struct ata_port_operations *inherits;
62616 -};
62617 +} __do_const;
62618
62619 struct ata_port_info {
62620 unsigned long flags;
62621 diff --git a/include/linux/mca.h b/include/linux/mca.h
62622 index 3797270..7765ede 100644
62623 --- a/include/linux/mca.h
62624 +++ b/include/linux/mca.h
62625 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
62626 int region);
62627 void * (*mca_transform_memory)(struct mca_device *,
62628 void *memory);
62629 -};
62630 +} __no_const;
62631
62632 struct mca_bus {
62633 u64 default_dma_mask;
62634 diff --git a/include/linux/memory.h b/include/linux/memory.h
62635 index 1ac7f6e..a5794d0 100644
62636 --- a/include/linux/memory.h
62637 +++ b/include/linux/memory.h
62638 @@ -143,7 +143,7 @@ struct memory_accessor {
62639 size_t count);
62640 ssize_t (*write)(struct memory_accessor *, const char *buf,
62641 off_t offset, size_t count);
62642 -};
62643 +} __no_const;
62644
62645 /*
62646 * Kernel text modification mutex, used for code patching. Users of this lock
62647 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62648 index 9970337..9444122 100644
62649 --- a/include/linux/mfd/abx500.h
62650 +++ b/include/linux/mfd/abx500.h
62651 @@ -188,6 +188,7 @@ struct abx500_ops {
62652 int (*event_registers_startup_state_get) (struct device *, u8 *);
62653 int (*startup_irq_enabled) (struct device *, unsigned int);
62654 };
62655 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62656
62657 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62658 void abx500_remove_ops(struct device *dev);
62659 diff --git a/include/linux/mm.h b/include/linux/mm.h
62660 index 17b27cd..baea141 100644
62661 --- a/include/linux/mm.h
62662 +++ b/include/linux/mm.h
62663 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
62664
62665 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62666 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62667 +
62668 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62669 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62670 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62671 +#else
62672 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62673 +#endif
62674 +
62675 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62676 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62677
62678 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
62679 int set_page_dirty_lock(struct page *page);
62680 int clear_page_dirty_for_io(struct page *page);
62681
62682 -/* Is the vma a continuation of the stack vma above it? */
62683 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62684 -{
62685 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62686 -}
62687 -
62688 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62689 - unsigned long addr)
62690 -{
62691 - return (vma->vm_flags & VM_GROWSDOWN) &&
62692 - (vma->vm_start == addr) &&
62693 - !vma_growsdown(vma->vm_prev, addr);
62694 -}
62695 -
62696 -/* Is the vma a continuation of the stack vma below it? */
62697 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62698 -{
62699 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62700 -}
62701 -
62702 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62703 - unsigned long addr)
62704 -{
62705 - return (vma->vm_flags & VM_GROWSUP) &&
62706 - (vma->vm_end == addr) &&
62707 - !vma_growsup(vma->vm_next, addr);
62708 -}
62709 -
62710 extern unsigned long move_page_tables(struct vm_area_struct *vma,
62711 unsigned long old_addr, struct vm_area_struct *new_vma,
62712 unsigned long new_addr, unsigned long len);
62713 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
62714 }
62715 #endif
62716
62717 +#ifdef CONFIG_MMU
62718 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62719 +#else
62720 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62721 +{
62722 + return __pgprot(0);
62723 +}
62724 +#endif
62725 +
62726 int vma_wants_writenotify(struct vm_area_struct *vma);
62727
62728 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62729 @@ -1152,8 +1140,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62730 {
62731 return 0;
62732 }
62733 +
62734 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62735 + unsigned long address)
62736 +{
62737 + return 0;
62738 +}
62739 #else
62740 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62741 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62742 #endif
62743
62744 #ifdef __PAGETABLE_PMD_FOLDED
62745 @@ -1162,8 +1157,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62746 {
62747 return 0;
62748 }
62749 +
62750 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62751 + unsigned long address)
62752 +{
62753 + return 0;
62754 +}
62755 #else
62756 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62757 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62758 #endif
62759
62760 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62761 @@ -1181,11 +1183,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62762 NULL: pud_offset(pgd, address);
62763 }
62764
62765 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62766 +{
62767 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62768 + NULL: pud_offset(pgd, address);
62769 +}
62770 +
62771 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62772 {
62773 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62774 NULL: pmd_offset(pud, address);
62775 }
62776 +
62777 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62778 +{
62779 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62780 + NULL: pmd_offset(pud, address);
62781 +}
62782 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62783
62784 #if USE_SPLIT_PTLOCKS
62785 @@ -1409,6 +1423,7 @@ out:
62786 }
62787
62788 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62789 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62790
62791 extern unsigned long do_brk(unsigned long, unsigned long);
62792
62793 @@ -1466,6 +1481,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62794 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62795 struct vm_area_struct **pprev);
62796
62797 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62798 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62799 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62800 +
62801 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62802 NULL if none. Assume start_addr < end_addr. */
62803 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62804 @@ -1494,15 +1513,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62805 return vma;
62806 }
62807
62808 -#ifdef CONFIG_MMU
62809 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
62810 -#else
62811 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62812 -{
62813 - return __pgprot(0);
62814 -}
62815 -#endif
62816 -
62817 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62818 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62819 unsigned long pfn, unsigned long size, pgprot_t);
62820 @@ -1606,7 +1616,7 @@ extern int unpoison_memory(unsigned long pfn);
62821 extern int sysctl_memory_failure_early_kill;
62822 extern int sysctl_memory_failure_recovery;
62823 extern void shake_page(struct page *p, int access);
62824 -extern atomic_long_t mce_bad_pages;
62825 +extern atomic_long_unchecked_t mce_bad_pages;
62826 extern int soft_offline_page(struct page *page, int flags);
62827
62828 extern void dump_page(struct page *page);
62829 @@ -1637,5 +1647,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62830 static inline bool page_is_guard(struct page *page) { return false; }
62831 #endif /* CONFIG_DEBUG_PAGEALLOC */
62832
62833 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62834 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62835 +#else
62836 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62837 +#endif
62838 +
62839 #endif /* __KERNEL__ */
62840 #endif /* _LINUX_MM_H */
62841 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62842 index 3cc3062..efeaeb7 100644
62843 --- a/include/linux/mm_types.h
62844 +++ b/include/linux/mm_types.h
62845 @@ -252,6 +252,8 @@ struct vm_area_struct {
62846 #ifdef CONFIG_NUMA
62847 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62848 #endif
62849 +
62850 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62851 };
62852
62853 struct core_thread {
62854 @@ -326,7 +328,7 @@ struct mm_struct {
62855 unsigned long def_flags;
62856 unsigned long nr_ptes; /* Page table pages */
62857 unsigned long start_code, end_code, start_data, end_data;
62858 - unsigned long start_brk, brk, start_stack;
62859 + unsigned long brk_gap, start_brk, brk, start_stack;
62860 unsigned long arg_start, arg_end, env_start, env_end;
62861
62862 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62863 @@ -388,6 +390,24 @@ struct mm_struct {
62864 #ifdef CONFIG_CPUMASK_OFFSTACK
62865 struct cpumask cpumask_allocation;
62866 #endif
62867 +
62868 +#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)
62869 + unsigned long pax_flags;
62870 +#endif
62871 +
62872 +#ifdef CONFIG_PAX_DLRESOLVE
62873 + unsigned long call_dl_resolve;
62874 +#endif
62875 +
62876 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62877 + unsigned long call_syscall;
62878 +#endif
62879 +
62880 +#ifdef CONFIG_PAX_ASLR
62881 + unsigned long delta_mmap; /* randomized offset */
62882 + unsigned long delta_stack; /* randomized offset */
62883 +#endif
62884 +
62885 };
62886
62887 static inline void mm_init_cpumask(struct mm_struct *mm)
62888 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62889 index 1d1b1e1..2a13c78 100644
62890 --- a/include/linux/mmu_notifier.h
62891 +++ b/include/linux/mmu_notifier.h
62892 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62893 */
62894 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62895 ({ \
62896 - pte_t __pte; \
62897 + pte_t ___pte; \
62898 struct vm_area_struct *___vma = __vma; \
62899 unsigned long ___address = __address; \
62900 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62901 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62902 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62903 - __pte; \
62904 + ___pte; \
62905 })
62906
62907 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62908 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62909 index 650ba2f..af0a58c 100644
62910 --- a/include/linux/mmzone.h
62911 +++ b/include/linux/mmzone.h
62912 @@ -379,7 +379,7 @@ struct zone {
62913 unsigned long flags; /* zone flags, see below */
62914
62915 /* Zone statistics */
62916 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62917 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62918
62919 /*
62920 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62921 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62922 index 83ac071..2656e0e 100644
62923 --- a/include/linux/mod_devicetable.h
62924 +++ b/include/linux/mod_devicetable.h
62925 @@ -12,7 +12,7 @@
62926 typedef unsigned long kernel_ulong_t;
62927 #endif
62928
62929 -#define PCI_ANY_ID (~0)
62930 +#define PCI_ANY_ID ((__u16)~0)
62931
62932 struct pci_device_id {
62933 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62934 @@ -131,7 +131,7 @@ struct usb_device_id {
62935 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62936 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62937
62938 -#define HID_ANY_ID (~0)
62939 +#define HID_ANY_ID (~0U)
62940
62941 struct hid_device_id {
62942 __u16 bus;
62943 diff --git a/include/linux/module.h b/include/linux/module.h
62944 index 4598bf0..e069d7f 100644
62945 --- a/include/linux/module.h
62946 +++ b/include/linux/module.h
62947 @@ -17,6 +17,7 @@
62948 #include <linux/moduleparam.h>
62949 #include <linux/tracepoint.h>
62950 #include <linux/export.h>
62951 +#include <linux/fs.h>
62952
62953 #include <linux/percpu.h>
62954 #include <asm/module.h>
62955 @@ -275,19 +276,16 @@ struct module
62956 int (*init)(void);
62957
62958 /* If this is non-NULL, vfree after init() returns */
62959 - void *module_init;
62960 + void *module_init_rx, *module_init_rw;
62961
62962 /* Here is the actual code + data, vfree'd on unload. */
62963 - void *module_core;
62964 + void *module_core_rx, *module_core_rw;
62965
62966 /* Here are the sizes of the init and core sections */
62967 - unsigned int init_size, core_size;
62968 + unsigned int init_size_rw, core_size_rw;
62969
62970 /* The size of the executable code in each section. */
62971 - unsigned int init_text_size, core_text_size;
62972 -
62973 - /* Size of RO sections of the module (text+rodata) */
62974 - unsigned int init_ro_size, core_ro_size;
62975 + unsigned int init_size_rx, core_size_rx;
62976
62977 /* Arch-specific module values */
62978 struct mod_arch_specific arch;
62979 @@ -343,6 +341,10 @@ struct module
62980 #ifdef CONFIG_EVENT_TRACING
62981 struct ftrace_event_call **trace_events;
62982 unsigned int num_trace_events;
62983 + struct file_operations trace_id;
62984 + struct file_operations trace_enable;
62985 + struct file_operations trace_format;
62986 + struct file_operations trace_filter;
62987 #endif
62988 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62989 unsigned int num_ftrace_callsites;
62990 @@ -390,16 +392,46 @@ bool is_module_address(unsigned long addr);
62991 bool is_module_percpu_address(unsigned long addr);
62992 bool is_module_text_address(unsigned long addr);
62993
62994 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62995 +{
62996 +
62997 +#ifdef CONFIG_PAX_KERNEXEC
62998 + if (ktla_ktva(addr) >= (unsigned long)start &&
62999 + ktla_ktva(addr) < (unsigned long)start + size)
63000 + return 1;
63001 +#endif
63002 +
63003 + return ((void *)addr >= start && (void *)addr < start + size);
63004 +}
63005 +
63006 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63007 +{
63008 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63009 +}
63010 +
63011 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63012 +{
63013 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63014 +}
63015 +
63016 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63017 +{
63018 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63019 +}
63020 +
63021 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63022 +{
63023 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63024 +}
63025 +
63026 static inline int within_module_core(unsigned long addr, struct module *mod)
63027 {
63028 - return (unsigned long)mod->module_core <= addr &&
63029 - addr < (unsigned long)mod->module_core + mod->core_size;
63030 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63031 }
63032
63033 static inline int within_module_init(unsigned long addr, struct module *mod)
63034 {
63035 - return (unsigned long)mod->module_init <= addr &&
63036 - addr < (unsigned long)mod->module_init + mod->init_size;
63037 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63038 }
63039
63040 /* Search for module by name: must hold module_mutex. */
63041 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63042 index b2be02e..72d2f78 100644
63043 --- a/include/linux/moduleloader.h
63044 +++ b/include/linux/moduleloader.h
63045 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63046
63047 /* Allocator used for allocating struct module, core sections and init
63048 sections. Returns NULL on failure. */
63049 -void *module_alloc(unsigned long size);
63050 +void *module_alloc(unsigned long size) __size_overflow(1);
63051 +
63052 +#ifdef CONFIG_PAX_KERNEXEC
63053 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63054 +#else
63055 +#define module_alloc_exec(x) module_alloc(x)
63056 +#endif
63057
63058 /* Free memory returned from module_alloc. */
63059 void module_free(struct module *mod, void *module_region);
63060
63061 +#ifdef CONFIG_PAX_KERNEXEC
63062 +void module_free_exec(struct module *mod, void *module_region);
63063 +#else
63064 +#define module_free_exec(x, y) module_free((x), (y))
63065 +#endif
63066 +
63067 /* Apply the given relocation to the (simplified) ELF. Return -error
63068 or 0. */
63069 int apply_relocate(Elf_Shdr *sechdrs,
63070 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63071 index c47f4d6..23f9bdb 100644
63072 --- a/include/linux/moduleparam.h
63073 +++ b/include/linux/moduleparam.h
63074 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
63075 * @len is usually just sizeof(string).
63076 */
63077 #define module_param_string(name, string, len, perm) \
63078 - static const struct kparam_string __param_string_##name \
63079 + static const struct kparam_string __param_string_##name __used \
63080 = { len, string }; \
63081 __module_param_call(MODULE_PARAM_PREFIX, name, \
63082 &param_ops_string, \
63083 @@ -396,7 +396,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63084 */
63085 #define module_param_array_named(name, array, type, nump, perm) \
63086 param_check_##type(name, &(array)[0]); \
63087 - static const struct kparam_array __param_arr_##name \
63088 + static const struct kparam_array __param_arr_##name __used \
63089 = { .max = ARRAY_SIZE(array), .num = nump, \
63090 .ops = &param_ops_##type, \
63091 .elemsize = sizeof(array[0]), .elem = array }; \
63092 diff --git a/include/linux/namei.h b/include/linux/namei.h
63093 index ffc0213..2c1f2cb 100644
63094 --- a/include/linux/namei.h
63095 +++ b/include/linux/namei.h
63096 @@ -24,7 +24,7 @@ struct nameidata {
63097 unsigned seq;
63098 int last_type;
63099 unsigned depth;
63100 - char *saved_names[MAX_NESTED_LINKS + 1];
63101 + const char *saved_names[MAX_NESTED_LINKS + 1];
63102
63103 /* Intent data */
63104 union {
63105 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
63106 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
63107 extern void unlock_rename(struct dentry *, struct dentry *);
63108
63109 -static inline void nd_set_link(struct nameidata *nd, char *path)
63110 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63111 {
63112 nd->saved_names[nd->depth] = path;
63113 }
63114
63115 -static inline char *nd_get_link(struct nameidata *nd)
63116 +static inline const char *nd_get_link(const struct nameidata *nd)
63117 {
63118 return nd->saved_names[nd->depth];
63119 }
63120 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63121 index 4f3b01a..8256d1a 100644
63122 --- a/include/linux/netdevice.h
63123 +++ b/include/linux/netdevice.h
63124 @@ -1002,6 +1002,7 @@ struct net_device_ops {
63125 int (*ndo_neigh_construct)(struct neighbour *n);
63126 void (*ndo_neigh_destroy)(struct neighbour *n);
63127 };
63128 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63129
63130 /*
63131 * The DEVICE structure.
63132 @@ -1063,7 +1064,7 @@ struct net_device {
63133 int iflink;
63134
63135 struct net_device_stats stats;
63136 - atomic_long_t rx_dropped; /* dropped packets by core network
63137 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63138 * Do not use this in drivers.
63139 */
63140
63141 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63142 new file mode 100644
63143 index 0000000..33f4af8
63144 --- /dev/null
63145 +++ b/include/linux/netfilter/xt_gradm.h
63146 @@ -0,0 +1,9 @@
63147 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63148 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63149 +
63150 +struct xt_gradm_mtinfo {
63151 + __u16 flags;
63152 + __u16 invflags;
63153 +};
63154 +
63155 +#endif
63156 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63157 index c65a18a..0c05f3a 100644
63158 --- a/include/linux/of_pdt.h
63159 +++ b/include/linux/of_pdt.h
63160 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63161
63162 /* return 0 on success; fill in 'len' with number of bytes in path */
63163 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63164 -};
63165 +} __no_const;
63166
63167 extern void *prom_early_alloc(unsigned long size);
63168
63169 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63170 index a4c5624..2dabfb7 100644
63171 --- a/include/linux/oprofile.h
63172 +++ b/include/linux/oprofile.h
63173 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63174 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63175 char const * name, ulong * val);
63176
63177 -/** Create a file for read-only access to an atomic_t. */
63178 +/** Create a file for read-only access to an atomic_unchecked_t. */
63179 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63180 - char const * name, atomic_t * val);
63181 + char const * name, atomic_unchecked_t * val);
63182
63183 /** create a directory */
63184 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63185 @@ -163,7 +163,7 @@ ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t co
63186 * Read an ASCII string for a number from a userspace buffer and fill *val on success.
63187 * Returns 0 on success, < 0 on error.
63188 */
63189 -int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count);
63190 +int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count) __size_overflow(3);
63191
63192 /** lock for read/write safety */
63193 extern raw_spinlock_t oprofilefs_lock;
63194 diff --git a/include/linux/padata.h b/include/linux/padata.h
63195 index 4633b2f..988bc08 100644
63196 --- a/include/linux/padata.h
63197 +++ b/include/linux/padata.h
63198 @@ -129,7 +129,7 @@ struct parallel_data {
63199 struct padata_instance *pinst;
63200 struct padata_parallel_queue __percpu *pqueue;
63201 struct padata_serial_queue __percpu *squeue;
63202 - atomic_t seq_nr;
63203 + atomic_unchecked_t seq_nr;
63204 atomic_t reorder_objects;
63205 atomic_t refcnt;
63206 unsigned int max_seq_nr;
63207 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63208 index abb2776..d8b8e15 100644
63209 --- a/include/linux/perf_event.h
63210 +++ b/include/linux/perf_event.h
63211 @@ -750,8 +750,8 @@ struct perf_event {
63212
63213 enum perf_event_active_state state;
63214 unsigned int attach_state;
63215 - local64_t count;
63216 - atomic64_t child_count;
63217 + local64_t count; /* PaX: fix it one day */
63218 + atomic64_unchecked_t child_count;
63219
63220 /*
63221 * These are the total time in nanoseconds that the event
63222 @@ -802,8 +802,8 @@ struct perf_event {
63223 * These accumulate total time (in nanoseconds) that children
63224 * events have been enabled and running, respectively.
63225 */
63226 - atomic64_t child_total_time_enabled;
63227 - atomic64_t child_total_time_running;
63228 + atomic64_unchecked_t child_total_time_enabled;
63229 + atomic64_unchecked_t child_total_time_running;
63230
63231 /*
63232 * Protect attach/detach and child_list:
63233 diff --git a/include/linux/personality.h b/include/linux/personality.h
63234 index 8fc7dd1a..c19d89e 100644
63235 --- a/include/linux/personality.h
63236 +++ b/include/linux/personality.h
63237 @@ -44,6 +44,7 @@ enum {
63238 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63239 ADDR_NO_RANDOMIZE | \
63240 ADDR_COMPAT_LAYOUT | \
63241 + ADDR_LIMIT_3GB | \
63242 MMAP_PAGE_ZERO)
63243
63244 /*
63245 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63246 index 0072a53..c5dcca5 100644
63247 --- a/include/linux/pipe_fs_i.h
63248 +++ b/include/linux/pipe_fs_i.h
63249 @@ -47,9 +47,9 @@ struct pipe_buffer {
63250 struct pipe_inode_info {
63251 wait_queue_head_t wait;
63252 unsigned int nrbufs, curbuf, buffers;
63253 - unsigned int readers;
63254 - unsigned int writers;
63255 - unsigned int waiting_writers;
63256 + atomic_t readers;
63257 + atomic_t writers;
63258 + atomic_t waiting_writers;
63259 unsigned int r_counter;
63260 unsigned int w_counter;
63261 struct page *tmp_page;
63262 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63263 index 609daae..5392427 100644
63264 --- a/include/linux/pm_runtime.h
63265 +++ b/include/linux/pm_runtime.h
63266 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63267
63268 static inline void pm_runtime_mark_last_busy(struct device *dev)
63269 {
63270 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63271 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63272 }
63273
63274 #else /* !CONFIG_PM_RUNTIME */
63275 diff --git a/include/linux/poison.h b/include/linux/poison.h
63276 index 2110a81..13a11bb 100644
63277 --- a/include/linux/poison.h
63278 +++ b/include/linux/poison.h
63279 @@ -19,8 +19,8 @@
63280 * under normal circumstances, used to verify that nobody uses
63281 * non-initialized list entries.
63282 */
63283 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63284 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63285 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63286 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63287
63288 /********** include/linux/timer.h **********/
63289 /*
63290 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63291 index 58969b2..ead129b 100644
63292 --- a/include/linux/preempt.h
63293 +++ b/include/linux/preempt.h
63294 @@ -123,7 +123,7 @@ struct preempt_ops {
63295 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63296 void (*sched_out)(struct preempt_notifier *notifier,
63297 struct task_struct *next);
63298 -};
63299 +} __no_const;
63300
63301 /**
63302 * preempt_notifier - key for installing preemption notifiers
63303 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63304 index 85c5073..51fac8b 100644
63305 --- a/include/linux/proc_fs.h
63306 +++ b/include/linux/proc_fs.h
63307 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63308 return proc_create_data(name, mode, parent, proc_fops, NULL);
63309 }
63310
63311 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63312 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63313 +{
63314 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63315 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63316 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63317 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63318 +#else
63319 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63320 +#endif
63321 +}
63322 +
63323 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63324 umode_t mode, struct proc_dir_entry *base,
63325 read_proc_t *read_proc, void * data)
63326 @@ -258,7 +270,7 @@ union proc_op {
63327 int (*proc_show)(struct seq_file *m,
63328 struct pid_namespace *ns, struct pid *pid,
63329 struct task_struct *task);
63330 -};
63331 +} __no_const;
63332
63333 struct ctl_table_header;
63334 struct ctl_table;
63335 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
63336 index c2f1f6a..6fdb196 100644
63337 --- a/include/linux/ptrace.h
63338 +++ b/include/linux/ptrace.h
63339 @@ -199,9 +199,10 @@ static inline void ptrace_event(int event, unsigned long message)
63340 if (unlikely(ptrace_event_enabled(current, event))) {
63341 current->ptrace_message = message;
63342 ptrace_notify((event << 8) | SIGTRAP);
63343 - } else if (event == PTRACE_EVENT_EXEC && unlikely(current->ptrace)) {
63344 + } else if (event == PTRACE_EVENT_EXEC) {
63345 /* legacy EXEC report via SIGTRAP */
63346 - send_sig(SIGTRAP, current, 0);
63347 + if ((current->ptrace & (PT_PTRACED|PT_SEIZED)) == PT_PTRACED)
63348 + send_sig(SIGTRAP, current, 0);
63349 }
63350 }
63351
63352 diff --git a/include/linux/random.h b/include/linux/random.h
63353 index 8f74538..02a1012 100644
63354 --- a/include/linux/random.h
63355 +++ b/include/linux/random.h
63356 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
63357
63358 u32 prandom32(struct rnd_state *);
63359
63360 +static inline unsigned long pax_get_random_long(void)
63361 +{
63362 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63363 +}
63364 +
63365 /*
63366 * Handle minimum values for seeds
63367 */
63368 static inline u32 __seed(u32 x, u32 m)
63369 {
63370 - return (x < m) ? x + m : x;
63371 + return (x <= m) ? x + m + 1 : x;
63372 }
63373
63374 /**
63375 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63376 index e0879a7..a12f962 100644
63377 --- a/include/linux/reboot.h
63378 +++ b/include/linux/reboot.h
63379 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63380 * Architecture-specific implementations of sys_reboot commands.
63381 */
63382
63383 -extern void machine_restart(char *cmd);
63384 -extern void machine_halt(void);
63385 -extern void machine_power_off(void);
63386 +extern void machine_restart(char *cmd) __noreturn;
63387 +extern void machine_halt(void) __noreturn;
63388 +extern void machine_power_off(void) __noreturn;
63389
63390 extern void machine_shutdown(void);
63391 struct pt_regs;
63392 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63393 */
63394
63395 extern void kernel_restart_prepare(char *cmd);
63396 -extern void kernel_restart(char *cmd);
63397 -extern void kernel_halt(void);
63398 -extern void kernel_power_off(void);
63399 +extern void kernel_restart(char *cmd) __noreturn;
63400 +extern void kernel_halt(void) __noreturn;
63401 +extern void kernel_power_off(void) __noreturn;
63402
63403 extern int C_A_D; /* for sysctl */
63404 void ctrl_alt_del(void);
63405 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63406 * Emergency restart, callable from an interrupt handler.
63407 */
63408
63409 -extern void emergency_restart(void);
63410 +extern void emergency_restart(void) __noreturn;
63411 #include <asm/emergency-restart.h>
63412
63413 #endif
63414 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
63415 index 2213ddc..650212a 100644
63416 --- a/include/linux/reiserfs_fs.h
63417 +++ b/include/linux/reiserfs_fs.h
63418 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
63419 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
63420
63421 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
63422 -#define get_generation(s) atomic_read (&fs_generation(s))
63423 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
63424 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63425 #define __fs_changed(gen,s) (gen != get_generation (s))
63426 #define fs_changed(gen,s) \
63427 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
63428 index 8c9e85c..1698e9a 100644
63429 --- a/include/linux/reiserfs_fs_sb.h
63430 +++ b/include/linux/reiserfs_fs_sb.h
63431 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
63432 /* Comment? -Hans */
63433 wait_queue_head_t s_wait;
63434 /* To be obsoleted soon by per buffer seals.. -Hans */
63435 - atomic_t s_generation_counter; // increased by one every time the
63436 + atomic_unchecked_t s_generation_counter; // increased by one every time the
63437 // tree gets re-balanced
63438 unsigned long s_properties; /* File system properties. Currently holds
63439 on-disk FS format */
63440 diff --git a/include/linux/relay.h b/include/linux/relay.h
63441 index a822fd7..62b70f6 100644
63442 --- a/include/linux/relay.h
63443 +++ b/include/linux/relay.h
63444 @@ -159,7 +159,7 @@ struct rchan_callbacks
63445 * The callback should return 0 if successful, negative if not.
63446 */
63447 int (*remove_buf_file)(struct dentry *dentry);
63448 -};
63449 +} __no_const;
63450
63451 /*
63452 * CONFIG_RELAY kernel API, kernel/relay.c
63453 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63454 index c6c6084..5bf1212 100644
63455 --- a/include/linux/rfkill.h
63456 +++ b/include/linux/rfkill.h
63457 @@ -147,6 +147,7 @@ struct rfkill_ops {
63458 void (*query)(struct rfkill *rfkill, void *data);
63459 int (*set_block)(void *data, bool blocked);
63460 };
63461 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63462
63463 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63464 /**
63465 diff --git a/include/linux/rio.h b/include/linux/rio.h
63466 index 4d50611..c6858a2 100644
63467 --- a/include/linux/rio.h
63468 +++ b/include/linux/rio.h
63469 @@ -315,7 +315,7 @@ struct rio_ops {
63470 int mbox, void *buffer, size_t len);
63471 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63472 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63473 -};
63474 +} __no_const;
63475
63476 #define RIO_RESOURCE_MEM 0x00000100
63477 #define RIO_RESOURCE_DOORBELL 0x00000200
63478 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63479 index 1cdd62a..e399f0d 100644
63480 --- a/include/linux/rmap.h
63481 +++ b/include/linux/rmap.h
63482 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63483 void anon_vma_init(void); /* create anon_vma_cachep */
63484 int anon_vma_prepare(struct vm_area_struct *);
63485 void unlink_anon_vmas(struct vm_area_struct *);
63486 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63487 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63488 void anon_vma_moveto_tail(struct vm_area_struct *);
63489 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63490 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63491 void __anon_vma_link(struct vm_area_struct *);
63492
63493 static inline void anon_vma_merge(struct vm_area_struct *vma,
63494 diff --git a/include/linux/sched.h b/include/linux/sched.h
63495 index 0657368..765f70f 100644
63496 --- a/include/linux/sched.h
63497 +++ b/include/linux/sched.h
63498 @@ -101,6 +101,7 @@ struct bio_list;
63499 struct fs_struct;
63500 struct perf_event_context;
63501 struct blk_plug;
63502 +struct linux_binprm;
63503
63504 /*
63505 * List of flags we want to share for kernel threads,
63506 @@ -382,10 +383,13 @@ struct user_namespace;
63507 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63508
63509 extern int sysctl_max_map_count;
63510 +extern unsigned long sysctl_heap_stack_gap;
63511
63512 #include <linux/aio.h>
63513
63514 #ifdef CONFIG_MMU
63515 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63516 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63517 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63518 extern unsigned long
63519 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63520 @@ -631,6 +635,17 @@ struct signal_struct {
63521 #ifdef CONFIG_TASKSTATS
63522 struct taskstats *stats;
63523 #endif
63524 +
63525 +#ifdef CONFIG_GRKERNSEC
63526 + u32 curr_ip;
63527 + u32 saved_ip;
63528 + u32 gr_saddr;
63529 + u32 gr_daddr;
63530 + u16 gr_sport;
63531 + u16 gr_dport;
63532 + u8 used_accept:1;
63533 +#endif
63534 +
63535 #ifdef CONFIG_AUDIT
63536 unsigned audit_tty;
63537 struct tty_audit_buf *tty_audit_buf;
63538 @@ -714,6 +729,11 @@ struct user_struct {
63539 struct key *session_keyring; /* UID's default session keyring */
63540 #endif
63541
63542 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63543 + unsigned int banned;
63544 + unsigned long ban_expires;
63545 +#endif
63546 +
63547 /* Hash table maintenance information */
63548 struct hlist_node uidhash_node;
63549 uid_t uid;
63550 @@ -1354,8 +1374,8 @@ struct task_struct {
63551 struct list_head thread_group;
63552
63553 struct completion *vfork_done; /* for vfork() */
63554 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63555 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63556 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63557 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63558
63559 cputime_t utime, stime, utimescaled, stimescaled;
63560 cputime_t gtime;
63561 @@ -1371,13 +1391,6 @@ struct task_struct {
63562 struct task_cputime cputime_expires;
63563 struct list_head cpu_timers[3];
63564
63565 -/* process credentials */
63566 - const struct cred __rcu *real_cred; /* objective and real subjective task
63567 - * credentials (COW) */
63568 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63569 - * credentials (COW) */
63570 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63571 -
63572 char comm[TASK_COMM_LEN]; /* executable name excluding path
63573 - access with [gs]et_task_comm (which lock
63574 it with task_lock())
63575 @@ -1394,8 +1407,16 @@ struct task_struct {
63576 #endif
63577 /* CPU-specific state of this task */
63578 struct thread_struct thread;
63579 +/* thread_info moved to task_struct */
63580 +#ifdef CONFIG_X86
63581 + struct thread_info tinfo;
63582 +#endif
63583 /* filesystem information */
63584 struct fs_struct *fs;
63585 +
63586 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63587 + * credentials (COW) */
63588 +
63589 /* open file information */
63590 struct files_struct *files;
63591 /* namespaces */
63592 @@ -1442,6 +1463,11 @@ struct task_struct {
63593 struct rt_mutex_waiter *pi_blocked_on;
63594 #endif
63595
63596 +/* process credentials */
63597 + const struct cred __rcu *real_cred; /* objective and real subjective task
63598 + * credentials (COW) */
63599 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63600 +
63601 #ifdef CONFIG_DEBUG_MUTEXES
63602 /* mutex deadlock detection */
63603 struct mutex_waiter *blocked_on;
63604 @@ -1558,6 +1584,27 @@ struct task_struct {
63605 unsigned long default_timer_slack_ns;
63606
63607 struct list_head *scm_work_list;
63608 +
63609 +#ifdef CONFIG_GRKERNSEC
63610 + /* grsecurity */
63611 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63612 + u64 exec_id;
63613 +#endif
63614 +#ifdef CONFIG_GRKERNSEC_SETXID
63615 + const struct cred *delayed_cred;
63616 +#endif
63617 + struct dentry *gr_chroot_dentry;
63618 + struct acl_subject_label *acl;
63619 + struct acl_role_label *role;
63620 + struct file *exec_file;
63621 + u16 acl_role_id;
63622 + /* is this the task that authenticated to the special role */
63623 + u8 acl_sp_role;
63624 + u8 is_writable;
63625 + u8 brute;
63626 + u8 gr_is_chrooted;
63627 +#endif
63628 +
63629 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63630 /* Index of current stored address in ret_stack */
63631 int curr_ret_stack;
63632 @@ -1592,6 +1639,51 @@ struct task_struct {
63633 #endif
63634 };
63635
63636 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63637 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63638 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63639 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63640 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63641 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63642 +
63643 +#ifdef CONFIG_PAX_SOFTMODE
63644 +extern int pax_softmode;
63645 +#endif
63646 +
63647 +extern int pax_check_flags(unsigned long *);
63648 +
63649 +/* if tsk != current then task_lock must be held on it */
63650 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63651 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63652 +{
63653 + if (likely(tsk->mm))
63654 + return tsk->mm->pax_flags;
63655 + else
63656 + return 0UL;
63657 +}
63658 +
63659 +/* if tsk != current then task_lock must be held on it */
63660 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63661 +{
63662 + if (likely(tsk->mm)) {
63663 + tsk->mm->pax_flags = flags;
63664 + return 0;
63665 + }
63666 + return -EINVAL;
63667 +}
63668 +#endif
63669 +
63670 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63671 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63672 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63673 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63674 +#endif
63675 +
63676 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63677 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63678 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63679 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
63680 +
63681 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63682 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63683
63684 @@ -2104,7 +2196,9 @@ void yield(void);
63685 extern struct exec_domain default_exec_domain;
63686
63687 union thread_union {
63688 +#ifndef CONFIG_X86
63689 struct thread_info thread_info;
63690 +#endif
63691 unsigned long stack[THREAD_SIZE/sizeof(long)];
63692 };
63693
63694 @@ -2137,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
63695 */
63696
63697 extern struct task_struct *find_task_by_vpid(pid_t nr);
63698 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63699 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63700 struct pid_namespace *ns);
63701
63702 @@ -2280,7 +2375,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63703 extern void exit_itimers(struct signal_struct *);
63704 extern void flush_itimer_signals(void);
63705
63706 -extern void do_group_exit(int);
63707 +extern __noreturn void do_group_exit(int);
63708
63709 extern void daemonize(const char *, ...);
63710 extern int allow_signal(int);
63711 @@ -2478,13 +2573,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63712
63713 #endif
63714
63715 -static inline int object_is_on_stack(void *obj)
63716 +static inline int object_starts_on_stack(void *obj)
63717 {
63718 - void *stack = task_stack_page(current);
63719 + const void *stack = task_stack_page(current);
63720
63721 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63722 }
63723
63724 +#ifdef CONFIG_PAX_USERCOPY
63725 +extern int object_is_on_stack(const void *obj, unsigned long len);
63726 +#endif
63727 +
63728 extern void thread_info_cache_init(void);
63729
63730 #ifdef CONFIG_DEBUG_STACK_USAGE
63731 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63732 index 899fbb4..1cb4138 100644
63733 --- a/include/linux/screen_info.h
63734 +++ b/include/linux/screen_info.h
63735 @@ -43,7 +43,8 @@ struct screen_info {
63736 __u16 pages; /* 0x32 */
63737 __u16 vesa_attributes; /* 0x34 */
63738 __u32 capabilities; /* 0x36 */
63739 - __u8 _reserved[6]; /* 0x3a */
63740 + __u16 vesapm_size; /* 0x3a */
63741 + __u8 _reserved[4]; /* 0x3c */
63742 } __attribute__((packed));
63743
63744 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63745 diff --git a/include/linux/security.h b/include/linux/security.h
63746 index 83c18e8..2d98860 100644
63747 --- a/include/linux/security.h
63748 +++ b/include/linux/security.h
63749 @@ -37,6 +37,7 @@
63750 #include <linux/xfrm.h>
63751 #include <linux/slab.h>
63752 #include <linux/xattr.h>
63753 +#include <linux/grsecurity.h>
63754 #include <net/flow.h>
63755
63756 /* Maximum number of letters for an LSM name string */
63757 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63758 index 44f1514..2bbf6c1 100644
63759 --- a/include/linux/seq_file.h
63760 +++ b/include/linux/seq_file.h
63761 @@ -24,6 +24,9 @@ struct seq_file {
63762 struct mutex lock;
63763 const struct seq_operations *op;
63764 int poll_event;
63765 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63766 + u64 exec_id;
63767 +#endif
63768 void *private;
63769 };
63770
63771 @@ -33,6 +36,7 @@ struct seq_operations {
63772 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63773 int (*show) (struct seq_file *m, void *v);
63774 };
63775 +typedef struct seq_operations __no_const seq_operations_no_const;
63776
63777 #define SEQ_SKIP 1
63778
63779 diff --git a/include/linux/shm.h b/include/linux/shm.h
63780 index 92808b8..c28cac4 100644
63781 --- a/include/linux/shm.h
63782 +++ b/include/linux/shm.h
63783 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63784
63785 /* The task created the shm object. NULL if the task is dead. */
63786 struct task_struct *shm_creator;
63787 +#ifdef CONFIG_GRKERNSEC
63788 + time_t shm_createtime;
63789 + pid_t shm_lapid;
63790 +#endif
63791 };
63792
63793 /* shm_mode upper byte flags */
63794 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63795 index 42854ce..3b7d3c8 100644
63796 --- a/include/linux/skbuff.h
63797 +++ b/include/linux/skbuff.h
63798 @@ -655,7 +655,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63799 */
63800 static inline int skb_queue_empty(const struct sk_buff_head *list)
63801 {
63802 - return list->next == (struct sk_buff *)list;
63803 + return list->next == (const struct sk_buff *)list;
63804 }
63805
63806 /**
63807 @@ -668,7 +668,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63808 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63809 const struct sk_buff *skb)
63810 {
63811 - return skb->next == (struct sk_buff *)list;
63812 + return skb->next == (const struct sk_buff *)list;
63813 }
63814
63815 /**
63816 @@ -681,7 +681,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63817 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63818 const struct sk_buff *skb)
63819 {
63820 - return skb->prev == (struct sk_buff *)list;
63821 + return skb->prev == (const struct sk_buff *)list;
63822 }
63823
63824 /**
63825 @@ -1558,7 +1558,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63826 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63827 */
63828 #ifndef NET_SKB_PAD
63829 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63830 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63831 #endif
63832
63833 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63834 diff --git a/include/linux/slab.h b/include/linux/slab.h
63835 index 573c809..07e1f43 100644
63836 --- a/include/linux/slab.h
63837 +++ b/include/linux/slab.h
63838 @@ -11,12 +11,20 @@
63839
63840 #include <linux/gfp.h>
63841 #include <linux/types.h>
63842 +#include <linux/err.h>
63843
63844 /*
63845 * Flags to pass to kmem_cache_create().
63846 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63847 */
63848 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63849 +
63850 +#ifdef CONFIG_PAX_USERCOPY
63851 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63852 +#else
63853 +#define SLAB_USERCOPY 0x00000000UL
63854 +#endif
63855 +
63856 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63857 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63858 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63859 @@ -87,10 +95,13 @@
63860 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63861 * Both make kfree a no-op.
63862 */
63863 -#define ZERO_SIZE_PTR ((void *)16)
63864 +#define ZERO_SIZE_PTR \
63865 +({ \
63866 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63867 + (void *)(-MAX_ERRNO-1L); \
63868 +})
63869
63870 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63871 - (unsigned long)ZERO_SIZE_PTR)
63872 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63873
63874 /*
63875 * struct kmem_cache related prototypes
63876 @@ -156,11 +167,12 @@ unsigned int kmem_cache_size(struct kmem_cache *);
63877 /*
63878 * Common kmalloc functions provided by all allocators
63879 */
63880 -void * __must_check __krealloc(const void *, size_t, gfp_t);
63881 -void * __must_check krealloc(const void *, size_t, gfp_t);
63882 +void * __must_check __krealloc(const void *, size_t, gfp_t) __size_overflow(2);
63883 +void * __must_check krealloc(const void *, size_t, gfp_t) __size_overflow(2);
63884 void kfree(const void *);
63885 void kzfree(const void *);
63886 size_t ksize(const void *);
63887 +void check_object_size(const void *ptr, unsigned long n, bool to);
63888
63889 /*
63890 * Allocator specific definitions. These are mainly used to establish optimized
63891 @@ -287,7 +299,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63892 */
63893 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63894 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63895 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63896 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63897 #define kmalloc_track_caller(size, flags) \
63898 __kmalloc_track_caller(size, flags, _RET_IP_)
63899 #else
63900 @@ -306,7 +318,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63901 */
63902 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63903 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63904 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63905 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63906 #define kmalloc_node_track_caller(size, flags, node) \
63907 __kmalloc_node_track_caller(size, flags, node, \
63908 _RET_IP_)
63909 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63910 index fbd1117..c0bd874 100644
63911 --- a/include/linux/slab_def.h
63912 +++ b/include/linux/slab_def.h
63913 @@ -66,10 +66,10 @@ struct kmem_cache {
63914 unsigned long node_allocs;
63915 unsigned long node_frees;
63916 unsigned long node_overflow;
63917 - atomic_t allochit;
63918 - atomic_t allocmiss;
63919 - atomic_t freehit;
63920 - atomic_t freemiss;
63921 + atomic_unchecked_t allochit;
63922 + atomic_unchecked_t allocmiss;
63923 + atomic_unchecked_t freehit;
63924 + atomic_unchecked_t freemiss;
63925
63926 /*
63927 * If debugging is enabled, then the allocator can add additional
63928 @@ -107,7 +107,7 @@ struct cache_sizes {
63929 extern struct cache_sizes malloc_sizes[];
63930
63931 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63932 -void *__kmalloc(size_t size, gfp_t flags);
63933 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63934
63935 #ifdef CONFIG_TRACING
63936 extern void *kmem_cache_alloc_trace(size_t size,
63937 @@ -125,6 +125,7 @@ static inline size_t slab_buffer_size(struct kmem_cache *cachep)
63938 }
63939 #endif
63940
63941 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63942 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63943 {
63944 struct kmem_cache *cachep;
63945 @@ -160,7 +161,7 @@ found:
63946 }
63947
63948 #ifdef CONFIG_NUMA
63949 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63950 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63951 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63952
63953 #ifdef CONFIG_TRACING
63954 @@ -179,6 +180,7 @@ kmem_cache_alloc_node_trace(size_t size,
63955 }
63956 #endif
63957
63958 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63959 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63960 {
63961 struct kmem_cache *cachep;
63962 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63963 index 0ec00b3..65e7e0e 100644
63964 --- a/include/linux/slob_def.h
63965 +++ b/include/linux/slob_def.h
63966 @@ -9,8 +9,9 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63967 return kmem_cache_alloc_node(cachep, flags, -1);
63968 }
63969
63970 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63971 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63972
63973 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63974 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63975 {
63976 return __kmalloc_node(size, flags, node);
63977 @@ -24,11 +25,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63978 * kmalloc is the normal method of allocating memory
63979 * in the kernel.
63980 */
63981 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63982 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63983 {
63984 return __kmalloc_node(size, flags, -1);
63985 }
63986
63987 +static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63988 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63989 {
63990 return kmalloc(size, flags);
63991 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63992 index a32bcfd..d26bd6e 100644
63993 --- a/include/linux/slub_def.h
63994 +++ b/include/linux/slub_def.h
63995 @@ -89,7 +89,7 @@ struct kmem_cache {
63996 struct kmem_cache_order_objects max;
63997 struct kmem_cache_order_objects min;
63998 gfp_t allocflags; /* gfp flags to use on each alloc */
63999 - int refcount; /* Refcount for slab cache destroy */
64000 + atomic_t refcount; /* Refcount for slab cache destroy */
64001 void (*ctor)(void *);
64002 int inuse; /* Offset to metadata */
64003 int align; /* Alignment */
64004 @@ -204,6 +204,7 @@ static __always_inline int kmalloc_index(size_t size)
64005 * This ought to end up with a global pointer to the right cache
64006 * in kmalloc_caches.
64007 */
64008 +static __always_inline struct kmem_cache *kmalloc_slab(size_t size) __size_overflow(1);
64009 static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64010 {
64011 int index = kmalloc_index(size);
64012 @@ -215,9 +216,11 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64013 }
64014
64015 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64016 -void *__kmalloc(size_t size, gfp_t flags);
64017 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64018
64019 static __always_inline void *
64020 +kmalloc_order(size_t size, gfp_t flags, unsigned int order) __size_overflow(1);
64021 +static __always_inline void *
64022 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64023 {
64024 void *ret = (void *) __get_free_pages(flags | __GFP_COMP, order);
64025 @@ -256,12 +259,14 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64026 }
64027 #endif
64028
64029 +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
64030 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64031 {
64032 unsigned int order = get_order(size);
64033 return kmalloc_order_trace(size, flags, order);
64034 }
64035
64036 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64037 static __always_inline void *kmalloc(size_t size, gfp_t flags)
64038 {
64039 if (__builtin_constant_p(size)) {
64040 @@ -281,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64041 }
64042
64043 #ifdef CONFIG_NUMA
64044 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64045 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64046 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64047
64048 #ifdef CONFIG_TRACING
64049 @@ -298,6 +303,7 @@ kmem_cache_alloc_node_trace(struct kmem_cache *s,
64050 }
64051 #endif
64052
64053 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64054 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64055 {
64056 if (__builtin_constant_p(size) &&
64057 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64058 index de8832d..0147b46 100644
64059 --- a/include/linux/sonet.h
64060 +++ b/include/linux/sonet.h
64061 @@ -61,7 +61,7 @@ struct sonet_stats {
64062 #include <linux/atomic.h>
64063
64064 struct k_sonet_stats {
64065 -#define __HANDLE_ITEM(i) atomic_t i
64066 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64067 __SONET_ITEMS
64068 #undef __HANDLE_ITEM
64069 };
64070 diff --git a/include/linux/stddef.h b/include/linux/stddef.h
64071 index 6a40c76..1747b67 100644
64072 --- a/include/linux/stddef.h
64073 +++ b/include/linux/stddef.h
64074 @@ -3,14 +3,10 @@
64075
64076 #include <linux/compiler.h>
64077
64078 +#ifdef __KERNEL__
64079 +
64080 #undef NULL
64081 -#if defined(__cplusplus)
64082 -#define NULL 0
64083 -#else
64084 #define NULL ((void *)0)
64085 -#endif
64086 -
64087 -#ifdef __KERNEL__
64088
64089 enum {
64090 false = 0,
64091 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64092 index 2c5993a..b0e79f0 100644
64093 --- a/include/linux/sunrpc/clnt.h
64094 +++ b/include/linux/sunrpc/clnt.h
64095 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64096 {
64097 switch (sap->sa_family) {
64098 case AF_INET:
64099 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64100 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64101 case AF_INET6:
64102 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64103 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64104 }
64105 return 0;
64106 }
64107 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64108 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64109 const struct sockaddr *src)
64110 {
64111 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64112 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64113 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64114
64115 dsin->sin_family = ssin->sin_family;
64116 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64117 if (sa->sa_family != AF_INET6)
64118 return 0;
64119
64120 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64121 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64122 }
64123
64124 #endif /* __KERNEL__ */
64125 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64126 index e775689..9e206d9 100644
64127 --- a/include/linux/sunrpc/sched.h
64128 +++ b/include/linux/sunrpc/sched.h
64129 @@ -105,6 +105,7 @@ struct rpc_call_ops {
64130 void (*rpc_call_done)(struct rpc_task *, void *);
64131 void (*rpc_release)(void *);
64132 };
64133 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64134
64135 struct rpc_task_setup {
64136 struct rpc_task *task;
64137 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64138 index c14fe86..393245e 100644
64139 --- a/include/linux/sunrpc/svc_rdma.h
64140 +++ b/include/linux/sunrpc/svc_rdma.h
64141 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64142 extern unsigned int svcrdma_max_requests;
64143 extern unsigned int svcrdma_max_req_size;
64144
64145 -extern atomic_t rdma_stat_recv;
64146 -extern atomic_t rdma_stat_read;
64147 -extern atomic_t rdma_stat_write;
64148 -extern atomic_t rdma_stat_sq_starve;
64149 -extern atomic_t rdma_stat_rq_starve;
64150 -extern atomic_t rdma_stat_rq_poll;
64151 -extern atomic_t rdma_stat_rq_prod;
64152 -extern atomic_t rdma_stat_sq_poll;
64153 -extern atomic_t rdma_stat_sq_prod;
64154 +extern atomic_unchecked_t rdma_stat_recv;
64155 +extern atomic_unchecked_t rdma_stat_read;
64156 +extern atomic_unchecked_t rdma_stat_write;
64157 +extern atomic_unchecked_t rdma_stat_sq_starve;
64158 +extern atomic_unchecked_t rdma_stat_rq_starve;
64159 +extern atomic_unchecked_t rdma_stat_rq_poll;
64160 +extern atomic_unchecked_t rdma_stat_rq_prod;
64161 +extern atomic_unchecked_t rdma_stat_sq_poll;
64162 +extern atomic_unchecked_t rdma_stat_sq_prod;
64163
64164 #define RPCRDMA_VERSION 1
64165
64166 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64167 index bb9127d..34ab358 100644
64168 --- a/include/linux/sysctl.h
64169 +++ b/include/linux/sysctl.h
64170 @@ -155,7 +155,11 @@ enum
64171 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64172 };
64173
64174 -
64175 +#ifdef CONFIG_PAX_SOFTMODE
64176 +enum {
64177 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64178 +};
64179 +#endif
64180
64181 /* CTL_VM names: */
64182 enum
64183 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64184
64185 extern int proc_dostring(struct ctl_table *, int,
64186 void __user *, size_t *, loff_t *);
64187 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64188 + void __user *, size_t *, loff_t *);
64189 extern int proc_dointvec(struct ctl_table *, int,
64190 void __user *, size_t *, loff_t *);
64191 extern int proc_dointvec_minmax(struct ctl_table *, int,
64192 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
64193 index a71a292..51bd91d 100644
64194 --- a/include/linux/tracehook.h
64195 +++ b/include/linux/tracehook.h
64196 @@ -54,12 +54,12 @@ struct linux_binprm;
64197 /*
64198 * ptrace report for syscall entry and exit looks identical.
64199 */
64200 -static inline void ptrace_report_syscall(struct pt_regs *regs)
64201 +static inline int ptrace_report_syscall(struct pt_regs *regs)
64202 {
64203 int ptrace = current->ptrace;
64204
64205 if (!(ptrace & PT_PTRACED))
64206 - return;
64207 + return 0;
64208
64209 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
64210
64211 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
64212 send_sig(current->exit_code, current, 1);
64213 current->exit_code = 0;
64214 }
64215 +
64216 + return fatal_signal_pending(current);
64217 }
64218
64219 /**
64220 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
64221 static inline __must_check int tracehook_report_syscall_entry(
64222 struct pt_regs *regs)
64223 {
64224 - ptrace_report_syscall(regs);
64225 - return 0;
64226 + return ptrace_report_syscall(regs);
64227 }
64228
64229 /**
64230 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64231 index ff7dc08..893e1bd 100644
64232 --- a/include/linux/tty_ldisc.h
64233 +++ b/include/linux/tty_ldisc.h
64234 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
64235
64236 struct module *owner;
64237
64238 - int refcount;
64239 + atomic_t refcount;
64240 };
64241
64242 struct tty_ldisc {
64243 diff --git a/include/linux/types.h b/include/linux/types.h
64244 index e5fa503..df6e8a4 100644
64245 --- a/include/linux/types.h
64246 +++ b/include/linux/types.h
64247 @@ -214,10 +214,26 @@ typedef struct {
64248 int counter;
64249 } atomic_t;
64250
64251 +#ifdef CONFIG_PAX_REFCOUNT
64252 +typedef struct {
64253 + int counter;
64254 +} atomic_unchecked_t;
64255 +#else
64256 +typedef atomic_t atomic_unchecked_t;
64257 +#endif
64258 +
64259 #ifdef CONFIG_64BIT
64260 typedef struct {
64261 long counter;
64262 } atomic64_t;
64263 +
64264 +#ifdef CONFIG_PAX_REFCOUNT
64265 +typedef struct {
64266 + long counter;
64267 +} atomic64_unchecked_t;
64268 +#else
64269 +typedef atomic64_t atomic64_unchecked_t;
64270 +#endif
64271 #endif
64272
64273 struct list_head {
64274 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64275 index 5ca0951..53a2fff 100644
64276 --- a/include/linux/uaccess.h
64277 +++ b/include/linux/uaccess.h
64278 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64279 long ret; \
64280 mm_segment_t old_fs = get_fs(); \
64281 \
64282 - set_fs(KERNEL_DS); \
64283 pagefault_disable(); \
64284 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64285 - pagefault_enable(); \
64286 + set_fs(KERNEL_DS); \
64287 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64288 set_fs(old_fs); \
64289 + pagefault_enable(); \
64290 ret; \
64291 })
64292
64293 @@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *dst, const void *src, size_t size);
64294 * Safely write to address @dst from the buffer at @src. If a kernel fault
64295 * happens, handle that and return -EFAULT.
64296 */
64297 -extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
64298 +extern long notrace probe_kernel_write(void *dst, const void *src, size_t size) __size_overflow(3);
64299 extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
64300
64301 #endif /* __LINUX_UACCESS_H__ */
64302 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64303 index 99c1b4d..bb94261 100644
64304 --- a/include/linux/unaligned/access_ok.h
64305 +++ b/include/linux/unaligned/access_ok.h
64306 @@ -6,32 +6,32 @@
64307
64308 static inline u16 get_unaligned_le16(const void *p)
64309 {
64310 - return le16_to_cpup((__le16 *)p);
64311 + return le16_to_cpup((const __le16 *)p);
64312 }
64313
64314 static inline u32 get_unaligned_le32(const void *p)
64315 {
64316 - return le32_to_cpup((__le32 *)p);
64317 + return le32_to_cpup((const __le32 *)p);
64318 }
64319
64320 static inline u64 get_unaligned_le64(const void *p)
64321 {
64322 - return le64_to_cpup((__le64 *)p);
64323 + return le64_to_cpup((const __le64 *)p);
64324 }
64325
64326 static inline u16 get_unaligned_be16(const void *p)
64327 {
64328 - return be16_to_cpup((__be16 *)p);
64329 + return be16_to_cpup((const __be16 *)p);
64330 }
64331
64332 static inline u32 get_unaligned_be32(const void *p)
64333 {
64334 - return be32_to_cpup((__be32 *)p);
64335 + return be32_to_cpup((const __be32 *)p);
64336 }
64337
64338 static inline u64 get_unaligned_be64(const void *p)
64339 {
64340 - return be64_to_cpup((__be64 *)p);
64341 + return be64_to_cpup((const __be64 *)p);
64342 }
64343
64344 static inline void put_unaligned_le16(u16 val, void *p)
64345 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64346 index 0d3f988..000f101 100644
64347 --- a/include/linux/usb/renesas_usbhs.h
64348 +++ b/include/linux/usb/renesas_usbhs.h
64349 @@ -39,7 +39,7 @@ enum {
64350 */
64351 struct renesas_usbhs_driver_callback {
64352 int (*notify_hotplug)(struct platform_device *pdev);
64353 -};
64354 +} __no_const;
64355
64356 /*
64357 * callback functions for platform
64358 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64359 * VBUS control is needed for Host
64360 */
64361 int (*set_vbus)(struct platform_device *pdev, int enable);
64362 -};
64363 +} __no_const;
64364
64365 /*
64366 * parameters for renesas usbhs
64367 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64368 index 6f8fbcf..8259001 100644
64369 --- a/include/linux/vermagic.h
64370 +++ b/include/linux/vermagic.h
64371 @@ -25,9 +25,35 @@
64372 #define MODULE_ARCH_VERMAGIC ""
64373 #endif
64374
64375 +#ifdef CONFIG_PAX_REFCOUNT
64376 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64377 +#else
64378 +#define MODULE_PAX_REFCOUNT ""
64379 +#endif
64380 +
64381 +#ifdef CONSTIFY_PLUGIN
64382 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64383 +#else
64384 +#define MODULE_CONSTIFY_PLUGIN ""
64385 +#endif
64386 +
64387 +#ifdef STACKLEAK_PLUGIN
64388 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64389 +#else
64390 +#define MODULE_STACKLEAK_PLUGIN ""
64391 +#endif
64392 +
64393 +#ifdef CONFIG_GRKERNSEC
64394 +#define MODULE_GRSEC "GRSEC "
64395 +#else
64396 +#define MODULE_GRSEC ""
64397 +#endif
64398 +
64399 #define VERMAGIC_STRING \
64400 UTS_RELEASE " " \
64401 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64402 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64403 - MODULE_ARCH_VERMAGIC
64404 + MODULE_ARCH_VERMAGIC \
64405 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64406 + MODULE_GRSEC
64407
64408 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64409 index dcdfc2b..cce598d 100644
64410 --- a/include/linux/vmalloc.h
64411 +++ b/include/linux/vmalloc.h
64412 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64413 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64414 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64415 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64416 +
64417 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64418 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64419 +#endif
64420 +
64421 /* bits [20..32] reserved for arch specific ioremap internals */
64422
64423 /*
64424 @@ -51,18 +56,18 @@ static inline void vmalloc_init(void)
64425 }
64426 #endif
64427
64428 -extern void *vmalloc(unsigned long size);
64429 -extern void *vzalloc(unsigned long size);
64430 -extern void *vmalloc_user(unsigned long size);
64431 -extern void *vmalloc_node(unsigned long size, int node);
64432 -extern void *vzalloc_node(unsigned long size, int node);
64433 -extern void *vmalloc_exec(unsigned long size);
64434 -extern void *vmalloc_32(unsigned long size);
64435 -extern void *vmalloc_32_user(unsigned long size);
64436 -extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64437 +extern void *vmalloc(unsigned long size) __size_overflow(1);
64438 +extern void *vzalloc(unsigned long size) __size_overflow(1);
64439 +extern void *vmalloc_user(unsigned long size) __size_overflow(1);
64440 +extern void *vmalloc_node(unsigned long size, int node) __size_overflow(1);
64441 +extern void *vzalloc_node(unsigned long size, int node) __size_overflow(1);
64442 +extern void *vmalloc_exec(unsigned long size) __size_overflow(1);
64443 +extern void *vmalloc_32(unsigned long size) __size_overflow(1);
64444 +extern void *vmalloc_32_user(unsigned long size) __size_overflow(1);
64445 +extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot) __size_overflow(1);
64446 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64447 unsigned long start, unsigned long end, gfp_t gfp_mask,
64448 - pgprot_t prot, int node, void *caller);
64449 + pgprot_t prot, int node, void *caller) __size_overflow(1);
64450 extern void vfree(const void *addr);
64451
64452 extern void *vmap(struct page **pages, unsigned int count,
64453 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64454 extern void free_vm_area(struct vm_struct *area);
64455
64456 /* for /dev/kmem */
64457 -extern long vread(char *buf, char *addr, unsigned long count);
64458 -extern long vwrite(char *buf, char *addr, unsigned long count);
64459 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64460 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64461
64462 /*
64463 * Internals. Dont't use..
64464 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64465 index 65efb92..137adbb 100644
64466 --- a/include/linux/vmstat.h
64467 +++ b/include/linux/vmstat.h
64468 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64469 /*
64470 * Zone based page accounting with per cpu differentials.
64471 */
64472 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64473 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64474
64475 static inline void zone_page_state_add(long x, struct zone *zone,
64476 enum zone_stat_item item)
64477 {
64478 - atomic_long_add(x, &zone->vm_stat[item]);
64479 - atomic_long_add(x, &vm_stat[item]);
64480 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64481 + atomic_long_add_unchecked(x, &vm_stat[item]);
64482 }
64483
64484 static inline unsigned long global_page_state(enum zone_stat_item item)
64485 {
64486 - long x = atomic_long_read(&vm_stat[item]);
64487 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64488 #ifdef CONFIG_SMP
64489 if (x < 0)
64490 x = 0;
64491 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64492 static inline unsigned long zone_page_state(struct zone *zone,
64493 enum zone_stat_item item)
64494 {
64495 - long x = atomic_long_read(&zone->vm_stat[item]);
64496 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64497 #ifdef CONFIG_SMP
64498 if (x < 0)
64499 x = 0;
64500 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64501 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64502 enum zone_stat_item item)
64503 {
64504 - long x = atomic_long_read(&zone->vm_stat[item]);
64505 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64506
64507 #ifdef CONFIG_SMP
64508 int cpu;
64509 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64510
64511 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64512 {
64513 - atomic_long_inc(&zone->vm_stat[item]);
64514 - atomic_long_inc(&vm_stat[item]);
64515 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64516 + atomic_long_inc_unchecked(&vm_stat[item]);
64517 }
64518
64519 static inline void __inc_zone_page_state(struct page *page,
64520 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64521
64522 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64523 {
64524 - atomic_long_dec(&zone->vm_stat[item]);
64525 - atomic_long_dec(&vm_stat[item]);
64526 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64527 + atomic_long_dec_unchecked(&vm_stat[item]);
64528 }
64529
64530 static inline void __dec_zone_page_state(struct page *page,
64531 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64532 index e5d1220..ef6e406 100644
64533 --- a/include/linux/xattr.h
64534 +++ b/include/linux/xattr.h
64535 @@ -57,6 +57,11 @@
64536 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64537 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64538
64539 +/* User namespace */
64540 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64541 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64542 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64543 +
64544 #ifdef __KERNEL__
64545
64546 #include <linux/types.h>
64547 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64548 index 4aeff96..b378cdc 100644
64549 --- a/include/media/saa7146_vv.h
64550 +++ b/include/media/saa7146_vv.h
64551 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
64552 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64553
64554 /* the extension can override this */
64555 - struct v4l2_ioctl_ops ops;
64556 + v4l2_ioctl_ops_no_const ops;
64557 /* pointer to the saa7146 core ops */
64558 const struct v4l2_ioctl_ops *core_ops;
64559
64560 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64561 index c7c40f1..4f01585 100644
64562 --- a/include/media/v4l2-dev.h
64563 +++ b/include/media/v4l2-dev.h
64564 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
64565
64566
64567 struct v4l2_file_operations {
64568 - struct module *owner;
64569 + struct module * const owner;
64570 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
64571 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
64572 unsigned int (*poll) (struct file *, struct poll_table_struct *);
64573 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
64574 int (*open) (struct file *);
64575 int (*release) (struct file *);
64576 };
64577 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64578
64579 /*
64580 * Newer version of video_device, handled by videodev2.c
64581 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64582 index 3f5d60f..44210ed 100644
64583 --- a/include/media/v4l2-ioctl.h
64584 +++ b/include/media/v4l2-ioctl.h
64585 @@ -278,7 +278,7 @@ struct v4l2_ioctl_ops {
64586 long (*vidioc_default) (struct file *file, void *fh,
64587 bool valid_prio, int cmd, void *arg);
64588 };
64589 -
64590 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64591
64592 /* v4l debugging and diagnostics */
64593
64594 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64595 index 8d55251..dfe5b0a 100644
64596 --- a/include/net/caif/caif_hsi.h
64597 +++ b/include/net/caif/caif_hsi.h
64598 @@ -98,7 +98,7 @@ struct cfhsi_drv {
64599 void (*rx_done_cb) (struct cfhsi_drv *drv);
64600 void (*wake_up_cb) (struct cfhsi_drv *drv);
64601 void (*wake_down_cb) (struct cfhsi_drv *drv);
64602 -};
64603 +} __no_const;
64604
64605 /* Structure implemented by HSI device. */
64606 struct cfhsi_dev {
64607 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64608 index 9e5425b..8136ffc 100644
64609 --- a/include/net/caif/cfctrl.h
64610 +++ b/include/net/caif/cfctrl.h
64611 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64612 void (*radioset_rsp)(void);
64613 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64614 struct cflayer *client_layer);
64615 -};
64616 +} __no_const;
64617
64618 /* Link Setup Parameters for CAIF-Links. */
64619 struct cfctrl_link_param {
64620 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64621 struct cfctrl {
64622 struct cfsrvl serv;
64623 struct cfctrl_rsp res;
64624 - atomic_t req_seq_no;
64625 - atomic_t rsp_seq_no;
64626 + atomic_unchecked_t req_seq_no;
64627 + atomic_unchecked_t rsp_seq_no;
64628 struct list_head list;
64629 /* Protects from simultaneous access to first_req list */
64630 spinlock_t info_list_lock;
64631 diff --git a/include/net/flow.h b/include/net/flow.h
64632 index 6c469db..7743b8e 100644
64633 --- a/include/net/flow.h
64634 +++ b/include/net/flow.h
64635 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64636
64637 extern void flow_cache_flush(void);
64638 extern void flow_cache_flush_deferred(void);
64639 -extern atomic_t flow_cache_genid;
64640 +extern atomic_unchecked_t flow_cache_genid;
64641
64642 #endif
64643 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64644 index b94765e..053f68b 100644
64645 --- a/include/net/inetpeer.h
64646 +++ b/include/net/inetpeer.h
64647 @@ -48,8 +48,8 @@ struct inet_peer {
64648 */
64649 union {
64650 struct {
64651 - atomic_t rid; /* Frag reception counter */
64652 - atomic_t ip_id_count; /* IP ID for the next packet */
64653 + atomic_unchecked_t rid; /* Frag reception counter */
64654 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64655 __u32 tcp_ts;
64656 __u32 tcp_ts_stamp;
64657 };
64658 @@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64659 more++;
64660 inet_peer_refcheck(p);
64661 do {
64662 - old = atomic_read(&p->ip_id_count);
64663 + old = atomic_read_unchecked(&p->ip_id_count);
64664 new = old + more;
64665 if (!new)
64666 new = 1;
64667 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64668 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64669 return new;
64670 }
64671
64672 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64673 index 10422ef..662570f 100644
64674 --- a/include/net/ip_fib.h
64675 +++ b/include/net/ip_fib.h
64676 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64677
64678 #define FIB_RES_SADDR(net, res) \
64679 ((FIB_RES_NH(res).nh_saddr_genid == \
64680 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64681 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64682 FIB_RES_NH(res).nh_saddr : \
64683 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64684 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64685 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64686 index ebe517f..1bd286b 100644
64687 --- a/include/net/ip_vs.h
64688 +++ b/include/net/ip_vs.h
64689 @@ -509,7 +509,7 @@ struct ip_vs_conn {
64690 struct ip_vs_conn *control; /* Master control connection */
64691 atomic_t n_control; /* Number of controlled ones */
64692 struct ip_vs_dest *dest; /* real server */
64693 - atomic_t in_pkts; /* incoming packet counter */
64694 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64695
64696 /* packet transmitter for different forwarding methods. If it
64697 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64698 @@ -647,7 +647,7 @@ struct ip_vs_dest {
64699 __be16 port; /* port number of the server */
64700 union nf_inet_addr addr; /* IP address of the server */
64701 volatile unsigned flags; /* dest status flags */
64702 - atomic_t conn_flags; /* flags to copy to conn */
64703 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64704 atomic_t weight; /* server weight */
64705
64706 atomic_t refcnt; /* reference counter */
64707 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64708 index 69b610a..fe3962c 100644
64709 --- a/include/net/irda/ircomm_core.h
64710 +++ b/include/net/irda/ircomm_core.h
64711 @@ -51,7 +51,7 @@ typedef struct {
64712 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64713 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64714 struct ircomm_info *);
64715 -} call_t;
64716 +} __no_const call_t;
64717
64718 struct ircomm_cb {
64719 irda_queue_t queue;
64720 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64721 index 59ba38bc..d515662 100644
64722 --- a/include/net/irda/ircomm_tty.h
64723 +++ b/include/net/irda/ircomm_tty.h
64724 @@ -35,6 +35,7 @@
64725 #include <linux/termios.h>
64726 #include <linux/timer.h>
64727 #include <linux/tty.h> /* struct tty_struct */
64728 +#include <asm/local.h>
64729
64730 #include <net/irda/irias_object.h>
64731 #include <net/irda/ircomm_core.h>
64732 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64733 unsigned short close_delay;
64734 unsigned short closing_wait; /* time to wait before closing */
64735
64736 - int open_count;
64737 - int blocked_open; /* # of blocked opens */
64738 + local_t open_count;
64739 + local_t blocked_open; /* # of blocked opens */
64740
64741 /* Protect concurent access to :
64742 * o self->open_count
64743 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64744 index 0954ec9..7413562 100644
64745 --- a/include/net/iucv/af_iucv.h
64746 +++ b/include/net/iucv/af_iucv.h
64747 @@ -138,7 +138,7 @@ struct iucv_sock {
64748 struct iucv_sock_list {
64749 struct hlist_head head;
64750 rwlock_t lock;
64751 - atomic_t autobind_name;
64752 + atomic_unchecked_t autobind_name;
64753 };
64754
64755 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64756 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64757 index 34c996f..bb3b4d4 100644
64758 --- a/include/net/neighbour.h
64759 +++ b/include/net/neighbour.h
64760 @@ -123,7 +123,7 @@ struct neigh_ops {
64761 void (*error_report)(struct neighbour *, struct sk_buff *);
64762 int (*output)(struct neighbour *, struct sk_buff *);
64763 int (*connected_output)(struct neighbour *, struct sk_buff *);
64764 -};
64765 +} __do_const;
64766
64767 struct pneigh_entry {
64768 struct pneigh_entry *next;
64769 diff --git a/include/net/netlink.h b/include/net/netlink.h
64770 index cb1f350..3279d2c 100644
64771 --- a/include/net/netlink.h
64772 +++ b/include/net/netlink.h
64773 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64774 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64775 {
64776 if (mark)
64777 - skb_trim(skb, (unsigned char *) mark - skb->data);
64778 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64779 }
64780
64781 /**
64782 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64783 index bbd023a..97c6d0d 100644
64784 --- a/include/net/netns/ipv4.h
64785 +++ b/include/net/netns/ipv4.h
64786 @@ -57,8 +57,8 @@ struct netns_ipv4 {
64787 unsigned int sysctl_ping_group_range[2];
64788 long sysctl_tcp_mem[3];
64789
64790 - atomic_t rt_genid;
64791 - atomic_t dev_addr_genid;
64792 + atomic_unchecked_t rt_genid;
64793 + atomic_unchecked_t dev_addr_genid;
64794
64795 #ifdef CONFIG_IP_MROUTE
64796 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64797 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64798 index d368561..96aaa17 100644
64799 --- a/include/net/sctp/sctp.h
64800 +++ b/include/net/sctp/sctp.h
64801 @@ -318,9 +318,9 @@ do { \
64802
64803 #else /* SCTP_DEBUG */
64804
64805 -#define SCTP_DEBUG_PRINTK(whatever...)
64806 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64807 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64808 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64809 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64810 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64811 #define SCTP_ENABLE_DEBUG
64812 #define SCTP_DISABLE_DEBUG
64813 #define SCTP_ASSERT(expr, str, func)
64814 diff --git a/include/net/sock.h b/include/net/sock.h
64815 index 91c1c8b..15ae923 100644
64816 --- a/include/net/sock.h
64817 +++ b/include/net/sock.h
64818 @@ -299,7 +299,7 @@ struct sock {
64819 #ifdef CONFIG_RPS
64820 __u32 sk_rxhash;
64821 #endif
64822 - atomic_t sk_drops;
64823 + atomic_unchecked_t sk_drops;
64824 int sk_rcvbuf;
64825
64826 struct sk_filter __rcu *sk_filter;
64827 @@ -1660,7 +1660,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64828 }
64829
64830 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64831 - char __user *from, char *to,
64832 + char __user *from, unsigned char *to,
64833 int copy, int offset)
64834 {
64835 if (skb->ip_summed == CHECKSUM_NONE) {
64836 diff --git a/include/net/tcp.h b/include/net/tcp.h
64837 index 2d80c29..aa07caf 100644
64838 --- a/include/net/tcp.h
64839 +++ b/include/net/tcp.h
64840 @@ -1426,7 +1426,7 @@ struct tcp_seq_afinfo {
64841 char *name;
64842 sa_family_t family;
64843 const struct file_operations *seq_fops;
64844 - struct seq_operations seq_ops;
64845 + seq_operations_no_const seq_ops;
64846 };
64847
64848 struct tcp_iter_state {
64849 diff --git a/include/net/udp.h b/include/net/udp.h
64850 index e39592f..fef9680 100644
64851 --- a/include/net/udp.h
64852 +++ b/include/net/udp.h
64853 @@ -243,7 +243,7 @@ struct udp_seq_afinfo {
64854 sa_family_t family;
64855 struct udp_table *udp_table;
64856 const struct file_operations *seq_fops;
64857 - struct seq_operations seq_ops;
64858 + seq_operations_no_const seq_ops;
64859 };
64860
64861 struct udp_iter_state {
64862 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64863 index 89174e2..1f82598 100644
64864 --- a/include/net/xfrm.h
64865 +++ b/include/net/xfrm.h
64866 @@ -505,7 +505,7 @@ struct xfrm_policy {
64867 struct timer_list timer;
64868
64869 struct flow_cache_object flo;
64870 - atomic_t genid;
64871 + atomic_unchecked_t genid;
64872 u32 priority;
64873 u32 index;
64874 struct xfrm_mark mark;
64875 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64876 index 1a046b1..ee0bef0 100644
64877 --- a/include/rdma/iw_cm.h
64878 +++ b/include/rdma/iw_cm.h
64879 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
64880 int backlog);
64881
64882 int (*destroy_listen)(struct iw_cm_id *cm_id);
64883 -};
64884 +} __no_const;
64885
64886 /**
64887 * iw_create_cm_id - Create an IW CM identifier.
64888 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64889 index 6a3922f..0b73022 100644
64890 --- a/include/scsi/libfc.h
64891 +++ b/include/scsi/libfc.h
64892 @@ -748,6 +748,7 @@ struct libfc_function_template {
64893 */
64894 void (*disc_stop_final) (struct fc_lport *);
64895 };
64896 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64897
64898 /**
64899 * struct fc_disc - Discovery context
64900 @@ -851,7 +852,7 @@ struct fc_lport {
64901 struct fc_vport *vport;
64902
64903 /* Operational Information */
64904 - struct libfc_function_template tt;
64905 + libfc_function_template_no_const tt;
64906 u8 link_up;
64907 u8 qfull;
64908 enum fc_lport_state state;
64909 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64910 index 77273f2..dd4031f 100644
64911 --- a/include/scsi/scsi_device.h
64912 +++ b/include/scsi/scsi_device.h
64913 @@ -161,9 +161,9 @@ struct scsi_device {
64914 unsigned int max_device_blocked; /* what device_blocked counts down from */
64915 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64916
64917 - atomic_t iorequest_cnt;
64918 - atomic_t iodone_cnt;
64919 - atomic_t ioerr_cnt;
64920 + atomic_unchecked_t iorequest_cnt;
64921 + atomic_unchecked_t iodone_cnt;
64922 + atomic_unchecked_t ioerr_cnt;
64923
64924 struct device sdev_gendev,
64925 sdev_dev;
64926 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64927 index 2a65167..91e01f8 100644
64928 --- a/include/scsi/scsi_transport_fc.h
64929 +++ b/include/scsi/scsi_transport_fc.h
64930 @@ -711,7 +711,7 @@ struct fc_function_template {
64931 unsigned long show_host_system_hostname:1;
64932
64933 unsigned long disable_target_scan:1;
64934 -};
64935 +} __do_const;
64936
64937
64938 /**
64939 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64940 index 030b87c..98a6954 100644
64941 --- a/include/sound/ak4xxx-adda.h
64942 +++ b/include/sound/ak4xxx-adda.h
64943 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64944 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64945 unsigned char val);
64946 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64947 -};
64948 +} __no_const;
64949
64950 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64951
64952 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64953 index 8c05e47..2b5df97 100644
64954 --- a/include/sound/hwdep.h
64955 +++ b/include/sound/hwdep.h
64956 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64957 struct snd_hwdep_dsp_status *status);
64958 int (*dsp_load)(struct snd_hwdep *hw,
64959 struct snd_hwdep_dsp_image *image);
64960 -};
64961 +} __no_const;
64962
64963 struct snd_hwdep {
64964 struct snd_card *card;
64965 diff --git a/include/sound/info.h b/include/sound/info.h
64966 index 9ca1a49..aba1728 100644
64967 --- a/include/sound/info.h
64968 +++ b/include/sound/info.h
64969 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
64970 struct snd_info_buffer *buffer);
64971 void (*write)(struct snd_info_entry *entry,
64972 struct snd_info_buffer *buffer);
64973 -};
64974 +} __no_const;
64975
64976 struct snd_info_entry_ops {
64977 int (*open)(struct snd_info_entry *entry,
64978 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64979 index 0cf91b2..b70cae4 100644
64980 --- a/include/sound/pcm.h
64981 +++ b/include/sound/pcm.h
64982 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
64983 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64984 int (*ack)(struct snd_pcm_substream *substream);
64985 };
64986 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64987
64988 /*
64989 *
64990 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64991 index af1b49e..a5d55a5 100644
64992 --- a/include/sound/sb16_csp.h
64993 +++ b/include/sound/sb16_csp.h
64994 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64995 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64996 int (*csp_stop) (struct snd_sb_csp * p);
64997 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64998 -};
64999 +} __no_const;
65000
65001 /*
65002 * CSP private data
65003 diff --git a/include/sound/soc.h b/include/sound/soc.h
65004 index 0992dff..bb366fe 100644
65005 --- a/include/sound/soc.h
65006 +++ b/include/sound/soc.h
65007 @@ -682,7 +682,7 @@ struct snd_soc_platform_driver {
65008 /* platform IO - used for platform DAPM */
65009 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65010 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65011 -};
65012 +} __do_const;
65013
65014 struct snd_soc_platform {
65015 const char *name;
65016 @@ -852,7 +852,7 @@ struct snd_soc_pcm_runtime {
65017 struct snd_soc_dai_link *dai_link;
65018 struct mutex pcm_mutex;
65019 enum snd_soc_pcm_subclass pcm_subclass;
65020 - struct snd_pcm_ops ops;
65021 + snd_pcm_ops_no_const ops;
65022
65023 unsigned int complete:1;
65024 unsigned int dev_registered:1;
65025 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
65026 index 444cd6b..3327cc5 100644
65027 --- a/include/sound/ymfpci.h
65028 +++ b/include/sound/ymfpci.h
65029 @@ -358,7 +358,7 @@ struct snd_ymfpci {
65030 spinlock_t reg_lock;
65031 spinlock_t voice_lock;
65032 wait_queue_head_t interrupt_sleep;
65033 - atomic_t interrupt_sleep_count;
65034 + atomic_unchecked_t interrupt_sleep_count;
65035 struct snd_info_entry *proc_entry;
65036 const struct firmware *dsp_microcode;
65037 const struct firmware *controller_microcode;
65038 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65039 index fe73eb8..56388b1 100644
65040 --- a/include/target/target_core_base.h
65041 +++ b/include/target/target_core_base.h
65042 @@ -443,7 +443,7 @@ struct t10_reservation_ops {
65043 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65044 int (*t10_pr_register)(struct se_cmd *);
65045 int (*t10_pr_clear)(struct se_cmd *);
65046 -};
65047 +} __no_const;
65048
65049 struct t10_reservation {
65050 /* Reservation effects all target ports */
65051 @@ -561,8 +561,8 @@ struct se_cmd {
65052 atomic_t t_se_count;
65053 atomic_t t_task_cdbs_left;
65054 atomic_t t_task_cdbs_ex_left;
65055 - atomic_t t_task_cdbs_sent;
65056 - atomic_t t_transport_aborted;
65057 + atomic_unchecked_t t_task_cdbs_sent;
65058 + atomic_unchecked_t t_transport_aborted;
65059 atomic_t t_transport_active;
65060 atomic_t t_transport_complete;
65061 atomic_t t_transport_queue_active;
65062 @@ -799,7 +799,7 @@ struct se_device {
65063 spinlock_t stats_lock;
65064 /* Active commands on this virtual SE device */
65065 atomic_t simple_cmds;
65066 - atomic_t dev_ordered_id;
65067 + atomic_unchecked_t dev_ordered_id;
65068 atomic_t execute_tasks;
65069 atomic_t dev_ordered_sync;
65070 atomic_t dev_qf_count;
65071 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65072 index 1c09820..7f5ec79 100644
65073 --- a/include/trace/events/irq.h
65074 +++ b/include/trace/events/irq.h
65075 @@ -36,7 +36,7 @@ struct softirq_action;
65076 */
65077 TRACE_EVENT(irq_handler_entry,
65078
65079 - TP_PROTO(int irq, struct irqaction *action),
65080 + TP_PROTO(int irq, const struct irqaction *action),
65081
65082 TP_ARGS(irq, action),
65083
65084 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65085 */
65086 TRACE_EVENT(irq_handler_exit,
65087
65088 - TP_PROTO(int irq, struct irqaction *action, int ret),
65089 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65090
65091 TP_ARGS(irq, action, ret),
65092
65093 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65094 index c41f308..6918de3 100644
65095 --- a/include/video/udlfb.h
65096 +++ b/include/video/udlfb.h
65097 @@ -52,10 +52,10 @@ struct dlfb_data {
65098 u32 pseudo_palette[256];
65099 int blank_mode; /*one of FB_BLANK_ */
65100 /* blit-only rendering path metrics, exposed through sysfs */
65101 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65102 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65103 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65104 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65105 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65106 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65107 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65108 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65109 };
65110
65111 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65112 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65113 index 0993a22..32ba2fe 100644
65114 --- a/include/video/uvesafb.h
65115 +++ b/include/video/uvesafb.h
65116 @@ -177,6 +177,7 @@ struct uvesafb_par {
65117 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65118 u8 pmi_setpal; /* PMI for palette changes */
65119 u16 *pmi_base; /* protected mode interface location */
65120 + u8 *pmi_code; /* protected mode code location */
65121 void *pmi_start;
65122 void *pmi_pal;
65123 u8 *vbe_state_orig; /*
65124 diff --git a/init/Kconfig b/init/Kconfig
65125 index 3f42cd6..613f41d 100644
65126 --- a/init/Kconfig
65127 +++ b/init/Kconfig
65128 @@ -799,6 +799,7 @@ endif # CGROUPS
65129
65130 config CHECKPOINT_RESTORE
65131 bool "Checkpoint/restore support" if EXPERT
65132 + depends on !GRKERNSEC
65133 default n
65134 help
65135 Enables additional kernel features in a sake of checkpoint/restore.
65136 @@ -1249,7 +1250,7 @@ config SLUB_DEBUG
65137
65138 config COMPAT_BRK
65139 bool "Disable heap randomization"
65140 - default y
65141 + default n
65142 help
65143 Randomizing heap placement makes heap exploits harder, but it
65144 also breaks ancient binaries (including anything libc5 based).
65145 diff --git a/init/do_mounts.c b/init/do_mounts.c
65146 index 2974c8b..0b863ae 100644
65147 --- a/init/do_mounts.c
65148 +++ b/init/do_mounts.c
65149 @@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
65150 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65151 {
65152 struct super_block *s;
65153 - int err = sys_mount(name, "/root", fs, flags, data);
65154 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65155 if (err)
65156 return err;
65157
65158 - sys_chdir((const char __user __force *)"/root");
65159 + sys_chdir((const char __force_user *)"/root");
65160 s = current->fs->pwd.dentry->d_sb;
65161 ROOT_DEV = s->s_dev;
65162 printk(KERN_INFO
65163 @@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
65164 va_start(args, fmt);
65165 vsprintf(buf, fmt, args);
65166 va_end(args);
65167 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65168 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65169 if (fd >= 0) {
65170 sys_ioctl(fd, FDEJECT, 0);
65171 sys_close(fd);
65172 }
65173 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65174 - fd = sys_open("/dev/console", O_RDWR, 0);
65175 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65176 if (fd >= 0) {
65177 sys_ioctl(fd, TCGETS, (long)&termios);
65178 termios.c_lflag &= ~ICANON;
65179 sys_ioctl(fd, TCSETSF, (long)&termios);
65180 - sys_read(fd, &c, 1);
65181 + sys_read(fd, (char __user *)&c, 1);
65182 termios.c_lflag |= ICANON;
65183 sys_ioctl(fd, TCSETSF, (long)&termios);
65184 sys_close(fd);
65185 @@ -555,6 +555,6 @@ void __init prepare_namespace(void)
65186 mount_root();
65187 out:
65188 devtmpfs_mount("dev");
65189 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65190 - sys_chroot((const char __user __force *)".");
65191 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65192 + sys_chroot((const char __force_user *)".");
65193 }
65194 diff --git a/init/do_mounts.h b/init/do_mounts.h
65195 index f5b978a..69dbfe8 100644
65196 --- a/init/do_mounts.h
65197 +++ b/init/do_mounts.h
65198 @@ -15,15 +15,15 @@ extern int root_mountflags;
65199
65200 static inline int create_dev(char *name, dev_t dev)
65201 {
65202 - sys_unlink(name);
65203 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65204 + sys_unlink((char __force_user *)name);
65205 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65206 }
65207
65208 #if BITS_PER_LONG == 32
65209 static inline u32 bstat(char *name)
65210 {
65211 struct stat64 stat;
65212 - if (sys_stat64(name, &stat) != 0)
65213 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65214 return 0;
65215 if (!S_ISBLK(stat.st_mode))
65216 return 0;
65217 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65218 static inline u32 bstat(char *name)
65219 {
65220 struct stat stat;
65221 - if (sys_newstat(name, &stat) != 0)
65222 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65223 return 0;
65224 if (!S_ISBLK(stat.st_mode))
65225 return 0;
65226 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65227 index 3098a38..253064e 100644
65228 --- a/init/do_mounts_initrd.c
65229 +++ b/init/do_mounts_initrd.c
65230 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
65231 create_dev("/dev/root.old", Root_RAM0);
65232 /* mount initrd on rootfs' /root */
65233 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65234 - sys_mkdir("/old", 0700);
65235 - root_fd = sys_open("/", 0, 0);
65236 - old_fd = sys_open("/old", 0, 0);
65237 + sys_mkdir((const char __force_user *)"/old", 0700);
65238 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65239 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65240 /* move initrd over / and chdir/chroot in initrd root */
65241 - sys_chdir("/root");
65242 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65243 - sys_chroot(".");
65244 + sys_chdir((const char __force_user *)"/root");
65245 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65246 + sys_chroot((const char __force_user *)".");
65247
65248 /*
65249 * In case that a resume from disk is carried out by linuxrc or one of
65250 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
65251
65252 /* move initrd to rootfs' /old */
65253 sys_fchdir(old_fd);
65254 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65255 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65256 /* switch root and cwd back to / of rootfs */
65257 sys_fchdir(root_fd);
65258 - sys_chroot(".");
65259 + sys_chroot((const char __force_user *)".");
65260 sys_close(old_fd);
65261 sys_close(root_fd);
65262
65263 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65264 - sys_chdir("/old");
65265 + sys_chdir((const char __force_user *)"/old");
65266 return;
65267 }
65268
65269 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
65270 mount_root();
65271
65272 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65273 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65274 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65275 if (!error)
65276 printk("okay\n");
65277 else {
65278 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
65279 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65280 if (error == -ENOENT)
65281 printk("/initrd does not exist. Ignored.\n");
65282 else
65283 printk("failed\n");
65284 printk(KERN_NOTICE "Unmounting old root\n");
65285 - sys_umount("/old", MNT_DETACH);
65286 + sys_umount((char __force_user *)"/old", MNT_DETACH);
65287 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65288 if (fd < 0) {
65289 error = fd;
65290 @@ -116,11 +116,11 @@ int __init initrd_load(void)
65291 * mounted in the normal path.
65292 */
65293 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65294 - sys_unlink("/initrd.image");
65295 + sys_unlink((const char __force_user *)"/initrd.image");
65296 handle_initrd();
65297 return 1;
65298 }
65299 }
65300 - sys_unlink("/initrd.image");
65301 + sys_unlink((const char __force_user *)"/initrd.image");
65302 return 0;
65303 }
65304 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65305 index 32c4799..c27ee74 100644
65306 --- a/init/do_mounts_md.c
65307 +++ b/init/do_mounts_md.c
65308 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
65309 partitioned ? "_d" : "", minor,
65310 md_setup_args[ent].device_names);
65311
65312 - fd = sys_open(name, 0, 0);
65313 + fd = sys_open((char __force_user *)name, 0, 0);
65314 if (fd < 0) {
65315 printk(KERN_ERR "md: open failed - cannot start "
65316 "array %s\n", name);
65317 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
65318 * array without it
65319 */
65320 sys_close(fd);
65321 - fd = sys_open(name, 0, 0);
65322 + fd = sys_open((char __force_user *)name, 0, 0);
65323 sys_ioctl(fd, BLKRRPART, 0);
65324 }
65325 sys_close(fd);
65326 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
65327
65328 wait_for_device_probe();
65329
65330 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
65331 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65332 if (fd >= 0) {
65333 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65334 sys_close(fd);
65335 diff --git a/init/initramfs.c b/init/initramfs.c
65336 index 8216c30..25e8e32 100644
65337 --- a/init/initramfs.c
65338 +++ b/init/initramfs.c
65339 @@ -74,7 +74,7 @@ static void __init free_hash(void)
65340 }
65341 }
65342
65343 -static long __init do_utime(char __user *filename, time_t mtime)
65344 +static long __init do_utime(__force char __user *filename, time_t mtime)
65345 {
65346 struct timespec t[2];
65347
65348 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
65349 struct dir_entry *de, *tmp;
65350 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65351 list_del(&de->list);
65352 - do_utime(de->name, de->mtime);
65353 + do_utime((char __force_user *)de->name, de->mtime);
65354 kfree(de->name);
65355 kfree(de);
65356 }
65357 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
65358 if (nlink >= 2) {
65359 char *old = find_link(major, minor, ino, mode, collected);
65360 if (old)
65361 - return (sys_link(old, collected) < 0) ? -1 : 1;
65362 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65363 }
65364 return 0;
65365 }
65366 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
65367 {
65368 struct stat st;
65369
65370 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65371 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65372 if (S_ISDIR(st.st_mode))
65373 - sys_rmdir(path);
65374 + sys_rmdir((char __force_user *)path);
65375 else
65376 - sys_unlink(path);
65377 + sys_unlink((char __force_user *)path);
65378 }
65379 }
65380
65381 @@ -305,7 +305,7 @@ static int __init do_name(void)
65382 int openflags = O_WRONLY|O_CREAT;
65383 if (ml != 1)
65384 openflags |= O_TRUNC;
65385 - wfd = sys_open(collected, openflags, mode);
65386 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65387
65388 if (wfd >= 0) {
65389 sys_fchown(wfd, uid, gid);
65390 @@ -317,17 +317,17 @@ static int __init do_name(void)
65391 }
65392 }
65393 } else if (S_ISDIR(mode)) {
65394 - sys_mkdir(collected, mode);
65395 - sys_chown(collected, uid, gid);
65396 - sys_chmod(collected, mode);
65397 + sys_mkdir((char __force_user *)collected, mode);
65398 + sys_chown((char __force_user *)collected, uid, gid);
65399 + sys_chmod((char __force_user *)collected, mode);
65400 dir_add(collected, mtime);
65401 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65402 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65403 if (maybe_link() == 0) {
65404 - sys_mknod(collected, mode, rdev);
65405 - sys_chown(collected, uid, gid);
65406 - sys_chmod(collected, mode);
65407 - do_utime(collected, mtime);
65408 + sys_mknod((char __force_user *)collected, mode, rdev);
65409 + sys_chown((char __force_user *)collected, uid, gid);
65410 + sys_chmod((char __force_user *)collected, mode);
65411 + do_utime((char __force_user *)collected, mtime);
65412 }
65413 }
65414 return 0;
65415 @@ -336,15 +336,15 @@ static int __init do_name(void)
65416 static int __init do_copy(void)
65417 {
65418 if (count >= body_len) {
65419 - sys_write(wfd, victim, body_len);
65420 + sys_write(wfd, (char __force_user *)victim, body_len);
65421 sys_close(wfd);
65422 - do_utime(vcollected, mtime);
65423 + do_utime((char __force_user *)vcollected, mtime);
65424 kfree(vcollected);
65425 eat(body_len);
65426 state = SkipIt;
65427 return 0;
65428 } else {
65429 - sys_write(wfd, victim, count);
65430 + sys_write(wfd, (char __force_user *)victim, count);
65431 body_len -= count;
65432 eat(count);
65433 return 1;
65434 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
65435 {
65436 collected[N_ALIGN(name_len) + body_len] = '\0';
65437 clean_path(collected, 0);
65438 - sys_symlink(collected + N_ALIGN(name_len), collected);
65439 - sys_lchown(collected, uid, gid);
65440 - do_utime(collected, mtime);
65441 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65442 + sys_lchown((char __force_user *)collected, uid, gid);
65443 + do_utime((char __force_user *)collected, mtime);
65444 state = SkipIt;
65445 next_state = Reset;
65446 return 0;
65447 diff --git a/init/main.c b/init/main.c
65448 index ff49a6d..5fa0429 100644
65449 --- a/init/main.c
65450 +++ b/init/main.c
65451 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
65452 extern void tc_init(void);
65453 #endif
65454
65455 +extern void grsecurity_init(void);
65456 +
65457 /*
65458 * Debug helper: via this flag we know that we are in 'early bootup code'
65459 * where only the boot processor is running with IRQ disabled. This means
65460 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
65461
65462 __setup("reset_devices", set_reset_devices);
65463
65464 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65465 +extern char pax_enter_kernel_user[];
65466 +extern char pax_exit_kernel_user[];
65467 +extern pgdval_t clone_pgd_mask;
65468 +#endif
65469 +
65470 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65471 +static int __init setup_pax_nouderef(char *str)
65472 +{
65473 +#ifdef CONFIG_X86_32
65474 + unsigned int cpu;
65475 + struct desc_struct *gdt;
65476 +
65477 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65478 + gdt = get_cpu_gdt_table(cpu);
65479 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65480 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65481 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65482 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65483 + }
65484 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65485 +#else
65486 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65487 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65488 + clone_pgd_mask = ~(pgdval_t)0UL;
65489 +#endif
65490 +
65491 + return 0;
65492 +}
65493 +early_param("pax_nouderef", setup_pax_nouderef);
65494 +#endif
65495 +
65496 +#ifdef CONFIG_PAX_SOFTMODE
65497 +int pax_softmode;
65498 +
65499 +static int __init setup_pax_softmode(char *str)
65500 +{
65501 + get_option(&str, &pax_softmode);
65502 + return 1;
65503 +}
65504 +__setup("pax_softmode=", setup_pax_softmode);
65505 +#endif
65506 +
65507 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65508 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65509 static const char *panic_later, *panic_param;
65510 @@ -675,6 +720,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65511 {
65512 int count = preempt_count();
65513 int ret;
65514 + const char *msg1 = "", *msg2 = "";
65515
65516 if (initcall_debug)
65517 ret = do_one_initcall_debug(fn);
65518 @@ -687,15 +733,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65519 sprintf(msgbuf, "error code %d ", ret);
65520
65521 if (preempt_count() != count) {
65522 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65523 + msg1 = " preemption imbalance";
65524 preempt_count() = count;
65525 }
65526 if (irqs_disabled()) {
65527 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65528 + msg2 = " disabled interrupts";
65529 local_irq_enable();
65530 }
65531 - if (msgbuf[0]) {
65532 - printk("initcall %pF returned with %s\n", fn, msgbuf);
65533 + if (msgbuf[0] || *msg1 || *msg2) {
65534 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65535 }
65536
65537 return ret;
65538 @@ -814,7 +860,7 @@ static int __init kernel_init(void * unused)
65539 do_basic_setup();
65540
65541 /* Open the /dev/console on the rootfs, this should never fail */
65542 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65543 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65544 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65545
65546 (void) sys_dup(0);
65547 @@ -827,11 +873,13 @@ static int __init kernel_init(void * unused)
65548 if (!ramdisk_execute_command)
65549 ramdisk_execute_command = "/init";
65550
65551 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65552 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65553 ramdisk_execute_command = NULL;
65554 prepare_namespace();
65555 }
65556
65557 + grsecurity_init();
65558 +
65559 /*
65560 * Ok, we have completed the initial bootup, and
65561 * we're essentially up and running. Get rid of the
65562 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65563 index 86ee272..773d937 100644
65564 --- a/ipc/mqueue.c
65565 +++ b/ipc/mqueue.c
65566 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65567 mq_bytes = (mq_msg_tblsz +
65568 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
65569
65570 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65571 spin_lock(&mq_lock);
65572 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65573 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65574 diff --git a/ipc/msg.c b/ipc/msg.c
65575 index 7385de2..a8180e08 100644
65576 --- a/ipc/msg.c
65577 +++ b/ipc/msg.c
65578 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65579 return security_msg_queue_associate(msq, msgflg);
65580 }
65581
65582 +static struct ipc_ops msg_ops = {
65583 + .getnew = newque,
65584 + .associate = msg_security,
65585 + .more_checks = NULL
65586 +};
65587 +
65588 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65589 {
65590 struct ipc_namespace *ns;
65591 - struct ipc_ops msg_ops;
65592 struct ipc_params msg_params;
65593
65594 ns = current->nsproxy->ipc_ns;
65595
65596 - msg_ops.getnew = newque;
65597 - msg_ops.associate = msg_security;
65598 - msg_ops.more_checks = NULL;
65599 -
65600 msg_params.key = key;
65601 msg_params.flg = msgflg;
65602
65603 diff --git a/ipc/sem.c b/ipc/sem.c
65604 index 5215a81..cfc0cac 100644
65605 --- a/ipc/sem.c
65606 +++ b/ipc/sem.c
65607 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65608 return 0;
65609 }
65610
65611 +static struct ipc_ops sem_ops = {
65612 + .getnew = newary,
65613 + .associate = sem_security,
65614 + .more_checks = sem_more_checks
65615 +};
65616 +
65617 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65618 {
65619 struct ipc_namespace *ns;
65620 - struct ipc_ops sem_ops;
65621 struct ipc_params sem_params;
65622
65623 ns = current->nsproxy->ipc_ns;
65624 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65625 if (nsems < 0 || nsems > ns->sc_semmsl)
65626 return -EINVAL;
65627
65628 - sem_ops.getnew = newary;
65629 - sem_ops.associate = sem_security;
65630 - sem_ops.more_checks = sem_more_checks;
65631 -
65632 sem_params.key = key;
65633 sem_params.flg = semflg;
65634 sem_params.u.nsems = nsems;
65635 diff --git a/ipc/shm.c b/ipc/shm.c
65636 index b76be5b..859e750 100644
65637 --- a/ipc/shm.c
65638 +++ b/ipc/shm.c
65639 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65640 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65641 #endif
65642
65643 +#ifdef CONFIG_GRKERNSEC
65644 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65645 + const time_t shm_createtime, const uid_t cuid,
65646 + const int shmid);
65647 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65648 + const time_t shm_createtime);
65649 +#endif
65650 +
65651 void shm_init_ns(struct ipc_namespace *ns)
65652 {
65653 ns->shm_ctlmax = SHMMAX;
65654 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65655 shp->shm_lprid = 0;
65656 shp->shm_atim = shp->shm_dtim = 0;
65657 shp->shm_ctim = get_seconds();
65658 +#ifdef CONFIG_GRKERNSEC
65659 + {
65660 + struct timespec timeval;
65661 + do_posix_clock_monotonic_gettime(&timeval);
65662 +
65663 + shp->shm_createtime = timeval.tv_sec;
65664 + }
65665 +#endif
65666 shp->shm_segsz = size;
65667 shp->shm_nattch = 0;
65668 shp->shm_file = file;
65669 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65670 return 0;
65671 }
65672
65673 +static struct ipc_ops shm_ops = {
65674 + .getnew = newseg,
65675 + .associate = shm_security,
65676 + .more_checks = shm_more_checks
65677 +};
65678 +
65679 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65680 {
65681 struct ipc_namespace *ns;
65682 - struct ipc_ops shm_ops;
65683 struct ipc_params shm_params;
65684
65685 ns = current->nsproxy->ipc_ns;
65686
65687 - shm_ops.getnew = newseg;
65688 - shm_ops.associate = shm_security;
65689 - shm_ops.more_checks = shm_more_checks;
65690 -
65691 shm_params.key = key;
65692 shm_params.flg = shmflg;
65693 shm_params.u.size = size;
65694 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65695 f_mode = FMODE_READ | FMODE_WRITE;
65696 }
65697 if (shmflg & SHM_EXEC) {
65698 +
65699 +#ifdef CONFIG_PAX_MPROTECT
65700 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
65701 + goto out;
65702 +#endif
65703 +
65704 prot |= PROT_EXEC;
65705 acc_mode |= S_IXUGO;
65706 }
65707 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65708 if (err)
65709 goto out_unlock;
65710
65711 +#ifdef CONFIG_GRKERNSEC
65712 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65713 + shp->shm_perm.cuid, shmid) ||
65714 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65715 + err = -EACCES;
65716 + goto out_unlock;
65717 + }
65718 +#endif
65719 +
65720 path = shp->shm_file->f_path;
65721 path_get(&path);
65722 shp->shm_nattch++;
65723 +#ifdef CONFIG_GRKERNSEC
65724 + shp->shm_lapid = current->pid;
65725 +#endif
65726 size = i_size_read(path.dentry->d_inode);
65727 shm_unlock(shp);
65728
65729 diff --git a/kernel/acct.c b/kernel/acct.c
65730 index 02e6167..54824f7 100644
65731 --- a/kernel/acct.c
65732 +++ b/kernel/acct.c
65733 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65734 */
65735 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65736 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65737 - file->f_op->write(file, (char *)&ac,
65738 + file->f_op->write(file, (char __force_user *)&ac,
65739 sizeof(acct_t), &file->f_pos);
65740 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65741 set_fs(fs);
65742 diff --git a/kernel/audit.c b/kernel/audit.c
65743 index bb0eb5b..cf2a03a 100644
65744 --- a/kernel/audit.c
65745 +++ b/kernel/audit.c
65746 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65747 3) suppressed due to audit_rate_limit
65748 4) suppressed due to audit_backlog_limit
65749 */
65750 -static atomic_t audit_lost = ATOMIC_INIT(0);
65751 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65752
65753 /* The netlink socket. */
65754 static struct sock *audit_sock;
65755 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65756 unsigned long now;
65757 int print;
65758
65759 - atomic_inc(&audit_lost);
65760 + atomic_inc_unchecked(&audit_lost);
65761
65762 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65763
65764 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65765 printk(KERN_WARNING
65766 "audit: audit_lost=%d audit_rate_limit=%d "
65767 "audit_backlog_limit=%d\n",
65768 - atomic_read(&audit_lost),
65769 + atomic_read_unchecked(&audit_lost),
65770 audit_rate_limit,
65771 audit_backlog_limit);
65772 audit_panic(message);
65773 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65774 status_set.pid = audit_pid;
65775 status_set.rate_limit = audit_rate_limit;
65776 status_set.backlog_limit = audit_backlog_limit;
65777 - status_set.lost = atomic_read(&audit_lost);
65778 + status_set.lost = atomic_read_unchecked(&audit_lost);
65779 status_set.backlog = skb_queue_len(&audit_skb_queue);
65780 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65781 &status_set, sizeof(status_set));
65782 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65783 index af1de0f..06dfe57 100644
65784 --- a/kernel/auditsc.c
65785 +++ b/kernel/auditsc.c
65786 @@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65787 }
65788
65789 /* global counter which is incremented every time something logs in */
65790 -static atomic_t session_id = ATOMIC_INIT(0);
65791 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65792
65793 /**
65794 * audit_set_loginuid - set current task's audit_context loginuid
65795 @@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
65796 return -EPERM;
65797 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65798
65799 - sessionid = atomic_inc_return(&session_id);
65800 + sessionid = atomic_inc_return_unchecked(&session_id);
65801 if (context && context->in_syscall) {
65802 struct audit_buffer *ab;
65803
65804 diff --git a/kernel/capability.c b/kernel/capability.c
65805 index 3f1adb6..c564db0 100644
65806 --- a/kernel/capability.c
65807 +++ b/kernel/capability.c
65808 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65809 * before modification is attempted and the application
65810 * fails.
65811 */
65812 + if (tocopy > ARRAY_SIZE(kdata))
65813 + return -EFAULT;
65814 +
65815 if (copy_to_user(dataptr, kdata, tocopy
65816 * sizeof(struct __user_cap_data_struct))) {
65817 return -EFAULT;
65818 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65819 int ret;
65820
65821 rcu_read_lock();
65822 - ret = security_capable(__task_cred(t), ns, cap);
65823 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65824 + gr_task_is_capable(t, __task_cred(t), cap);
65825 rcu_read_unlock();
65826
65827 - return (ret == 0);
65828 + return ret;
65829 }
65830
65831 /**
65832 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65833 int ret;
65834
65835 rcu_read_lock();
65836 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
65837 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65838 rcu_read_unlock();
65839
65840 - return (ret == 0);
65841 + return ret;
65842 }
65843
65844 /**
65845 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65846 BUG();
65847 }
65848
65849 - if (security_capable(current_cred(), ns, cap) == 0) {
65850 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65851 current->flags |= PF_SUPERPRIV;
65852 return true;
65853 }
65854 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65855 }
65856 EXPORT_SYMBOL(ns_capable);
65857
65858 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
65859 +{
65860 + if (unlikely(!cap_valid(cap))) {
65861 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65862 + BUG();
65863 + }
65864 +
65865 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65866 + current->flags |= PF_SUPERPRIV;
65867 + return true;
65868 + }
65869 + return false;
65870 +}
65871 +EXPORT_SYMBOL(ns_capable_nolog);
65872 +
65873 /**
65874 * capable - Determine if the current task has a superior capability in effect
65875 * @cap: The capability to be tested for
65876 @@ -408,6 +427,12 @@ bool capable(int cap)
65877 }
65878 EXPORT_SYMBOL(capable);
65879
65880 +bool capable_nolog(int cap)
65881 +{
65882 + return ns_capable_nolog(&init_user_ns, cap);
65883 +}
65884 +EXPORT_SYMBOL(capable_nolog);
65885 +
65886 /**
65887 * nsown_capable - Check superior capability to one's own user_ns
65888 * @cap: The capability in question
65889 diff --git a/kernel/compat.c b/kernel/compat.c
65890 index f346ced..aa2b1f4 100644
65891 --- a/kernel/compat.c
65892 +++ b/kernel/compat.c
65893 @@ -13,6 +13,7 @@
65894
65895 #include <linux/linkage.h>
65896 #include <linux/compat.h>
65897 +#include <linux/module.h>
65898 #include <linux/errno.h>
65899 #include <linux/time.h>
65900 #include <linux/signal.h>
65901 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65902 mm_segment_t oldfs;
65903 long ret;
65904
65905 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65906 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65907 oldfs = get_fs();
65908 set_fs(KERNEL_DS);
65909 ret = hrtimer_nanosleep_restart(restart);
65910 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65911 oldfs = get_fs();
65912 set_fs(KERNEL_DS);
65913 ret = hrtimer_nanosleep(&tu,
65914 - rmtp ? (struct timespec __user *)&rmt : NULL,
65915 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
65916 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65917 set_fs(oldfs);
65918
65919 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65920 mm_segment_t old_fs = get_fs();
65921
65922 set_fs(KERNEL_DS);
65923 - ret = sys_sigpending((old_sigset_t __user *) &s);
65924 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
65925 set_fs(old_fs);
65926 if (ret == 0)
65927 ret = put_user(s, set);
65928 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
65929 old_fs = get_fs();
65930 set_fs(KERNEL_DS);
65931 ret = sys_sigprocmask(how,
65932 - set ? (old_sigset_t __user *) &s : NULL,
65933 - oset ? (old_sigset_t __user *) &s : NULL);
65934 + set ? (old_sigset_t __force_user *) &s : NULL,
65935 + oset ? (old_sigset_t __force_user *) &s : NULL);
65936 set_fs(old_fs);
65937 if (ret == 0)
65938 if (oset)
65939 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65940 mm_segment_t old_fs = get_fs();
65941
65942 set_fs(KERNEL_DS);
65943 - ret = sys_old_getrlimit(resource, &r);
65944 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65945 set_fs(old_fs);
65946
65947 if (!ret) {
65948 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65949 mm_segment_t old_fs = get_fs();
65950
65951 set_fs(KERNEL_DS);
65952 - ret = sys_getrusage(who, (struct rusage __user *) &r);
65953 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65954 set_fs(old_fs);
65955
65956 if (ret)
65957 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65958 set_fs (KERNEL_DS);
65959 ret = sys_wait4(pid,
65960 (stat_addr ?
65961 - (unsigned int __user *) &status : NULL),
65962 - options, (struct rusage __user *) &r);
65963 + (unsigned int __force_user *) &status : NULL),
65964 + options, (struct rusage __force_user *) &r);
65965 set_fs (old_fs);
65966
65967 if (ret > 0) {
65968 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65969 memset(&info, 0, sizeof(info));
65970
65971 set_fs(KERNEL_DS);
65972 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65973 - uru ? (struct rusage __user *)&ru : NULL);
65974 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65975 + uru ? (struct rusage __force_user *)&ru : NULL);
65976 set_fs(old_fs);
65977
65978 if ((ret < 0) || (info.si_signo == 0))
65979 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65980 oldfs = get_fs();
65981 set_fs(KERNEL_DS);
65982 err = sys_timer_settime(timer_id, flags,
65983 - (struct itimerspec __user *) &newts,
65984 - (struct itimerspec __user *) &oldts);
65985 + (struct itimerspec __force_user *) &newts,
65986 + (struct itimerspec __force_user *) &oldts);
65987 set_fs(oldfs);
65988 if (!err && old && put_compat_itimerspec(old, &oldts))
65989 return -EFAULT;
65990 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65991 oldfs = get_fs();
65992 set_fs(KERNEL_DS);
65993 err = sys_timer_gettime(timer_id,
65994 - (struct itimerspec __user *) &ts);
65995 + (struct itimerspec __force_user *) &ts);
65996 set_fs(oldfs);
65997 if (!err && put_compat_itimerspec(setting, &ts))
65998 return -EFAULT;
65999 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66000 oldfs = get_fs();
66001 set_fs(KERNEL_DS);
66002 err = sys_clock_settime(which_clock,
66003 - (struct timespec __user *) &ts);
66004 + (struct timespec __force_user *) &ts);
66005 set_fs(oldfs);
66006 return err;
66007 }
66008 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66009 oldfs = get_fs();
66010 set_fs(KERNEL_DS);
66011 err = sys_clock_gettime(which_clock,
66012 - (struct timespec __user *) &ts);
66013 + (struct timespec __force_user *) &ts);
66014 set_fs(oldfs);
66015 if (!err && put_compat_timespec(&ts, tp))
66016 return -EFAULT;
66017 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66018
66019 oldfs = get_fs();
66020 set_fs(KERNEL_DS);
66021 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66022 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66023 set_fs(oldfs);
66024
66025 err = compat_put_timex(utp, &txc);
66026 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66027 oldfs = get_fs();
66028 set_fs(KERNEL_DS);
66029 err = sys_clock_getres(which_clock,
66030 - (struct timespec __user *) &ts);
66031 + (struct timespec __force_user *) &ts);
66032 set_fs(oldfs);
66033 if (!err && tp && put_compat_timespec(&ts, tp))
66034 return -EFAULT;
66035 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66036 long err;
66037 mm_segment_t oldfs;
66038 struct timespec tu;
66039 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66040 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66041
66042 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66043 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66044 oldfs = get_fs();
66045 set_fs(KERNEL_DS);
66046 err = clock_nanosleep_restart(restart);
66047 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66048 oldfs = get_fs();
66049 set_fs(KERNEL_DS);
66050 err = sys_clock_nanosleep(which_clock, flags,
66051 - (struct timespec __user *) &in,
66052 - (struct timespec __user *) &out);
66053 + (struct timespec __force_user *) &in,
66054 + (struct timespec __force_user *) &out);
66055 set_fs(oldfs);
66056
66057 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66058 diff --git a/kernel/configs.c b/kernel/configs.c
66059 index 42e8fa0..9e7406b 100644
66060 --- a/kernel/configs.c
66061 +++ b/kernel/configs.c
66062 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66063 struct proc_dir_entry *entry;
66064
66065 /* create the current config file */
66066 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66067 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66068 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66069 + &ikconfig_file_ops);
66070 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66071 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66072 + &ikconfig_file_ops);
66073 +#endif
66074 +#else
66075 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66076 &ikconfig_file_ops);
66077 +#endif
66078 +
66079 if (!entry)
66080 return -ENOMEM;
66081
66082 diff --git a/kernel/cred.c b/kernel/cred.c
66083 index 48c6fd3..3342f00 100644
66084 --- a/kernel/cred.c
66085 +++ b/kernel/cred.c
66086 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
66087 validate_creds(cred);
66088 put_cred(cred);
66089 }
66090 +
66091 +#ifdef CONFIG_GRKERNSEC_SETXID
66092 + cred = (struct cred *) tsk->delayed_cred;
66093 + if (cred) {
66094 + tsk->delayed_cred = NULL;
66095 + validate_creds(cred);
66096 + put_cred(cred);
66097 + }
66098 +#endif
66099 }
66100
66101 /**
66102 @@ -472,7 +481,7 @@ error_put:
66103 * Always returns 0 thus allowing this function to be tail-called at the end
66104 * of, say, sys_setgid().
66105 */
66106 -int commit_creds(struct cred *new)
66107 +static int __commit_creds(struct cred *new)
66108 {
66109 struct task_struct *task = current;
66110 const struct cred *old = task->real_cred;
66111 @@ -491,6 +500,8 @@ int commit_creds(struct cred *new)
66112
66113 get_cred(new); /* we will require a ref for the subj creds too */
66114
66115 + gr_set_role_label(task, new->uid, new->gid);
66116 +
66117 /* dumpability changes */
66118 if (old->euid != new->euid ||
66119 old->egid != new->egid ||
66120 @@ -540,6 +551,92 @@ int commit_creds(struct cred *new)
66121 put_cred(old);
66122 return 0;
66123 }
66124 +#ifdef CONFIG_GRKERNSEC_SETXID
66125 +extern int set_user(struct cred *new);
66126 +
66127 +void gr_delayed_cred_worker(void)
66128 +{
66129 + const struct cred *new = current->delayed_cred;
66130 + struct cred *ncred;
66131 +
66132 + current->delayed_cred = NULL;
66133 +
66134 + if (current_uid() && new != NULL) {
66135 + // from doing get_cred on it when queueing this
66136 + put_cred(new);
66137 + return;
66138 + } else if (new == NULL)
66139 + return;
66140 +
66141 + ncred = prepare_creds();
66142 + if (!ncred)
66143 + goto die;
66144 + // uids
66145 + ncred->uid = new->uid;
66146 + ncred->euid = new->euid;
66147 + ncred->suid = new->suid;
66148 + ncred->fsuid = new->fsuid;
66149 + // gids
66150 + ncred->gid = new->gid;
66151 + ncred->egid = new->egid;
66152 + ncred->sgid = new->sgid;
66153 + ncred->fsgid = new->fsgid;
66154 + // groups
66155 + if (set_groups(ncred, new->group_info) < 0) {
66156 + abort_creds(ncred);
66157 + goto die;
66158 + }
66159 + // caps
66160 + ncred->securebits = new->securebits;
66161 + ncred->cap_inheritable = new->cap_inheritable;
66162 + ncred->cap_permitted = new->cap_permitted;
66163 + ncred->cap_effective = new->cap_effective;
66164 + ncred->cap_bset = new->cap_bset;
66165 +
66166 + if (set_user(ncred)) {
66167 + abort_creds(ncred);
66168 + goto die;
66169 + }
66170 +
66171 + // from doing get_cred on it when queueing this
66172 + put_cred(new);
66173 +
66174 + __commit_creds(ncred);
66175 + return;
66176 +die:
66177 + // from doing get_cred on it when queueing this
66178 + put_cred(new);
66179 + do_group_exit(SIGKILL);
66180 +}
66181 +#endif
66182 +
66183 +int commit_creds(struct cred *new)
66184 +{
66185 +#ifdef CONFIG_GRKERNSEC_SETXID
66186 + struct task_struct *t;
66187 +
66188 + /* we won't get called with tasklist_lock held for writing
66189 + and interrupts disabled as the cred struct in that case is
66190 + init_cred
66191 + */
66192 + if (grsec_enable_setxid && !current_is_single_threaded() &&
66193 + !current_uid() && new->uid) {
66194 + rcu_read_lock();
66195 + read_lock(&tasklist_lock);
66196 + for (t = next_thread(current); t != current;
66197 + t = next_thread(t)) {
66198 + if (t->delayed_cred == NULL) {
66199 + t->delayed_cred = get_cred(new);
66200 + set_tsk_need_resched(t);
66201 + }
66202 + }
66203 + read_unlock(&tasklist_lock);
66204 + rcu_read_unlock();
66205 + }
66206 +#endif
66207 + return __commit_creds(new);
66208 +}
66209 +
66210 EXPORT_SYMBOL(commit_creds);
66211
66212 /**
66213 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66214 index 7fda904..59f620c 100644
66215 --- a/kernel/debug/debug_core.c
66216 +++ b/kernel/debug/debug_core.c
66217 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66218 */
66219 static atomic_t masters_in_kgdb;
66220 static atomic_t slaves_in_kgdb;
66221 -static atomic_t kgdb_break_tasklet_var;
66222 +static atomic_unchecked_t kgdb_break_tasklet_var;
66223 atomic_t kgdb_setting_breakpoint;
66224
66225 struct task_struct *kgdb_usethread;
66226 @@ -129,7 +129,7 @@ int kgdb_single_step;
66227 static pid_t kgdb_sstep_pid;
66228
66229 /* to keep track of the CPU which is doing the single stepping*/
66230 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66231 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66232
66233 /*
66234 * If you are debugging a problem where roundup (the collection of
66235 @@ -537,7 +537,7 @@ return_normal:
66236 * kernel will only try for the value of sstep_tries before
66237 * giving up and continuing on.
66238 */
66239 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66240 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66241 (kgdb_info[cpu].task &&
66242 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66243 atomic_set(&kgdb_active, -1);
66244 @@ -631,8 +631,8 @@ cpu_master_loop:
66245 }
66246
66247 kgdb_restore:
66248 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66249 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66250 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66251 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66252 if (kgdb_info[sstep_cpu].task)
66253 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66254 else
66255 @@ -829,18 +829,18 @@ static void kgdb_unregister_callbacks(void)
66256 static void kgdb_tasklet_bpt(unsigned long ing)
66257 {
66258 kgdb_breakpoint();
66259 - atomic_set(&kgdb_break_tasklet_var, 0);
66260 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66261 }
66262
66263 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66264
66265 void kgdb_schedule_breakpoint(void)
66266 {
66267 - if (atomic_read(&kgdb_break_tasklet_var) ||
66268 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66269 atomic_read(&kgdb_active) != -1 ||
66270 atomic_read(&kgdb_setting_breakpoint))
66271 return;
66272 - atomic_inc(&kgdb_break_tasklet_var);
66273 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66274 tasklet_schedule(&kgdb_tasklet_breakpoint);
66275 }
66276 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66277 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66278 index e2ae734..08a4c5c 100644
66279 --- a/kernel/debug/kdb/kdb_main.c
66280 +++ b/kernel/debug/kdb/kdb_main.c
66281 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
66282 list_for_each_entry(mod, kdb_modules, list) {
66283
66284 kdb_printf("%-20s%8u 0x%p ", mod->name,
66285 - mod->core_size, (void *)mod);
66286 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
66287 #ifdef CONFIG_MODULE_UNLOAD
66288 kdb_printf("%4ld ", module_refcount(mod));
66289 #endif
66290 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
66291 kdb_printf(" (Loading)");
66292 else
66293 kdb_printf(" (Live)");
66294 - kdb_printf(" 0x%p", mod->module_core);
66295 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66296
66297 #ifdef CONFIG_MODULE_UNLOAD
66298 {
66299 diff --git a/kernel/events/core.c b/kernel/events/core.c
66300 index 1b5c081..c375f83 100644
66301 --- a/kernel/events/core.c
66302 +++ b/kernel/events/core.c
66303 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66304 return 0;
66305 }
66306
66307 -static atomic64_t perf_event_id;
66308 +static atomic64_unchecked_t perf_event_id;
66309
66310 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66311 enum event_type_t event_type);
66312 @@ -2581,7 +2581,7 @@ static void __perf_event_read(void *info)
66313
66314 static inline u64 perf_event_count(struct perf_event *event)
66315 {
66316 - return local64_read(&event->count) + atomic64_read(&event->child_count);
66317 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66318 }
66319
66320 static u64 perf_event_read(struct perf_event *event)
66321 @@ -2897,9 +2897,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66322 mutex_lock(&event->child_mutex);
66323 total += perf_event_read(event);
66324 *enabled += event->total_time_enabled +
66325 - atomic64_read(&event->child_total_time_enabled);
66326 + atomic64_read_unchecked(&event->child_total_time_enabled);
66327 *running += event->total_time_running +
66328 - atomic64_read(&event->child_total_time_running);
66329 + atomic64_read_unchecked(&event->child_total_time_running);
66330
66331 list_for_each_entry(child, &event->child_list, child_list) {
66332 total += perf_event_read(child);
66333 @@ -3306,10 +3306,10 @@ void perf_event_update_userpage(struct perf_event *event)
66334 userpg->offset -= local64_read(&event->hw.prev_count);
66335
66336 userpg->time_enabled = enabled +
66337 - atomic64_read(&event->child_total_time_enabled);
66338 + atomic64_read_unchecked(&event->child_total_time_enabled);
66339
66340 userpg->time_running = running +
66341 - atomic64_read(&event->child_total_time_running);
66342 + atomic64_read_unchecked(&event->child_total_time_running);
66343
66344 barrier();
66345 ++userpg->lock;
66346 @@ -3738,11 +3738,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66347 values[n++] = perf_event_count(event);
66348 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66349 values[n++] = enabled +
66350 - atomic64_read(&event->child_total_time_enabled);
66351 + atomic64_read_unchecked(&event->child_total_time_enabled);
66352 }
66353 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66354 values[n++] = running +
66355 - atomic64_read(&event->child_total_time_running);
66356 + atomic64_read_unchecked(&event->child_total_time_running);
66357 }
66358 if (read_format & PERF_FORMAT_ID)
66359 values[n++] = primary_event_id(event);
66360 @@ -4393,12 +4393,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66361 * need to add enough zero bytes after the string to handle
66362 * the 64bit alignment we do later.
66363 */
66364 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66365 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
66366 if (!buf) {
66367 name = strncpy(tmp, "//enomem", sizeof(tmp));
66368 goto got_name;
66369 }
66370 - name = d_path(&file->f_path, buf, PATH_MAX);
66371 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66372 if (IS_ERR(name)) {
66373 name = strncpy(tmp, "//toolong", sizeof(tmp));
66374 goto got_name;
66375 @@ -5765,7 +5765,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66376 event->parent = parent_event;
66377
66378 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66379 - event->id = atomic64_inc_return(&perf_event_id);
66380 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
66381
66382 event->state = PERF_EVENT_STATE_INACTIVE;
66383
66384 @@ -6287,10 +6287,10 @@ static void sync_child_event(struct perf_event *child_event,
66385 /*
66386 * Add back the child's count to the parent's count:
66387 */
66388 - atomic64_add(child_val, &parent_event->child_count);
66389 - atomic64_add(child_event->total_time_enabled,
66390 + atomic64_add_unchecked(child_val, &parent_event->child_count);
66391 + atomic64_add_unchecked(child_event->total_time_enabled,
66392 &parent_event->child_total_time_enabled);
66393 - atomic64_add(child_event->total_time_running,
66394 + atomic64_add_unchecked(child_event->total_time_running,
66395 &parent_event->child_total_time_running);
66396
66397 /*
66398 diff --git a/kernel/exit.c b/kernel/exit.c
66399 index 46c8b14..d868958 100644
66400 --- a/kernel/exit.c
66401 +++ b/kernel/exit.c
66402 @@ -58,6 +58,10 @@
66403 #include <asm/pgtable.h>
66404 #include <asm/mmu_context.h>
66405
66406 +#ifdef CONFIG_GRKERNSEC
66407 +extern rwlock_t grsec_exec_file_lock;
66408 +#endif
66409 +
66410 static void exit_mm(struct task_struct * tsk);
66411
66412 static void __unhash_process(struct task_struct *p, bool group_dead)
66413 @@ -169,6 +173,10 @@ void release_task(struct task_struct * p)
66414 struct task_struct *leader;
66415 int zap_leader;
66416 repeat:
66417 +#ifdef CONFIG_NET
66418 + gr_del_task_from_ip_table(p);
66419 +#endif
66420 +
66421 /* don't need to get the RCU readlock here - the process is dead and
66422 * can't be modifying its own credentials. But shut RCU-lockdep up */
66423 rcu_read_lock();
66424 @@ -381,7 +389,7 @@ int allow_signal(int sig)
66425 * know it'll be handled, so that they don't get converted to
66426 * SIGKILL or just silently dropped.
66427 */
66428 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66429 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66430 recalc_sigpending();
66431 spin_unlock_irq(&current->sighand->siglock);
66432 return 0;
66433 @@ -417,6 +425,17 @@ void daemonize(const char *name, ...)
66434 vsnprintf(current->comm, sizeof(current->comm), name, args);
66435 va_end(args);
66436
66437 +#ifdef CONFIG_GRKERNSEC
66438 + write_lock(&grsec_exec_file_lock);
66439 + if (current->exec_file) {
66440 + fput(current->exec_file);
66441 + current->exec_file = NULL;
66442 + }
66443 + write_unlock(&grsec_exec_file_lock);
66444 +#endif
66445 +
66446 + gr_set_kernel_label(current);
66447 +
66448 /*
66449 * If we were started as result of loading a module, close all of the
66450 * user space pages. We don't need them, and if we didn't close them
66451 @@ -873,6 +892,8 @@ void do_exit(long code)
66452 struct task_struct *tsk = current;
66453 int group_dead;
66454
66455 + set_fs(USER_DS);
66456 +
66457 profile_task_exit(tsk);
66458
66459 WARN_ON(blk_needs_flush_plug(tsk));
66460 @@ -889,7 +910,6 @@ void do_exit(long code)
66461 * mm_release()->clear_child_tid() from writing to a user-controlled
66462 * kernel address.
66463 */
66464 - set_fs(USER_DS);
66465
66466 ptrace_event(PTRACE_EVENT_EXIT, code);
66467
66468 @@ -950,6 +970,9 @@ void do_exit(long code)
66469 tsk->exit_code = code;
66470 taskstats_exit(tsk, group_dead);
66471
66472 + gr_acl_handle_psacct(tsk, code);
66473 + gr_acl_handle_exit();
66474 +
66475 exit_mm(tsk);
66476
66477 if (group_dead)
66478 @@ -1066,7 +1089,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66479 * Take down every thread in the group. This is called by fatal signals
66480 * as well as by sys_exit_group (below).
66481 */
66482 -void
66483 +__noreturn void
66484 do_group_exit(int exit_code)
66485 {
66486 struct signal_struct *sig = current->signal;
66487 diff --git a/kernel/fork.c b/kernel/fork.c
66488 index 26a7a67..a1053f9 100644
66489 --- a/kernel/fork.c
66490 +++ b/kernel/fork.c
66491 @@ -284,7 +284,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66492 *stackend = STACK_END_MAGIC; /* for overflow detection */
66493
66494 #ifdef CONFIG_CC_STACKPROTECTOR
66495 - tsk->stack_canary = get_random_int();
66496 + tsk->stack_canary = pax_get_random_long();
66497 #endif
66498
66499 /*
66500 @@ -308,13 +308,77 @@ out:
66501 }
66502
66503 #ifdef CONFIG_MMU
66504 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
66505 +{
66506 + struct vm_area_struct *tmp;
66507 + unsigned long charge;
66508 + struct mempolicy *pol;
66509 + struct file *file;
66510 +
66511 + charge = 0;
66512 + if (mpnt->vm_flags & VM_ACCOUNT) {
66513 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66514 + if (security_vm_enough_memory(len))
66515 + goto fail_nomem;
66516 + charge = len;
66517 + }
66518 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66519 + if (!tmp)
66520 + goto fail_nomem;
66521 + *tmp = *mpnt;
66522 + tmp->vm_mm = mm;
66523 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66524 + pol = mpol_dup(vma_policy(mpnt));
66525 + if (IS_ERR(pol))
66526 + goto fail_nomem_policy;
66527 + vma_set_policy(tmp, pol);
66528 + if (anon_vma_fork(tmp, mpnt))
66529 + goto fail_nomem_anon_vma_fork;
66530 + tmp->vm_flags &= ~VM_LOCKED;
66531 + tmp->vm_next = tmp->vm_prev = NULL;
66532 + tmp->vm_mirror = NULL;
66533 + file = tmp->vm_file;
66534 + if (file) {
66535 + struct inode *inode = file->f_path.dentry->d_inode;
66536 + struct address_space *mapping = file->f_mapping;
66537 +
66538 + get_file(file);
66539 + if (tmp->vm_flags & VM_DENYWRITE)
66540 + atomic_dec(&inode->i_writecount);
66541 + mutex_lock(&mapping->i_mmap_mutex);
66542 + if (tmp->vm_flags & VM_SHARED)
66543 + mapping->i_mmap_writable++;
66544 + flush_dcache_mmap_lock(mapping);
66545 + /* insert tmp into the share list, just after mpnt */
66546 + vma_prio_tree_add(tmp, mpnt);
66547 + flush_dcache_mmap_unlock(mapping);
66548 + mutex_unlock(&mapping->i_mmap_mutex);
66549 + }
66550 +
66551 + /*
66552 + * Clear hugetlb-related page reserves for children. This only
66553 + * affects MAP_PRIVATE mappings. Faults generated by the child
66554 + * are not guaranteed to succeed, even if read-only
66555 + */
66556 + if (is_vm_hugetlb_page(tmp))
66557 + reset_vma_resv_huge_pages(tmp);
66558 +
66559 + return tmp;
66560 +
66561 +fail_nomem_anon_vma_fork:
66562 + mpol_put(pol);
66563 +fail_nomem_policy:
66564 + kmem_cache_free(vm_area_cachep, tmp);
66565 +fail_nomem:
66566 + vm_unacct_memory(charge);
66567 + return NULL;
66568 +}
66569 +
66570 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66571 {
66572 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66573 struct rb_node **rb_link, *rb_parent;
66574 int retval;
66575 - unsigned long charge;
66576 - struct mempolicy *pol;
66577
66578 down_write(&oldmm->mmap_sem);
66579 flush_cache_dup_mm(oldmm);
66580 @@ -326,8 +390,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66581 mm->locked_vm = 0;
66582 mm->mmap = NULL;
66583 mm->mmap_cache = NULL;
66584 - mm->free_area_cache = oldmm->mmap_base;
66585 - mm->cached_hole_size = ~0UL;
66586 + mm->free_area_cache = oldmm->free_area_cache;
66587 + mm->cached_hole_size = oldmm->cached_hole_size;
66588 mm->map_count = 0;
66589 cpumask_clear(mm_cpumask(mm));
66590 mm->mm_rb = RB_ROOT;
66591 @@ -343,8 +407,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66592
66593 prev = NULL;
66594 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66595 - struct file *file;
66596 -
66597 if (mpnt->vm_flags & VM_DONTCOPY) {
66598 long pages = vma_pages(mpnt);
66599 mm->total_vm -= pages;
66600 @@ -352,53 +414,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66601 -pages);
66602 continue;
66603 }
66604 - charge = 0;
66605 - if (mpnt->vm_flags & VM_ACCOUNT) {
66606 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66607 - if (security_vm_enough_memory(len))
66608 - goto fail_nomem;
66609 - charge = len;
66610 + tmp = dup_vma(mm, mpnt);
66611 + if (!tmp) {
66612 + retval = -ENOMEM;
66613 + goto out;
66614 }
66615 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66616 - if (!tmp)
66617 - goto fail_nomem;
66618 - *tmp = *mpnt;
66619 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66620 - pol = mpol_dup(vma_policy(mpnt));
66621 - retval = PTR_ERR(pol);
66622 - if (IS_ERR(pol))
66623 - goto fail_nomem_policy;
66624 - vma_set_policy(tmp, pol);
66625 - tmp->vm_mm = mm;
66626 - if (anon_vma_fork(tmp, mpnt))
66627 - goto fail_nomem_anon_vma_fork;
66628 - tmp->vm_flags &= ~VM_LOCKED;
66629 - tmp->vm_next = tmp->vm_prev = NULL;
66630 - file = tmp->vm_file;
66631 - if (file) {
66632 - struct inode *inode = file->f_path.dentry->d_inode;
66633 - struct address_space *mapping = file->f_mapping;
66634 -
66635 - get_file(file);
66636 - if (tmp->vm_flags & VM_DENYWRITE)
66637 - atomic_dec(&inode->i_writecount);
66638 - mutex_lock(&mapping->i_mmap_mutex);
66639 - if (tmp->vm_flags & VM_SHARED)
66640 - mapping->i_mmap_writable++;
66641 - flush_dcache_mmap_lock(mapping);
66642 - /* insert tmp into the share list, just after mpnt */
66643 - vma_prio_tree_add(tmp, mpnt);
66644 - flush_dcache_mmap_unlock(mapping);
66645 - mutex_unlock(&mapping->i_mmap_mutex);
66646 - }
66647 -
66648 - /*
66649 - * Clear hugetlb-related page reserves for children. This only
66650 - * affects MAP_PRIVATE mappings. Faults generated by the child
66651 - * are not guaranteed to succeed, even if read-only
66652 - */
66653 - if (is_vm_hugetlb_page(tmp))
66654 - reset_vma_resv_huge_pages(tmp);
66655
66656 /*
66657 * Link in the new vma and copy the page table entries.
66658 @@ -421,6 +441,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66659 if (retval)
66660 goto out;
66661 }
66662 +
66663 +#ifdef CONFIG_PAX_SEGMEXEC
66664 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66665 + struct vm_area_struct *mpnt_m;
66666 +
66667 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66668 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66669 +
66670 + if (!mpnt->vm_mirror)
66671 + continue;
66672 +
66673 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66674 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66675 + mpnt->vm_mirror = mpnt_m;
66676 + } else {
66677 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66678 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66679 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66680 + mpnt->vm_mirror->vm_mirror = mpnt;
66681 + }
66682 + }
66683 + BUG_ON(mpnt_m);
66684 + }
66685 +#endif
66686 +
66687 /* a new mm has just been created */
66688 arch_dup_mmap(oldmm, mm);
66689 retval = 0;
66690 @@ -429,14 +474,6 @@ out:
66691 flush_tlb_mm(oldmm);
66692 up_write(&oldmm->mmap_sem);
66693 return retval;
66694 -fail_nomem_anon_vma_fork:
66695 - mpol_put(pol);
66696 -fail_nomem_policy:
66697 - kmem_cache_free(vm_area_cachep, tmp);
66698 -fail_nomem:
66699 - retval = -ENOMEM;
66700 - vm_unacct_memory(charge);
66701 - goto out;
66702 }
66703
66704 static inline int mm_alloc_pgd(struct mm_struct *mm)
66705 @@ -658,8 +695,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66706 return ERR_PTR(err);
66707
66708 mm = get_task_mm(task);
66709 - if (mm && mm != current->mm &&
66710 - !ptrace_may_access(task, mode)) {
66711 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66712 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66713 mmput(mm);
66714 mm = ERR_PTR(-EACCES);
66715 }
66716 @@ -881,13 +918,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66717 spin_unlock(&fs->lock);
66718 return -EAGAIN;
66719 }
66720 - fs->users++;
66721 + atomic_inc(&fs->users);
66722 spin_unlock(&fs->lock);
66723 return 0;
66724 }
66725 tsk->fs = copy_fs_struct(fs);
66726 if (!tsk->fs)
66727 return -ENOMEM;
66728 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66729 return 0;
66730 }
66731
66732 @@ -1151,6 +1189,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66733 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66734 #endif
66735 retval = -EAGAIN;
66736 +
66737 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66738 +
66739 if (atomic_read(&p->real_cred->user->processes) >=
66740 task_rlimit(p, RLIMIT_NPROC)) {
66741 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66742 @@ -1306,6 +1347,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66743 if (clone_flags & CLONE_THREAD)
66744 p->tgid = current->tgid;
66745
66746 + gr_copy_label(p);
66747 +
66748 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
66749 /*
66750 * Clear TID on mm_release()?
66751 @@ -1472,6 +1515,8 @@ bad_fork_cleanup_count:
66752 bad_fork_free:
66753 free_task(p);
66754 fork_out:
66755 + gr_log_forkfail(retval);
66756 +
66757 return ERR_PTR(retval);
66758 }
66759
66760 @@ -1572,6 +1617,8 @@ long do_fork(unsigned long clone_flags,
66761 if (clone_flags & CLONE_PARENT_SETTID)
66762 put_user(nr, parent_tidptr);
66763
66764 + gr_handle_brute_check();
66765 +
66766 if (clone_flags & CLONE_VFORK) {
66767 p->vfork_done = &vfork;
66768 init_completion(&vfork);
66769 @@ -1670,7 +1717,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66770 return 0;
66771
66772 /* don't need lock here; in the worst case we'll do useless copy */
66773 - if (fs->users == 1)
66774 + if (atomic_read(&fs->users) == 1)
66775 return 0;
66776
66777 *new_fsp = copy_fs_struct(fs);
66778 @@ -1759,7 +1806,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66779 fs = current->fs;
66780 spin_lock(&fs->lock);
66781 current->fs = new_fs;
66782 - if (--fs->users)
66783 + gr_set_chroot_entries(current, &current->fs->root);
66784 + if (atomic_dec_return(&fs->users))
66785 new_fs = NULL;
66786 else
66787 new_fs = fs;
66788 diff --git a/kernel/futex.c b/kernel/futex.c
66789 index 866c9d5..5c5f828 100644
66790 --- a/kernel/futex.c
66791 +++ b/kernel/futex.c
66792 @@ -54,6 +54,7 @@
66793 #include <linux/mount.h>
66794 #include <linux/pagemap.h>
66795 #include <linux/syscalls.h>
66796 +#include <linux/ptrace.h>
66797 #include <linux/signal.h>
66798 #include <linux/export.h>
66799 #include <linux/magic.h>
66800 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66801 struct page *page, *page_head;
66802 int err, ro = 0;
66803
66804 +#ifdef CONFIG_PAX_SEGMEXEC
66805 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66806 + return -EFAULT;
66807 +#endif
66808 +
66809 /*
66810 * The futex address must be "naturally" aligned.
66811 */
66812 @@ -2721,6 +2727,7 @@ static int __init futex_init(void)
66813 {
66814 u32 curval;
66815 int i;
66816 + mm_segment_t oldfs;
66817
66818 /*
66819 * This will fail and we want it. Some arch implementations do
66820 @@ -2732,8 +2739,11 @@ static int __init futex_init(void)
66821 * implementation, the non-functional ones will return
66822 * -ENOSYS.
66823 */
66824 + oldfs = get_fs();
66825 + set_fs(USER_DS);
66826 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66827 futex_cmpxchg_enabled = 1;
66828 + set_fs(oldfs);
66829
66830 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66831 plist_head_init(&futex_queues[i].chain);
66832 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66833 index 9b22d03..6295b62 100644
66834 --- a/kernel/gcov/base.c
66835 +++ b/kernel/gcov/base.c
66836 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
66837 }
66838
66839 #ifdef CONFIG_MODULES
66840 -static inline int within(void *addr, void *start, unsigned long size)
66841 -{
66842 - return ((addr >= start) && (addr < start + size));
66843 -}
66844 -
66845 /* Update list and generate events when modules are unloaded. */
66846 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66847 void *data)
66848 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66849 prev = NULL;
66850 /* Remove entries located in module from linked list. */
66851 for (info = gcov_info_head; info; info = info->next) {
66852 - if (within(info, mod->module_core, mod->core_size)) {
66853 + if (within_module_core_rw((unsigned long)info, mod)) {
66854 if (prev)
66855 prev->next = info->next;
66856 else
66857 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66858 index ae34bf5..4e2f3d0 100644
66859 --- a/kernel/hrtimer.c
66860 +++ b/kernel/hrtimer.c
66861 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
66862 local_irq_restore(flags);
66863 }
66864
66865 -static void run_hrtimer_softirq(struct softirq_action *h)
66866 +static void run_hrtimer_softirq(void)
66867 {
66868 hrtimer_peek_ahead_timers();
66869 }
66870 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66871 index 01d3b70..9e4d098 100644
66872 --- a/kernel/jump_label.c
66873 +++ b/kernel/jump_label.c
66874 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66875
66876 size = (((unsigned long)stop - (unsigned long)start)
66877 / sizeof(struct jump_entry));
66878 + pax_open_kernel();
66879 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66880 + pax_close_kernel();
66881 }
66882
66883 static void jump_label_update(struct jump_label_key *key, int enable);
66884 @@ -340,10 +342,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66885 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66886 struct jump_entry *iter;
66887
66888 + pax_open_kernel();
66889 for (iter = iter_start; iter < iter_stop; iter++) {
66890 if (within_module_init(iter->code, mod))
66891 iter->code = 0;
66892 }
66893 + pax_close_kernel();
66894 }
66895
66896 static int
66897 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66898 index 079f1d3..a407562 100644
66899 --- a/kernel/kallsyms.c
66900 +++ b/kernel/kallsyms.c
66901 @@ -11,6 +11,9 @@
66902 * Changed the compression method from stem compression to "table lookup"
66903 * compression (see scripts/kallsyms.c for a more complete description)
66904 */
66905 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66906 +#define __INCLUDED_BY_HIDESYM 1
66907 +#endif
66908 #include <linux/kallsyms.h>
66909 #include <linux/module.h>
66910 #include <linux/init.h>
66911 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66912
66913 static inline int is_kernel_inittext(unsigned long addr)
66914 {
66915 + if (system_state != SYSTEM_BOOTING)
66916 + return 0;
66917 +
66918 if (addr >= (unsigned long)_sinittext
66919 && addr <= (unsigned long)_einittext)
66920 return 1;
66921 return 0;
66922 }
66923
66924 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66925 +#ifdef CONFIG_MODULES
66926 +static inline int is_module_text(unsigned long addr)
66927 +{
66928 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66929 + return 1;
66930 +
66931 + addr = ktla_ktva(addr);
66932 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66933 +}
66934 +#else
66935 +static inline int is_module_text(unsigned long addr)
66936 +{
66937 + return 0;
66938 +}
66939 +#endif
66940 +#endif
66941 +
66942 static inline int is_kernel_text(unsigned long addr)
66943 {
66944 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66945 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66946
66947 static inline int is_kernel(unsigned long addr)
66948 {
66949 +
66950 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66951 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
66952 + return 1;
66953 +
66954 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66955 +#else
66956 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66957 +#endif
66958 +
66959 return 1;
66960 return in_gate_area_no_mm(addr);
66961 }
66962
66963 static int is_ksym_addr(unsigned long addr)
66964 {
66965 +
66966 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66967 + if (is_module_text(addr))
66968 + return 0;
66969 +#endif
66970 +
66971 if (all_var)
66972 return is_kernel(addr);
66973
66974 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66975
66976 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66977 {
66978 - iter->name[0] = '\0';
66979 iter->nameoff = get_symbol_offset(new_pos);
66980 iter->pos = new_pos;
66981 }
66982 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
66983 {
66984 struct kallsym_iter *iter = m->private;
66985
66986 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66987 + if (current_uid())
66988 + return 0;
66989 +#endif
66990 +
66991 /* Some debugging symbols have no name. Ignore them. */
66992 if (!iter->name[0])
66993 return 0;
66994 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66995 struct kallsym_iter *iter;
66996 int ret;
66997
66998 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66999 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67000 if (!iter)
67001 return -ENOMEM;
67002 reset_iter(iter, 0);
67003 diff --git a/kernel/kexec.c b/kernel/kexec.c
67004 index 7b08867..3bac516 100644
67005 --- a/kernel/kexec.c
67006 +++ b/kernel/kexec.c
67007 @@ -1047,7 +1047,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67008 unsigned long flags)
67009 {
67010 struct compat_kexec_segment in;
67011 - struct kexec_segment out, __user *ksegments;
67012 + struct kexec_segment out;
67013 + struct kexec_segment __user *ksegments;
67014 unsigned long i, result;
67015
67016 /* Don't allow clients that don't understand the native
67017 diff --git a/kernel/kmod.c b/kernel/kmod.c
67018 index a3a46cb..f2e42f8 100644
67019 --- a/kernel/kmod.c
67020 +++ b/kernel/kmod.c
67021 @@ -75,13 +75,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
67022 * If module auto-loading support is disabled then this function
67023 * becomes a no-operation.
67024 */
67025 -int __request_module(bool wait, const char *fmt, ...)
67026 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67027 {
67028 - va_list args;
67029 char module_name[MODULE_NAME_LEN];
67030 unsigned int max_modprobes;
67031 int ret;
67032 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
67033 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
67034 static char *envp[] = { "HOME=/",
67035 "TERM=linux",
67036 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
67037 @@ -90,9 +89,7 @@ int __request_module(bool wait, const char *fmt, ...)
67038 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67039 static int kmod_loop_msg;
67040
67041 - va_start(args, fmt);
67042 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67043 - va_end(args);
67044 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67045 if (ret >= MODULE_NAME_LEN)
67046 return -ENAMETOOLONG;
67047
67048 @@ -100,6 +97,20 @@ int __request_module(bool wait, const char *fmt, ...)
67049 if (ret)
67050 return ret;
67051
67052 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67053 + if (!current_uid()) {
67054 + /* hack to workaround consolekit/udisks stupidity */
67055 + read_lock(&tasklist_lock);
67056 + if (!strcmp(current->comm, "mount") &&
67057 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67058 + read_unlock(&tasklist_lock);
67059 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67060 + return -EPERM;
67061 + }
67062 + read_unlock(&tasklist_lock);
67063 + }
67064 +#endif
67065 +
67066 /* If modprobe needs a service that is in a module, we get a recursive
67067 * loop. Limit the number of running kmod threads to max_threads/2 or
67068 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67069 @@ -135,6 +146,47 @@ int __request_module(bool wait, const char *fmt, ...)
67070 atomic_dec(&kmod_concurrent);
67071 return ret;
67072 }
67073 +
67074 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67075 +{
67076 + va_list args;
67077 + int ret;
67078 +
67079 + va_start(args, fmt);
67080 + ret = ____request_module(wait, module_param, fmt, args);
67081 + va_end(args);
67082 +
67083 + return ret;
67084 +}
67085 +
67086 +int __request_module(bool wait, const char *fmt, ...)
67087 +{
67088 + va_list args;
67089 + int ret;
67090 +
67091 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67092 + if (current_uid()) {
67093 + char module_param[MODULE_NAME_LEN];
67094 +
67095 + memset(module_param, 0, sizeof(module_param));
67096 +
67097 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67098 +
67099 + va_start(args, fmt);
67100 + ret = ____request_module(wait, module_param, fmt, args);
67101 + va_end(args);
67102 +
67103 + return ret;
67104 + }
67105 +#endif
67106 +
67107 + va_start(args, fmt);
67108 + ret = ____request_module(wait, NULL, fmt, args);
67109 + va_end(args);
67110 +
67111 + return ret;
67112 +}
67113 +
67114 EXPORT_SYMBOL(__request_module);
67115 #endif /* CONFIG_MODULES */
67116
67117 @@ -224,7 +276,7 @@ static int wait_for_helper(void *data)
67118 *
67119 * Thus the __user pointer cast is valid here.
67120 */
67121 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67122 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67123
67124 /*
67125 * If ret is 0, either ____call_usermodehelper failed and the
67126 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67127 index c62b854..cb67968 100644
67128 --- a/kernel/kprobes.c
67129 +++ b/kernel/kprobes.c
67130 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67131 * kernel image and loaded module images reside. This is required
67132 * so x86_64 can correctly handle the %rip-relative fixups.
67133 */
67134 - kip->insns = module_alloc(PAGE_SIZE);
67135 + kip->insns = module_alloc_exec(PAGE_SIZE);
67136 if (!kip->insns) {
67137 kfree(kip);
67138 return NULL;
67139 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67140 */
67141 if (!list_is_singular(&kip->list)) {
67142 list_del(&kip->list);
67143 - module_free(NULL, kip->insns);
67144 + module_free_exec(NULL, kip->insns);
67145 kfree(kip);
67146 }
67147 return 1;
67148 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67149 {
67150 int i, err = 0;
67151 unsigned long offset = 0, size = 0;
67152 - char *modname, namebuf[128];
67153 + char *modname, namebuf[KSYM_NAME_LEN];
67154 const char *symbol_name;
67155 void *addr;
67156 struct kprobe_blackpoint *kb;
67157 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67158 const char *sym = NULL;
67159 unsigned int i = *(loff_t *) v;
67160 unsigned long offset = 0;
67161 - char *modname, namebuf[128];
67162 + char *modname, namebuf[KSYM_NAME_LEN];
67163
67164 head = &kprobe_table[i];
67165 preempt_disable();
67166 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67167 index 4e316e1..5501eef 100644
67168 --- a/kernel/ksysfs.c
67169 +++ b/kernel/ksysfs.c
67170 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67171 {
67172 if (count+1 > UEVENT_HELPER_PATH_LEN)
67173 return -ENOENT;
67174 + if (!capable(CAP_SYS_ADMIN))
67175 + return -EPERM;
67176 memcpy(uevent_helper, buf, count);
67177 uevent_helper[count] = '\0';
67178 if (count && uevent_helper[count-1] == '\n')
67179 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67180 index 8889f7d..95319b7 100644
67181 --- a/kernel/lockdep.c
67182 +++ b/kernel/lockdep.c
67183 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
67184 end = (unsigned long) &_end,
67185 addr = (unsigned long) obj;
67186
67187 +#ifdef CONFIG_PAX_KERNEXEC
67188 + start = ktla_ktva(start);
67189 +#endif
67190 +
67191 /*
67192 * static variable?
67193 */
67194 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67195 if (!static_obj(lock->key)) {
67196 debug_locks_off();
67197 printk("INFO: trying to register non-static key.\n");
67198 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67199 printk("the code is fine but needs lockdep annotation.\n");
67200 printk("turning off the locking correctness validator.\n");
67201 dump_stack();
67202 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67203 if (!class)
67204 return 0;
67205 }
67206 - atomic_inc((atomic_t *)&class->ops);
67207 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67208 if (very_verbose(class)) {
67209 printk("\nacquire class [%p] %s", class->key, class->name);
67210 if (class->name_version > 1)
67211 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67212 index 91c32a0..b2c71c5 100644
67213 --- a/kernel/lockdep_proc.c
67214 +++ b/kernel/lockdep_proc.c
67215 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67216
67217 static void print_name(struct seq_file *m, struct lock_class *class)
67218 {
67219 - char str[128];
67220 + char str[KSYM_NAME_LEN];
67221 const char *name = class->name;
67222
67223 if (!name) {
67224 diff --git a/kernel/module.c b/kernel/module.c
67225 index 3d56b6f..2a22bd0 100644
67226 --- a/kernel/module.c
67227 +++ b/kernel/module.c
67228 @@ -58,6 +58,7 @@
67229 #include <linux/jump_label.h>
67230 #include <linux/pfn.h>
67231 #include <linux/bsearch.h>
67232 +#include <linux/grsecurity.h>
67233
67234 #define CREATE_TRACE_POINTS
67235 #include <trace/events/module.h>
67236 @@ -113,7 +114,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67237
67238 /* Bounds of module allocation, for speeding __module_address.
67239 * Protected by module_mutex. */
67240 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67241 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67242 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67243
67244 int register_module_notifier(struct notifier_block * nb)
67245 {
67246 @@ -277,7 +279,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67247 return true;
67248
67249 list_for_each_entry_rcu(mod, &modules, list) {
67250 - struct symsearch arr[] = {
67251 + struct symsearch modarr[] = {
67252 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67253 NOT_GPL_ONLY, false },
67254 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67255 @@ -299,7 +301,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67256 #endif
67257 };
67258
67259 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67260 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67261 return true;
67262 }
67263 return false;
67264 @@ -431,7 +433,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67265 static int percpu_modalloc(struct module *mod,
67266 unsigned long size, unsigned long align)
67267 {
67268 - if (align > PAGE_SIZE) {
67269 + if (align-1 >= PAGE_SIZE) {
67270 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67271 mod->name, align, PAGE_SIZE);
67272 align = PAGE_SIZE;
67273 @@ -1001,7 +1003,7 @@ struct module_attribute module_uevent =
67274 static ssize_t show_coresize(struct module_attribute *mattr,
67275 struct module_kobject *mk, char *buffer)
67276 {
67277 - return sprintf(buffer, "%u\n", mk->mod->core_size);
67278 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
67279 }
67280
67281 static struct module_attribute modinfo_coresize =
67282 @@ -1010,7 +1012,7 @@ static struct module_attribute modinfo_coresize =
67283 static ssize_t show_initsize(struct module_attribute *mattr,
67284 struct module_kobject *mk, char *buffer)
67285 {
67286 - return sprintf(buffer, "%u\n", mk->mod->init_size);
67287 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
67288 }
67289
67290 static struct module_attribute modinfo_initsize =
67291 @@ -1224,7 +1226,7 @@ resolve_symbol_wait(struct module *mod,
67292 */
67293 #ifdef CONFIG_SYSFS
67294
67295 -#ifdef CONFIG_KALLSYMS
67296 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67297 static inline bool sect_empty(const Elf_Shdr *sect)
67298 {
67299 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67300 @@ -1690,21 +1692,21 @@ static void set_section_ro_nx(void *base,
67301
67302 static void unset_module_core_ro_nx(struct module *mod)
67303 {
67304 - set_page_attributes(mod->module_core + mod->core_text_size,
67305 - mod->module_core + mod->core_size,
67306 + set_page_attributes(mod->module_core_rw,
67307 + mod->module_core_rw + mod->core_size_rw,
67308 set_memory_x);
67309 - set_page_attributes(mod->module_core,
67310 - mod->module_core + mod->core_ro_size,
67311 + set_page_attributes(mod->module_core_rx,
67312 + mod->module_core_rx + mod->core_size_rx,
67313 set_memory_rw);
67314 }
67315
67316 static void unset_module_init_ro_nx(struct module *mod)
67317 {
67318 - set_page_attributes(mod->module_init + mod->init_text_size,
67319 - mod->module_init + mod->init_size,
67320 + set_page_attributes(mod->module_init_rw,
67321 + mod->module_init_rw + mod->init_size_rw,
67322 set_memory_x);
67323 - set_page_attributes(mod->module_init,
67324 - mod->module_init + mod->init_ro_size,
67325 + set_page_attributes(mod->module_init_rx,
67326 + mod->module_init_rx + mod->init_size_rx,
67327 set_memory_rw);
67328 }
67329
67330 @@ -1715,14 +1717,14 @@ void set_all_modules_text_rw(void)
67331
67332 mutex_lock(&module_mutex);
67333 list_for_each_entry_rcu(mod, &modules, list) {
67334 - if ((mod->module_core) && (mod->core_text_size)) {
67335 - set_page_attributes(mod->module_core,
67336 - mod->module_core + mod->core_text_size,
67337 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67338 + set_page_attributes(mod->module_core_rx,
67339 + mod->module_core_rx + mod->core_size_rx,
67340 set_memory_rw);
67341 }
67342 - if ((mod->module_init) && (mod->init_text_size)) {
67343 - set_page_attributes(mod->module_init,
67344 - mod->module_init + mod->init_text_size,
67345 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67346 + set_page_attributes(mod->module_init_rx,
67347 + mod->module_init_rx + mod->init_size_rx,
67348 set_memory_rw);
67349 }
67350 }
67351 @@ -1736,14 +1738,14 @@ void set_all_modules_text_ro(void)
67352
67353 mutex_lock(&module_mutex);
67354 list_for_each_entry_rcu(mod, &modules, list) {
67355 - if ((mod->module_core) && (mod->core_text_size)) {
67356 - set_page_attributes(mod->module_core,
67357 - mod->module_core + mod->core_text_size,
67358 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67359 + set_page_attributes(mod->module_core_rx,
67360 + mod->module_core_rx + mod->core_size_rx,
67361 set_memory_ro);
67362 }
67363 - if ((mod->module_init) && (mod->init_text_size)) {
67364 - set_page_attributes(mod->module_init,
67365 - mod->module_init + mod->init_text_size,
67366 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67367 + set_page_attributes(mod->module_init_rx,
67368 + mod->module_init_rx + mod->init_size_rx,
67369 set_memory_ro);
67370 }
67371 }
67372 @@ -1789,16 +1791,19 @@ static void free_module(struct module *mod)
67373
67374 /* This may be NULL, but that's OK */
67375 unset_module_init_ro_nx(mod);
67376 - module_free(mod, mod->module_init);
67377 + module_free(mod, mod->module_init_rw);
67378 + module_free_exec(mod, mod->module_init_rx);
67379 kfree(mod->args);
67380 percpu_modfree(mod);
67381
67382 /* Free lock-classes: */
67383 - lockdep_free_key_range(mod->module_core, mod->core_size);
67384 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67385 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67386
67387 /* Finally, free the core (containing the module structure) */
67388 unset_module_core_ro_nx(mod);
67389 - module_free(mod, mod->module_core);
67390 + module_free_exec(mod, mod->module_core_rx);
67391 + module_free(mod, mod->module_core_rw);
67392
67393 #ifdef CONFIG_MPU
67394 update_protections(current->mm);
67395 @@ -1867,10 +1872,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67396 unsigned int i;
67397 int ret = 0;
67398 const struct kernel_symbol *ksym;
67399 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67400 + int is_fs_load = 0;
67401 + int register_filesystem_found = 0;
67402 + char *p;
67403 +
67404 + p = strstr(mod->args, "grsec_modharden_fs");
67405 + if (p) {
67406 + char *endptr = p + strlen("grsec_modharden_fs");
67407 + /* copy \0 as well */
67408 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67409 + is_fs_load = 1;
67410 + }
67411 +#endif
67412
67413 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67414 const char *name = info->strtab + sym[i].st_name;
67415
67416 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67417 + /* it's a real shame this will never get ripped and copied
67418 + upstream! ;(
67419 + */
67420 + if (is_fs_load && !strcmp(name, "register_filesystem"))
67421 + register_filesystem_found = 1;
67422 +#endif
67423 +
67424 switch (sym[i].st_shndx) {
67425 case SHN_COMMON:
67426 /* We compiled with -fno-common. These are not
67427 @@ -1891,7 +1917,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67428 ksym = resolve_symbol_wait(mod, info, name);
67429 /* Ok if resolved. */
67430 if (ksym && !IS_ERR(ksym)) {
67431 + pax_open_kernel();
67432 sym[i].st_value = ksym->value;
67433 + pax_close_kernel();
67434 break;
67435 }
67436
67437 @@ -1910,11 +1938,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67438 secbase = (unsigned long)mod_percpu(mod);
67439 else
67440 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67441 + pax_open_kernel();
67442 sym[i].st_value += secbase;
67443 + pax_close_kernel();
67444 break;
67445 }
67446 }
67447
67448 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67449 + if (is_fs_load && !register_filesystem_found) {
67450 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67451 + ret = -EPERM;
67452 + }
67453 +#endif
67454 +
67455 return ret;
67456 }
67457
67458 @@ -2018,22 +2055,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67459 || s->sh_entsize != ~0UL
67460 || strstarts(sname, ".init"))
67461 continue;
67462 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67463 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67464 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67465 + else
67466 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67467 pr_debug("\t%s\n", sname);
67468 }
67469 - switch (m) {
67470 - case 0: /* executable */
67471 - mod->core_size = debug_align(mod->core_size);
67472 - mod->core_text_size = mod->core_size;
67473 - break;
67474 - case 1: /* RO: text and ro-data */
67475 - mod->core_size = debug_align(mod->core_size);
67476 - mod->core_ro_size = mod->core_size;
67477 - break;
67478 - case 3: /* whole core */
67479 - mod->core_size = debug_align(mod->core_size);
67480 - break;
67481 - }
67482 }
67483
67484 pr_debug("Init section allocation order:\n");
67485 @@ -2047,23 +2074,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67486 || s->sh_entsize != ~0UL
67487 || !strstarts(sname, ".init"))
67488 continue;
67489 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67490 - | INIT_OFFSET_MASK);
67491 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67492 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67493 + else
67494 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67495 + s->sh_entsize |= INIT_OFFSET_MASK;
67496 pr_debug("\t%s\n", sname);
67497 }
67498 - switch (m) {
67499 - case 0: /* executable */
67500 - mod->init_size = debug_align(mod->init_size);
67501 - mod->init_text_size = mod->init_size;
67502 - break;
67503 - case 1: /* RO: text and ro-data */
67504 - mod->init_size = debug_align(mod->init_size);
67505 - mod->init_ro_size = mod->init_size;
67506 - break;
67507 - case 3: /* whole init */
67508 - mod->init_size = debug_align(mod->init_size);
67509 - break;
67510 - }
67511 }
67512 }
67513
67514 @@ -2235,7 +2252,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67515
67516 /* Put symbol section at end of init part of module. */
67517 symsect->sh_flags |= SHF_ALLOC;
67518 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67519 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67520 info->index.sym) | INIT_OFFSET_MASK;
67521 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67522
67523 @@ -2250,13 +2267,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67524 }
67525
67526 /* Append room for core symbols at end of core part. */
67527 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67528 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67529 - mod->core_size += strtab_size;
67530 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67531 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67532 + mod->core_size_rx += strtab_size;
67533
67534 /* Put string table section at end of init part of module. */
67535 strsect->sh_flags |= SHF_ALLOC;
67536 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67537 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67538 info->index.str) | INIT_OFFSET_MASK;
67539 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67540 }
67541 @@ -2274,12 +2291,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67542 /* Make sure we get permanent strtab: don't use info->strtab. */
67543 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67544
67545 + pax_open_kernel();
67546 +
67547 /* Set types up while we still have access to sections. */
67548 for (i = 0; i < mod->num_symtab; i++)
67549 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67550
67551 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67552 - mod->core_strtab = s = mod->module_core + info->stroffs;
67553 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67554 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67555 src = mod->symtab;
67556 *dst = *src;
67557 *s++ = 0;
67558 @@ -2292,6 +2311,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67559 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67560 }
67561 mod->core_num_syms = ndst;
67562 +
67563 + pax_close_kernel();
67564 }
67565 #else
67566 static inline void layout_symtab(struct module *mod, struct load_info *info)
67567 @@ -2325,17 +2346,33 @@ void * __weak module_alloc(unsigned long size)
67568 return size == 0 ? NULL : vmalloc_exec(size);
67569 }
67570
67571 -static void *module_alloc_update_bounds(unsigned long size)
67572 +static void *module_alloc_update_bounds_rw(unsigned long size)
67573 {
67574 void *ret = module_alloc(size);
67575
67576 if (ret) {
67577 mutex_lock(&module_mutex);
67578 /* Update module bounds. */
67579 - if ((unsigned long)ret < module_addr_min)
67580 - module_addr_min = (unsigned long)ret;
67581 - if ((unsigned long)ret + size > module_addr_max)
67582 - module_addr_max = (unsigned long)ret + size;
67583 + if ((unsigned long)ret < module_addr_min_rw)
67584 + module_addr_min_rw = (unsigned long)ret;
67585 + if ((unsigned long)ret + size > module_addr_max_rw)
67586 + module_addr_max_rw = (unsigned long)ret + size;
67587 + mutex_unlock(&module_mutex);
67588 + }
67589 + return ret;
67590 +}
67591 +
67592 +static void *module_alloc_update_bounds_rx(unsigned long size)
67593 +{
67594 + void *ret = module_alloc_exec(size);
67595 +
67596 + if (ret) {
67597 + mutex_lock(&module_mutex);
67598 + /* Update module bounds. */
67599 + if ((unsigned long)ret < module_addr_min_rx)
67600 + module_addr_min_rx = (unsigned long)ret;
67601 + if ((unsigned long)ret + size > module_addr_max_rx)
67602 + module_addr_max_rx = (unsigned long)ret + size;
67603 mutex_unlock(&module_mutex);
67604 }
67605 return ret;
67606 @@ -2512,8 +2549,14 @@ static struct module *setup_load_info(struct load_info *info)
67607 static int check_modinfo(struct module *mod, struct load_info *info)
67608 {
67609 const char *modmagic = get_modinfo(info, "vermagic");
67610 + const char *license = get_modinfo(info, "license");
67611 int err;
67612
67613 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67614 + if (!license || !license_is_gpl_compatible(license))
67615 + return -ENOEXEC;
67616 +#endif
67617 +
67618 /* This is allowed: modprobe --force will invalidate it. */
67619 if (!modmagic) {
67620 err = try_to_force_load(mod, "bad vermagic");
67621 @@ -2536,7 +2579,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67622 }
67623
67624 /* Set up license info based on the info section */
67625 - set_license(mod, get_modinfo(info, "license"));
67626 + set_license(mod, license);
67627
67628 return 0;
67629 }
67630 @@ -2630,7 +2673,7 @@ static int move_module(struct module *mod, struct load_info *info)
67631 void *ptr;
67632
67633 /* Do the allocs. */
67634 - ptr = module_alloc_update_bounds(mod->core_size);
67635 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67636 /*
67637 * The pointer to this block is stored in the module structure
67638 * which is inside the block. Just mark it as not being a
67639 @@ -2640,23 +2683,50 @@ static int move_module(struct module *mod, struct load_info *info)
67640 if (!ptr)
67641 return -ENOMEM;
67642
67643 - memset(ptr, 0, mod->core_size);
67644 - mod->module_core = ptr;
67645 + memset(ptr, 0, mod->core_size_rw);
67646 + mod->module_core_rw = ptr;
67647
67648 - ptr = module_alloc_update_bounds(mod->init_size);
67649 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67650 /*
67651 * The pointer to this block is stored in the module structure
67652 * which is inside the block. This block doesn't need to be
67653 * scanned as it contains data and code that will be freed
67654 * after the module is initialized.
67655 */
67656 - kmemleak_ignore(ptr);
67657 - if (!ptr && mod->init_size) {
67658 - module_free(mod, mod->module_core);
67659 + kmemleak_not_leak(ptr);
67660 + if (!ptr && mod->init_size_rw) {
67661 + module_free(mod, mod->module_core_rw);
67662 return -ENOMEM;
67663 }
67664 - memset(ptr, 0, mod->init_size);
67665 - mod->module_init = ptr;
67666 + memset(ptr, 0, mod->init_size_rw);
67667 + mod->module_init_rw = ptr;
67668 +
67669 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67670 + kmemleak_not_leak(ptr);
67671 + if (!ptr) {
67672 + module_free(mod, mod->module_init_rw);
67673 + module_free(mod, mod->module_core_rw);
67674 + return -ENOMEM;
67675 + }
67676 +
67677 + pax_open_kernel();
67678 + memset(ptr, 0, mod->core_size_rx);
67679 + pax_close_kernel();
67680 + mod->module_core_rx = ptr;
67681 +
67682 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67683 + kmemleak_not_leak(ptr);
67684 + if (!ptr && mod->init_size_rx) {
67685 + module_free_exec(mod, mod->module_core_rx);
67686 + module_free(mod, mod->module_init_rw);
67687 + module_free(mod, mod->module_core_rw);
67688 + return -ENOMEM;
67689 + }
67690 +
67691 + pax_open_kernel();
67692 + memset(ptr, 0, mod->init_size_rx);
67693 + pax_close_kernel();
67694 + mod->module_init_rx = ptr;
67695
67696 /* Transfer each section which specifies SHF_ALLOC */
67697 pr_debug("final section addresses:\n");
67698 @@ -2667,16 +2737,45 @@ static int move_module(struct module *mod, struct load_info *info)
67699 if (!(shdr->sh_flags & SHF_ALLOC))
67700 continue;
67701
67702 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
67703 - dest = mod->module_init
67704 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67705 - else
67706 - dest = mod->module_core + shdr->sh_entsize;
67707 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67708 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67709 + dest = mod->module_init_rw
67710 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67711 + else
67712 + dest = mod->module_init_rx
67713 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67714 + } else {
67715 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67716 + dest = mod->module_core_rw + shdr->sh_entsize;
67717 + else
67718 + dest = mod->module_core_rx + shdr->sh_entsize;
67719 + }
67720 +
67721 + if (shdr->sh_type != SHT_NOBITS) {
67722 +
67723 +#ifdef CONFIG_PAX_KERNEXEC
67724 +#ifdef CONFIG_X86_64
67725 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67726 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67727 +#endif
67728 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67729 + pax_open_kernel();
67730 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67731 + pax_close_kernel();
67732 + } else
67733 +#endif
67734
67735 - if (shdr->sh_type != SHT_NOBITS)
67736 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67737 + }
67738 /* Update sh_addr to point to copy in image. */
67739 - shdr->sh_addr = (unsigned long)dest;
67740 +
67741 +#ifdef CONFIG_PAX_KERNEXEC
67742 + if (shdr->sh_flags & SHF_EXECINSTR)
67743 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
67744 + else
67745 +#endif
67746 +
67747 + shdr->sh_addr = (unsigned long)dest;
67748 pr_debug("\t0x%lx %s\n",
67749 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67750 }
67751 @@ -2727,12 +2826,12 @@ static void flush_module_icache(const struct module *mod)
67752 * Do it before processing of module parameters, so the module
67753 * can provide parameter accessor functions of its own.
67754 */
67755 - if (mod->module_init)
67756 - flush_icache_range((unsigned long)mod->module_init,
67757 - (unsigned long)mod->module_init
67758 - + mod->init_size);
67759 - flush_icache_range((unsigned long)mod->module_core,
67760 - (unsigned long)mod->module_core + mod->core_size);
67761 + if (mod->module_init_rx)
67762 + flush_icache_range((unsigned long)mod->module_init_rx,
67763 + (unsigned long)mod->module_init_rx
67764 + + mod->init_size_rx);
67765 + flush_icache_range((unsigned long)mod->module_core_rx,
67766 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
67767
67768 set_fs(old_fs);
67769 }
67770 @@ -2802,8 +2901,10 @@ out:
67771 static void module_deallocate(struct module *mod, struct load_info *info)
67772 {
67773 percpu_modfree(mod);
67774 - module_free(mod, mod->module_init);
67775 - module_free(mod, mod->module_core);
67776 + module_free_exec(mod, mod->module_init_rx);
67777 + module_free_exec(mod, mod->module_core_rx);
67778 + module_free(mod, mod->module_init_rw);
67779 + module_free(mod, mod->module_core_rw);
67780 }
67781
67782 int __weak module_finalize(const Elf_Ehdr *hdr,
67783 @@ -2867,9 +2968,38 @@ static struct module *load_module(void __user *umod,
67784 if (err)
67785 goto free_unload;
67786
67787 + /* Now copy in args */
67788 + mod->args = strndup_user(uargs, ~0UL >> 1);
67789 + if (IS_ERR(mod->args)) {
67790 + err = PTR_ERR(mod->args);
67791 + goto free_unload;
67792 + }
67793 +
67794 /* Set up MODINFO_ATTR fields */
67795 setup_modinfo(mod, &info);
67796
67797 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67798 + {
67799 + char *p, *p2;
67800 +
67801 + if (strstr(mod->args, "grsec_modharden_netdev")) {
67802 + 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);
67803 + err = -EPERM;
67804 + goto free_modinfo;
67805 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67806 + p += strlen("grsec_modharden_normal");
67807 + p2 = strstr(p, "_");
67808 + if (p2) {
67809 + *p2 = '\0';
67810 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67811 + *p2 = '_';
67812 + }
67813 + err = -EPERM;
67814 + goto free_modinfo;
67815 + }
67816 + }
67817 +#endif
67818 +
67819 /* Fix up syms, so that st_value is a pointer to location. */
67820 err = simplify_symbols(mod, &info);
67821 if (err < 0)
67822 @@ -2885,13 +3015,6 @@ static struct module *load_module(void __user *umod,
67823
67824 flush_module_icache(mod);
67825
67826 - /* Now copy in args */
67827 - mod->args = strndup_user(uargs, ~0UL >> 1);
67828 - if (IS_ERR(mod->args)) {
67829 - err = PTR_ERR(mod->args);
67830 - goto free_arch_cleanup;
67831 - }
67832 -
67833 /* Mark state as coming so strong_try_module_get() ignores us. */
67834 mod->state = MODULE_STATE_COMING;
67835
67836 @@ -2948,11 +3071,10 @@ static struct module *load_module(void __user *umod,
67837 unlock:
67838 mutex_unlock(&module_mutex);
67839 synchronize_sched();
67840 - kfree(mod->args);
67841 - free_arch_cleanup:
67842 module_arch_cleanup(mod);
67843 free_modinfo:
67844 free_modinfo(mod);
67845 + kfree(mod->args);
67846 free_unload:
67847 module_unload_free(mod);
67848 free_module:
67849 @@ -2993,16 +3115,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67850 MODULE_STATE_COMING, mod);
67851
67852 /* Set RO and NX regions for core */
67853 - set_section_ro_nx(mod->module_core,
67854 - mod->core_text_size,
67855 - mod->core_ro_size,
67856 - mod->core_size);
67857 + set_section_ro_nx(mod->module_core_rx,
67858 + mod->core_size_rx,
67859 + mod->core_size_rx,
67860 + mod->core_size_rx);
67861
67862 /* Set RO and NX regions for init */
67863 - set_section_ro_nx(mod->module_init,
67864 - mod->init_text_size,
67865 - mod->init_ro_size,
67866 - mod->init_size);
67867 + set_section_ro_nx(mod->module_init_rx,
67868 + mod->init_size_rx,
67869 + mod->init_size_rx,
67870 + mod->init_size_rx);
67871
67872 do_mod_ctors(mod);
67873 /* Start the module */
67874 @@ -3048,11 +3170,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67875 mod->strtab = mod->core_strtab;
67876 #endif
67877 unset_module_init_ro_nx(mod);
67878 - module_free(mod, mod->module_init);
67879 - mod->module_init = NULL;
67880 - mod->init_size = 0;
67881 - mod->init_ro_size = 0;
67882 - mod->init_text_size = 0;
67883 + module_free(mod, mod->module_init_rw);
67884 + module_free_exec(mod, mod->module_init_rx);
67885 + mod->module_init_rw = NULL;
67886 + mod->module_init_rx = NULL;
67887 + mod->init_size_rw = 0;
67888 + mod->init_size_rx = 0;
67889 mutex_unlock(&module_mutex);
67890
67891 return 0;
67892 @@ -3083,10 +3206,16 @@ static const char *get_ksymbol(struct module *mod,
67893 unsigned long nextval;
67894
67895 /* At worse, next value is at end of module */
67896 - if (within_module_init(addr, mod))
67897 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
67898 + if (within_module_init_rx(addr, mod))
67899 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67900 + else if (within_module_init_rw(addr, mod))
67901 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67902 + else if (within_module_core_rx(addr, mod))
67903 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67904 + else if (within_module_core_rw(addr, mod))
67905 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67906 else
67907 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
67908 + return NULL;
67909
67910 /* Scan for closest preceding symbol, and next symbol. (ELF
67911 starts real symbols at 1). */
67912 @@ -3321,7 +3450,7 @@ static int m_show(struct seq_file *m, void *p)
67913 char buf[8];
67914
67915 seq_printf(m, "%s %u",
67916 - mod->name, mod->init_size + mod->core_size);
67917 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67918 print_unload_info(m, mod);
67919
67920 /* Informative for users. */
67921 @@ -3330,7 +3459,7 @@ static int m_show(struct seq_file *m, void *p)
67922 mod->state == MODULE_STATE_COMING ? "Loading":
67923 "Live");
67924 /* Used by oprofile and other similar tools. */
67925 - seq_printf(m, " 0x%pK", mod->module_core);
67926 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67927
67928 /* Taints info */
67929 if (mod->taints)
67930 @@ -3366,7 +3495,17 @@ static const struct file_operations proc_modules_operations = {
67931
67932 static int __init proc_modules_init(void)
67933 {
67934 +#ifndef CONFIG_GRKERNSEC_HIDESYM
67935 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67936 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67937 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67938 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67939 +#else
67940 proc_create("modules", 0, NULL, &proc_modules_operations);
67941 +#endif
67942 +#else
67943 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67944 +#endif
67945 return 0;
67946 }
67947 module_init(proc_modules_init);
67948 @@ -3425,12 +3564,12 @@ struct module *__module_address(unsigned long addr)
67949 {
67950 struct module *mod;
67951
67952 - if (addr < module_addr_min || addr > module_addr_max)
67953 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67954 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
67955 return NULL;
67956
67957 list_for_each_entry_rcu(mod, &modules, list)
67958 - if (within_module_core(addr, mod)
67959 - || within_module_init(addr, mod))
67960 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
67961 return mod;
67962 return NULL;
67963 }
67964 @@ -3464,11 +3603,20 @@ bool is_module_text_address(unsigned long addr)
67965 */
67966 struct module *__module_text_address(unsigned long addr)
67967 {
67968 - struct module *mod = __module_address(addr);
67969 + struct module *mod;
67970 +
67971 +#ifdef CONFIG_X86_32
67972 + addr = ktla_ktva(addr);
67973 +#endif
67974 +
67975 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67976 + return NULL;
67977 +
67978 + mod = __module_address(addr);
67979 +
67980 if (mod) {
67981 /* Make sure it's within the text section. */
67982 - if (!within(addr, mod->module_init, mod->init_text_size)
67983 - && !within(addr, mod->module_core, mod->core_text_size))
67984 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67985 mod = NULL;
67986 }
67987 return mod;
67988 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67989 index 7e3443f..b2a1e6b 100644
67990 --- a/kernel/mutex-debug.c
67991 +++ b/kernel/mutex-debug.c
67992 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67993 }
67994
67995 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67996 - struct thread_info *ti)
67997 + struct task_struct *task)
67998 {
67999 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68000
68001 /* Mark the current thread as blocked on the lock: */
68002 - ti->task->blocked_on = waiter;
68003 + task->blocked_on = waiter;
68004 }
68005
68006 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68007 - struct thread_info *ti)
68008 + struct task_struct *task)
68009 {
68010 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68011 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68012 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68013 - ti->task->blocked_on = NULL;
68014 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68015 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68016 + task->blocked_on = NULL;
68017
68018 list_del_init(&waiter->list);
68019 waiter->task = NULL;
68020 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68021 index 0799fd3..d06ae3b 100644
68022 --- a/kernel/mutex-debug.h
68023 +++ b/kernel/mutex-debug.h
68024 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68025 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68026 extern void debug_mutex_add_waiter(struct mutex *lock,
68027 struct mutex_waiter *waiter,
68028 - struct thread_info *ti);
68029 + struct task_struct *task);
68030 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68031 - struct thread_info *ti);
68032 + struct task_struct *task);
68033 extern void debug_mutex_unlock(struct mutex *lock);
68034 extern void debug_mutex_init(struct mutex *lock, const char *name,
68035 struct lock_class_key *key);
68036 diff --git a/kernel/mutex.c b/kernel/mutex.c
68037 index 89096dd..f91ebc5 100644
68038 --- a/kernel/mutex.c
68039 +++ b/kernel/mutex.c
68040 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68041 spin_lock_mutex(&lock->wait_lock, flags);
68042
68043 debug_mutex_lock_common(lock, &waiter);
68044 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68045 + debug_mutex_add_waiter(lock, &waiter, task);
68046
68047 /* add waiting tasks to the end of the waitqueue (FIFO): */
68048 list_add_tail(&waiter.list, &lock->wait_list);
68049 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68050 * TASK_UNINTERRUPTIBLE case.)
68051 */
68052 if (unlikely(signal_pending_state(state, task))) {
68053 - mutex_remove_waiter(lock, &waiter,
68054 - task_thread_info(task));
68055 + mutex_remove_waiter(lock, &waiter, task);
68056 mutex_release(&lock->dep_map, 1, ip);
68057 spin_unlock_mutex(&lock->wait_lock, flags);
68058
68059 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68060 done:
68061 lock_acquired(&lock->dep_map, ip);
68062 /* got the lock - rejoice! */
68063 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68064 + mutex_remove_waiter(lock, &waiter, task);
68065 mutex_set_owner(lock);
68066
68067 /* set it to 0 if there are no waiters left: */
68068 diff --git a/kernel/padata.c b/kernel/padata.c
68069 index b452599..5d68f4e 100644
68070 --- a/kernel/padata.c
68071 +++ b/kernel/padata.c
68072 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
68073 padata->pd = pd;
68074 padata->cb_cpu = cb_cpu;
68075
68076 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
68077 - atomic_set(&pd->seq_nr, -1);
68078 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
68079 + atomic_set_unchecked(&pd->seq_nr, -1);
68080
68081 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
68082 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
68083
68084 target_cpu = padata_cpu_hash(padata);
68085 queue = per_cpu_ptr(pd->pqueue, target_cpu);
68086 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
68087 padata_init_pqueues(pd);
68088 padata_init_squeues(pd);
68089 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
68090 - atomic_set(&pd->seq_nr, -1);
68091 + atomic_set_unchecked(&pd->seq_nr, -1);
68092 atomic_set(&pd->reorder_objects, 0);
68093 atomic_set(&pd->refcnt, 0);
68094 pd->pinst = pinst;
68095 diff --git a/kernel/panic.c b/kernel/panic.c
68096 index 8ed89a1..e83856a 100644
68097 --- a/kernel/panic.c
68098 +++ b/kernel/panic.c
68099 @@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68100 const char *board;
68101
68102 printk(KERN_WARNING "------------[ cut here ]------------\n");
68103 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68104 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68105 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68106 if (board)
68107 printk(KERN_WARNING "Hardware name: %s\n", board);
68108 @@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68109 */
68110 void __stack_chk_fail(void)
68111 {
68112 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68113 + dump_stack();
68114 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68115 __builtin_return_address(0));
68116 }
68117 EXPORT_SYMBOL(__stack_chk_fail);
68118 diff --git a/kernel/pid.c b/kernel/pid.c
68119 index 9f08dfa..6765c40 100644
68120 --- a/kernel/pid.c
68121 +++ b/kernel/pid.c
68122 @@ -33,6 +33,7 @@
68123 #include <linux/rculist.h>
68124 #include <linux/bootmem.h>
68125 #include <linux/hash.h>
68126 +#include <linux/security.h>
68127 #include <linux/pid_namespace.h>
68128 #include <linux/init_task.h>
68129 #include <linux/syscalls.h>
68130 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68131
68132 int pid_max = PID_MAX_DEFAULT;
68133
68134 -#define RESERVED_PIDS 300
68135 +#define RESERVED_PIDS 500
68136
68137 int pid_max_min = RESERVED_PIDS + 1;
68138 int pid_max_max = PID_MAX_LIMIT;
68139 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68140 */
68141 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68142 {
68143 + struct task_struct *task;
68144 +
68145 rcu_lockdep_assert(rcu_read_lock_held(),
68146 "find_task_by_pid_ns() needs rcu_read_lock()"
68147 " protection");
68148 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68149 +
68150 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68151 +
68152 + if (gr_pid_is_chrooted(task))
68153 + return NULL;
68154 +
68155 + return task;
68156 }
68157
68158 struct task_struct *find_task_by_vpid(pid_t vnr)
68159 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68160 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68161 }
68162
68163 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68164 +{
68165 + rcu_lockdep_assert(rcu_read_lock_held(),
68166 + "find_task_by_pid_ns() needs rcu_read_lock()"
68167 + " protection");
68168 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68169 +}
68170 +
68171 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68172 {
68173 struct pid *pid;
68174 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68175 index 125cb67..a4d1c30 100644
68176 --- a/kernel/posix-cpu-timers.c
68177 +++ b/kernel/posix-cpu-timers.c
68178 @@ -6,6 +6,7 @@
68179 #include <linux/posix-timers.h>
68180 #include <linux/errno.h>
68181 #include <linux/math64.h>
68182 +#include <linux/security.h>
68183 #include <asm/uaccess.h>
68184 #include <linux/kernel_stat.h>
68185 #include <trace/events/timer.h>
68186 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68187
68188 static __init int init_posix_cpu_timers(void)
68189 {
68190 - struct k_clock process = {
68191 + static struct k_clock process = {
68192 .clock_getres = process_cpu_clock_getres,
68193 .clock_get = process_cpu_clock_get,
68194 .timer_create = process_cpu_timer_create,
68195 .nsleep = process_cpu_nsleep,
68196 .nsleep_restart = process_cpu_nsleep_restart,
68197 };
68198 - struct k_clock thread = {
68199 + static struct k_clock thread = {
68200 .clock_getres = thread_cpu_clock_getres,
68201 .clock_get = thread_cpu_clock_get,
68202 .timer_create = thread_cpu_timer_create,
68203 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68204 index 69185ae..cc2847a 100644
68205 --- a/kernel/posix-timers.c
68206 +++ b/kernel/posix-timers.c
68207 @@ -43,6 +43,7 @@
68208 #include <linux/idr.h>
68209 #include <linux/posix-clock.h>
68210 #include <linux/posix-timers.h>
68211 +#include <linux/grsecurity.h>
68212 #include <linux/syscalls.h>
68213 #include <linux/wait.h>
68214 #include <linux/workqueue.h>
68215 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68216 * which we beg off on and pass to do_sys_settimeofday().
68217 */
68218
68219 -static struct k_clock posix_clocks[MAX_CLOCKS];
68220 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68221
68222 /*
68223 * These ones are defined below.
68224 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68225 */
68226 static __init int init_posix_timers(void)
68227 {
68228 - struct k_clock clock_realtime = {
68229 + static struct k_clock clock_realtime = {
68230 .clock_getres = hrtimer_get_res,
68231 .clock_get = posix_clock_realtime_get,
68232 .clock_set = posix_clock_realtime_set,
68233 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68234 .timer_get = common_timer_get,
68235 .timer_del = common_timer_del,
68236 };
68237 - struct k_clock clock_monotonic = {
68238 + static struct k_clock clock_monotonic = {
68239 .clock_getres = hrtimer_get_res,
68240 .clock_get = posix_ktime_get_ts,
68241 .nsleep = common_nsleep,
68242 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68243 .timer_get = common_timer_get,
68244 .timer_del = common_timer_del,
68245 };
68246 - struct k_clock clock_monotonic_raw = {
68247 + static struct k_clock clock_monotonic_raw = {
68248 .clock_getres = hrtimer_get_res,
68249 .clock_get = posix_get_monotonic_raw,
68250 };
68251 - struct k_clock clock_realtime_coarse = {
68252 + static struct k_clock clock_realtime_coarse = {
68253 .clock_getres = posix_get_coarse_res,
68254 .clock_get = posix_get_realtime_coarse,
68255 };
68256 - struct k_clock clock_monotonic_coarse = {
68257 + static struct k_clock clock_monotonic_coarse = {
68258 .clock_getres = posix_get_coarse_res,
68259 .clock_get = posix_get_monotonic_coarse,
68260 };
68261 - struct k_clock clock_boottime = {
68262 + static struct k_clock clock_boottime = {
68263 .clock_getres = hrtimer_get_res,
68264 .clock_get = posix_get_boottime,
68265 .nsleep = common_nsleep,
68266 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68267 return;
68268 }
68269
68270 - posix_clocks[clock_id] = *new_clock;
68271 + posix_clocks[clock_id] = new_clock;
68272 }
68273 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68274
68275 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68276 return (id & CLOCKFD_MASK) == CLOCKFD ?
68277 &clock_posix_dynamic : &clock_posix_cpu;
68278
68279 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68280 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68281 return NULL;
68282 - return &posix_clocks[id];
68283 + return posix_clocks[id];
68284 }
68285
68286 static int common_timer_create(struct k_itimer *new_timer)
68287 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68288 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68289 return -EFAULT;
68290
68291 + /* only the CLOCK_REALTIME clock can be set, all other clocks
68292 + have their clock_set fptr set to a nosettime dummy function
68293 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68294 + call common_clock_set, which calls do_sys_settimeofday, which
68295 + we hook
68296 + */
68297 +
68298 return kc->clock_set(which_clock, &new_tp);
68299 }
68300
68301 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68302 index d523593..68197a4 100644
68303 --- a/kernel/power/poweroff.c
68304 +++ b/kernel/power/poweroff.c
68305 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68306 .enable_mask = SYSRQ_ENABLE_BOOT,
68307 };
68308
68309 -static int pm_sysrq_init(void)
68310 +static int __init pm_sysrq_init(void)
68311 {
68312 register_sysrq_key('o', &sysrq_poweroff_op);
68313 return 0;
68314 diff --git a/kernel/power/process.c b/kernel/power/process.c
68315 index 7aac07a..2d3c6dc 100644
68316 --- a/kernel/power/process.c
68317 +++ b/kernel/power/process.c
68318 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
68319 u64 elapsed_csecs64;
68320 unsigned int elapsed_csecs;
68321 bool wakeup = false;
68322 + bool timedout = false;
68323
68324 do_gettimeofday(&start);
68325
68326 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
68327
68328 while (true) {
68329 todo = 0;
68330 + if (time_after(jiffies, end_time))
68331 + timedout = true;
68332 read_lock(&tasklist_lock);
68333 do_each_thread(g, p) {
68334 if (p == current || !freeze_task(p))
68335 @@ -60,9 +63,13 @@ static int try_to_freeze_tasks(bool user_only)
68336 * try_to_stop() after schedule() in ptrace/signal
68337 * stop sees TIF_FREEZE.
68338 */
68339 - if (!task_is_stopped_or_traced(p) &&
68340 - !freezer_should_skip(p))
68341 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68342 todo++;
68343 + if (timedout) {
68344 + printk(KERN_ERR "Task refusing to freeze:\n");
68345 + sched_show_task(p);
68346 + }
68347 + }
68348 } while_each_thread(g, p);
68349 read_unlock(&tasklist_lock);
68350
68351 @@ -71,7 +78,7 @@ static int try_to_freeze_tasks(bool user_only)
68352 todo += wq_busy;
68353 }
68354
68355 - if (!todo || time_after(jiffies, end_time))
68356 + if (!todo || timedout)
68357 break;
68358
68359 if (pm_wakeup_pending()) {
68360 diff --git a/kernel/printk.c b/kernel/printk.c
68361 index 32690a0..cd7c798 100644
68362 --- a/kernel/printk.c
68363 +++ b/kernel/printk.c
68364 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
68365 if (from_file && type != SYSLOG_ACTION_OPEN)
68366 return 0;
68367
68368 +#ifdef CONFIG_GRKERNSEC_DMESG
68369 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68370 + return -EPERM;
68371 +#endif
68372 +
68373 if (syslog_action_restricted(type)) {
68374 if (capable(CAP_SYSLOG))
68375 return 0;
68376 diff --git a/kernel/profile.c b/kernel/profile.c
68377 index 76b8e77..a2930e8 100644
68378 --- a/kernel/profile.c
68379 +++ b/kernel/profile.c
68380 @@ -39,7 +39,7 @@ struct profile_hit {
68381 /* Oprofile timer tick hook */
68382 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68383
68384 -static atomic_t *prof_buffer;
68385 +static atomic_unchecked_t *prof_buffer;
68386 static unsigned long prof_len, prof_shift;
68387
68388 int prof_on __read_mostly;
68389 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68390 hits[i].pc = 0;
68391 continue;
68392 }
68393 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68394 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68395 hits[i].hits = hits[i].pc = 0;
68396 }
68397 }
68398 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68399 * Add the current hit(s) and flush the write-queue out
68400 * to the global buffer:
68401 */
68402 - atomic_add(nr_hits, &prof_buffer[pc]);
68403 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68404 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68405 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68406 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68407 hits[i].pc = hits[i].hits = 0;
68408 }
68409 out:
68410 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68411 {
68412 unsigned long pc;
68413 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68414 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68415 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68416 }
68417 #endif /* !CONFIG_SMP */
68418
68419 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68420 return -EFAULT;
68421 buf++; p++; count--; read++;
68422 }
68423 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68424 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68425 if (copy_to_user(buf, (void *)pnt, count))
68426 return -EFAULT;
68427 read += count;
68428 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68429 }
68430 #endif
68431 profile_discard_flip_buffers();
68432 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68433 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68434 return count;
68435 }
68436
68437 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68438 index 00ab2ca..d237f61 100644
68439 --- a/kernel/ptrace.c
68440 +++ b/kernel/ptrace.c
68441 @@ -285,7 +285,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68442 task->ptrace = PT_PTRACED;
68443 if (seize)
68444 task->ptrace |= PT_SEIZED;
68445 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68446 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68447 task->ptrace |= PT_PTRACE_CAP;
68448
68449 __ptrace_link(task, current);
68450 @@ -491,7 +491,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68451 break;
68452 return -EIO;
68453 }
68454 - if (copy_to_user(dst, buf, retval))
68455 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68456 return -EFAULT;
68457 copied += retval;
68458 src += retval;
68459 @@ -688,7 +688,7 @@ int ptrace_request(struct task_struct *child, long request,
68460 bool seized = child->ptrace & PT_SEIZED;
68461 int ret = -EIO;
68462 siginfo_t siginfo, *si;
68463 - void __user *datavp = (void __user *) data;
68464 + void __user *datavp = (__force void __user *) data;
68465 unsigned long __user *datalp = datavp;
68466 unsigned long flags;
68467
68468 @@ -890,14 +890,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68469 goto out;
68470 }
68471
68472 + if (gr_handle_ptrace(child, request)) {
68473 + ret = -EPERM;
68474 + goto out_put_task_struct;
68475 + }
68476 +
68477 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68478 ret = ptrace_attach(child, request, data);
68479 /*
68480 * Some architectures need to do book-keeping after
68481 * a ptrace attach.
68482 */
68483 - if (!ret)
68484 + if (!ret) {
68485 arch_ptrace_attach(child);
68486 + gr_audit_ptrace(child);
68487 + }
68488 goto out_put_task_struct;
68489 }
68490
68491 @@ -923,7 +930,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68492 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68493 if (copied != sizeof(tmp))
68494 return -EIO;
68495 - return put_user(tmp, (unsigned long __user *)data);
68496 + return put_user(tmp, (__force unsigned long __user *)data);
68497 }
68498
68499 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68500 @@ -1033,14 +1040,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68501 goto out;
68502 }
68503
68504 + if (gr_handle_ptrace(child, request)) {
68505 + ret = -EPERM;
68506 + goto out_put_task_struct;
68507 + }
68508 +
68509 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68510 ret = ptrace_attach(child, request, data);
68511 /*
68512 * Some architectures need to do book-keeping after
68513 * a ptrace attach.
68514 */
68515 - if (!ret)
68516 + if (!ret) {
68517 arch_ptrace_attach(child);
68518 + gr_audit_ptrace(child);
68519 + }
68520 goto out_put_task_struct;
68521 }
68522
68523 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68524 index 977296d..c4744dc 100644
68525 --- a/kernel/rcutiny.c
68526 +++ b/kernel/rcutiny.c
68527 @@ -46,7 +46,7 @@
68528 struct rcu_ctrlblk;
68529 static void invoke_rcu_callbacks(void);
68530 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68531 -static void rcu_process_callbacks(struct softirq_action *unused);
68532 +static void rcu_process_callbacks(void);
68533 static void __call_rcu(struct rcu_head *head,
68534 void (*func)(struct rcu_head *rcu),
68535 struct rcu_ctrlblk *rcp);
68536 @@ -297,7 +297,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68537 rcu_is_callbacks_kthread()));
68538 }
68539
68540 -static void rcu_process_callbacks(struct softirq_action *unused)
68541 +static void rcu_process_callbacks(void)
68542 {
68543 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68544 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68545 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68546 index 9cb1ae4..aac7d3e 100644
68547 --- a/kernel/rcutiny_plugin.h
68548 +++ b/kernel/rcutiny_plugin.h
68549 @@ -920,7 +920,7 @@ static int rcu_kthread(void *arg)
68550 have_rcu_kthread_work = morework;
68551 local_irq_restore(flags);
68552 if (work)
68553 - rcu_process_callbacks(NULL);
68554 + rcu_process_callbacks();
68555 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68556 }
68557
68558 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68559 index a58ac28..196a3d8 100644
68560 --- a/kernel/rcutorture.c
68561 +++ b/kernel/rcutorture.c
68562 @@ -148,12 +148,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68563 { 0 };
68564 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68565 { 0 };
68566 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68567 -static atomic_t n_rcu_torture_alloc;
68568 -static atomic_t n_rcu_torture_alloc_fail;
68569 -static atomic_t n_rcu_torture_free;
68570 -static atomic_t n_rcu_torture_mberror;
68571 -static atomic_t n_rcu_torture_error;
68572 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68573 +static atomic_unchecked_t n_rcu_torture_alloc;
68574 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68575 +static atomic_unchecked_t n_rcu_torture_free;
68576 +static atomic_unchecked_t n_rcu_torture_mberror;
68577 +static atomic_unchecked_t n_rcu_torture_error;
68578 static long n_rcu_torture_boost_ktrerror;
68579 static long n_rcu_torture_boost_rterror;
68580 static long n_rcu_torture_boost_failure;
68581 @@ -243,11 +243,11 @@ rcu_torture_alloc(void)
68582
68583 spin_lock_bh(&rcu_torture_lock);
68584 if (list_empty(&rcu_torture_freelist)) {
68585 - atomic_inc(&n_rcu_torture_alloc_fail);
68586 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68587 spin_unlock_bh(&rcu_torture_lock);
68588 return NULL;
68589 }
68590 - atomic_inc(&n_rcu_torture_alloc);
68591 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68592 p = rcu_torture_freelist.next;
68593 list_del_init(p);
68594 spin_unlock_bh(&rcu_torture_lock);
68595 @@ -260,7 +260,7 @@ rcu_torture_alloc(void)
68596 static void
68597 rcu_torture_free(struct rcu_torture *p)
68598 {
68599 - atomic_inc(&n_rcu_torture_free);
68600 + atomic_inc_unchecked(&n_rcu_torture_free);
68601 spin_lock_bh(&rcu_torture_lock);
68602 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68603 spin_unlock_bh(&rcu_torture_lock);
68604 @@ -380,7 +380,7 @@ rcu_torture_cb(struct rcu_head *p)
68605 i = rp->rtort_pipe_count;
68606 if (i > RCU_TORTURE_PIPE_LEN)
68607 i = RCU_TORTURE_PIPE_LEN;
68608 - atomic_inc(&rcu_torture_wcount[i]);
68609 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68610 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68611 rp->rtort_mbtest = 0;
68612 rcu_torture_free(rp);
68613 @@ -427,7 +427,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68614 i = rp->rtort_pipe_count;
68615 if (i > RCU_TORTURE_PIPE_LEN)
68616 i = RCU_TORTURE_PIPE_LEN;
68617 - atomic_inc(&rcu_torture_wcount[i]);
68618 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68619 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68620 rp->rtort_mbtest = 0;
68621 list_del(&rp->rtort_free);
68622 @@ -916,7 +916,7 @@ rcu_torture_writer(void *arg)
68623 i = old_rp->rtort_pipe_count;
68624 if (i > RCU_TORTURE_PIPE_LEN)
68625 i = RCU_TORTURE_PIPE_LEN;
68626 - atomic_inc(&rcu_torture_wcount[i]);
68627 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68628 old_rp->rtort_pipe_count++;
68629 cur_ops->deferred_free(old_rp);
68630 }
68631 @@ -997,7 +997,7 @@ static void rcu_torture_timer(unsigned long unused)
68632 return;
68633 }
68634 if (p->rtort_mbtest == 0)
68635 - atomic_inc(&n_rcu_torture_mberror);
68636 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68637 spin_lock(&rand_lock);
68638 cur_ops->read_delay(&rand);
68639 n_rcu_torture_timers++;
68640 @@ -1061,7 +1061,7 @@ rcu_torture_reader(void *arg)
68641 continue;
68642 }
68643 if (p->rtort_mbtest == 0)
68644 - atomic_inc(&n_rcu_torture_mberror);
68645 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68646 cur_ops->read_delay(&rand);
68647 preempt_disable();
68648 pipe_count = p->rtort_pipe_count;
68649 @@ -1123,10 +1123,10 @@ rcu_torture_printk(char *page)
68650 rcu_torture_current,
68651 rcu_torture_current_version,
68652 list_empty(&rcu_torture_freelist),
68653 - atomic_read(&n_rcu_torture_alloc),
68654 - atomic_read(&n_rcu_torture_alloc_fail),
68655 - atomic_read(&n_rcu_torture_free),
68656 - atomic_read(&n_rcu_torture_mberror),
68657 + atomic_read_unchecked(&n_rcu_torture_alloc),
68658 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68659 + atomic_read_unchecked(&n_rcu_torture_free),
68660 + atomic_read_unchecked(&n_rcu_torture_mberror),
68661 n_rcu_torture_boost_ktrerror,
68662 n_rcu_torture_boost_rterror,
68663 n_rcu_torture_boost_failure,
68664 @@ -1136,7 +1136,7 @@ rcu_torture_printk(char *page)
68665 n_online_attempts,
68666 n_offline_successes,
68667 n_offline_attempts);
68668 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68669 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68670 n_rcu_torture_boost_ktrerror != 0 ||
68671 n_rcu_torture_boost_rterror != 0 ||
68672 n_rcu_torture_boost_failure != 0)
68673 @@ -1144,7 +1144,7 @@ rcu_torture_printk(char *page)
68674 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68675 if (i > 1) {
68676 cnt += sprintf(&page[cnt], "!!! ");
68677 - atomic_inc(&n_rcu_torture_error);
68678 + atomic_inc_unchecked(&n_rcu_torture_error);
68679 WARN_ON_ONCE(1);
68680 }
68681 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68682 @@ -1158,7 +1158,7 @@ rcu_torture_printk(char *page)
68683 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68684 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68685 cnt += sprintf(&page[cnt], " %d",
68686 - atomic_read(&rcu_torture_wcount[i]));
68687 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68688 }
68689 cnt += sprintf(&page[cnt], "\n");
68690 if (cur_ops->stats)
68691 @@ -1600,7 +1600,7 @@ rcu_torture_cleanup(void)
68692
68693 if (cur_ops->cleanup)
68694 cur_ops->cleanup();
68695 - if (atomic_read(&n_rcu_torture_error))
68696 + if (atomic_read_unchecked(&n_rcu_torture_error))
68697 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68698 else
68699 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
68700 @@ -1664,17 +1664,17 @@ rcu_torture_init(void)
68701
68702 rcu_torture_current = NULL;
68703 rcu_torture_current_version = 0;
68704 - atomic_set(&n_rcu_torture_alloc, 0);
68705 - atomic_set(&n_rcu_torture_alloc_fail, 0);
68706 - atomic_set(&n_rcu_torture_free, 0);
68707 - atomic_set(&n_rcu_torture_mberror, 0);
68708 - atomic_set(&n_rcu_torture_error, 0);
68709 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68710 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68711 + atomic_set_unchecked(&n_rcu_torture_free, 0);
68712 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68713 + atomic_set_unchecked(&n_rcu_torture_error, 0);
68714 n_rcu_torture_boost_ktrerror = 0;
68715 n_rcu_torture_boost_rterror = 0;
68716 n_rcu_torture_boost_failure = 0;
68717 n_rcu_torture_boosts = 0;
68718 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68719 - atomic_set(&rcu_torture_wcount[i], 0);
68720 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68721 for_each_possible_cpu(cpu) {
68722 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68723 per_cpu(rcu_torture_count, cpu)[i] = 0;
68724 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68725 index 6c4a672..70f3202 100644
68726 --- a/kernel/rcutree.c
68727 +++ b/kernel/rcutree.c
68728 @@ -363,9 +363,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68729 rcu_prepare_for_idle(smp_processor_id());
68730 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68731 smp_mb__before_atomic_inc(); /* See above. */
68732 - atomic_inc(&rdtp->dynticks);
68733 + atomic_inc_unchecked(&rdtp->dynticks);
68734 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68735 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68736 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68737 }
68738
68739 /**
68740 @@ -438,10 +438,10 @@ void rcu_irq_exit(void)
68741 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68742 {
68743 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68744 - atomic_inc(&rdtp->dynticks);
68745 + atomic_inc_unchecked(&rdtp->dynticks);
68746 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68747 smp_mb__after_atomic_inc(); /* See above. */
68748 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68749 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68750 rcu_cleanup_after_idle(smp_processor_id());
68751 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68752 if (!is_idle_task(current)) {
68753 @@ -531,14 +531,14 @@ void rcu_nmi_enter(void)
68754 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68755
68756 if (rdtp->dynticks_nmi_nesting == 0 &&
68757 - (atomic_read(&rdtp->dynticks) & 0x1))
68758 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68759 return;
68760 rdtp->dynticks_nmi_nesting++;
68761 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68762 - atomic_inc(&rdtp->dynticks);
68763 + atomic_inc_unchecked(&rdtp->dynticks);
68764 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68765 smp_mb__after_atomic_inc(); /* See above. */
68766 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68767 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68768 }
68769
68770 /**
68771 @@ -557,9 +557,9 @@ void rcu_nmi_exit(void)
68772 return;
68773 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68774 smp_mb__before_atomic_inc(); /* See above. */
68775 - atomic_inc(&rdtp->dynticks);
68776 + atomic_inc_unchecked(&rdtp->dynticks);
68777 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68778 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68779 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68780 }
68781
68782 #ifdef CONFIG_PROVE_RCU
68783 @@ -575,7 +575,7 @@ int rcu_is_cpu_idle(void)
68784 int ret;
68785
68786 preempt_disable();
68787 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68788 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68789 preempt_enable();
68790 return ret;
68791 }
68792 @@ -604,7 +604,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68793 */
68794 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68795 {
68796 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68797 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68798 return (rdp->dynticks_snap & 0x1) == 0;
68799 }
68800
68801 @@ -619,7 +619,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68802 unsigned int curr;
68803 unsigned int snap;
68804
68805 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68806 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68807 snap = (unsigned int)rdp->dynticks_snap;
68808
68809 /*
68810 @@ -1667,7 +1667,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68811 /*
68812 * Do RCU core processing for the current CPU.
68813 */
68814 -static void rcu_process_callbacks(struct softirq_action *unused)
68815 +static void rcu_process_callbacks(void)
68816 {
68817 trace_rcu_utilization("Start RCU core");
68818 __rcu_process_callbacks(&rcu_sched_state,
68819 @@ -2030,7 +2030,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68820 rdp->qlen = 0;
68821 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68822 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_NESTING);
68823 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68824 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68825 rdp->cpu = cpu;
68826 rdp->rsp = rsp;
68827 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68828 @@ -2058,8 +2058,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68829 rdp->n_force_qs_snap = rsp->n_force_qs;
68830 rdp->blimit = blimit;
68831 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_NESTING;
68832 - atomic_set(&rdp->dynticks->dynticks,
68833 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68834 + atomic_set_unchecked(&rdp->dynticks->dynticks,
68835 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68836 rcu_prepare_for_idle_init(cpu);
68837 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68838
68839 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68840 index fddff92..2c08359 100644
68841 --- a/kernel/rcutree.h
68842 +++ b/kernel/rcutree.h
68843 @@ -87,7 +87,7 @@ struct rcu_dynticks {
68844 long long dynticks_nesting; /* Track irq/process nesting level. */
68845 /* Process level is worth LLONG_MAX/2. */
68846 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68847 - atomic_t dynticks; /* Even value for idle, else odd. */
68848 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68849 };
68850
68851 /* RCU's kthread states for tracing. */
68852 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68853 index 8bb35d7..6ea0a463 100644
68854 --- a/kernel/rcutree_plugin.h
68855 +++ b/kernel/rcutree_plugin.h
68856 @@ -850,7 +850,7 @@ void synchronize_rcu_expedited(void)
68857
68858 /* Clean up and exit. */
68859 smp_mb(); /* ensure expedited GP seen before counter increment. */
68860 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68861 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68862 unlock_mb_ret:
68863 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68864 mb_ret:
68865 @@ -1833,8 +1833,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
68866
68867 #else /* #ifndef CONFIG_SMP */
68868
68869 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68870 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68871 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68872 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68873
68874 static int synchronize_sched_expedited_cpu_stop(void *data)
68875 {
68876 @@ -1889,7 +1889,7 @@ void synchronize_sched_expedited(void)
68877 int firstsnap, s, snap, trycount = 0;
68878
68879 /* Note that atomic_inc_return() implies full memory barrier. */
68880 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68881 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68882 get_online_cpus();
68883
68884 /*
68885 @@ -1910,7 +1910,7 @@ void synchronize_sched_expedited(void)
68886 }
68887
68888 /* Check to see if someone else did our work for us. */
68889 - s = atomic_read(&sync_sched_expedited_done);
68890 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68891 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68892 smp_mb(); /* ensure test happens before caller kfree */
68893 return;
68894 @@ -1925,7 +1925,7 @@ void synchronize_sched_expedited(void)
68895 * grace period works for us.
68896 */
68897 get_online_cpus();
68898 - snap = atomic_read(&sync_sched_expedited_started);
68899 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
68900 smp_mb(); /* ensure read is before try_stop_cpus(). */
68901 }
68902
68903 @@ -1936,12 +1936,12 @@ void synchronize_sched_expedited(void)
68904 * than we did beat us to the punch.
68905 */
68906 do {
68907 - s = atomic_read(&sync_sched_expedited_done);
68908 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68909 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68910 smp_mb(); /* ensure test happens before caller kfree */
68911 break;
68912 }
68913 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68914 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68915
68916 put_online_cpus();
68917 }
68918 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68919 index 654cfe6..c0b28e2 100644
68920 --- a/kernel/rcutree_trace.c
68921 +++ b/kernel/rcutree_trace.c
68922 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68923 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68924 rdp->qs_pending);
68925 seq_printf(m, " dt=%d/%llx/%d df=%lu",
68926 - atomic_read(&rdp->dynticks->dynticks),
68927 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68928 rdp->dynticks->dynticks_nesting,
68929 rdp->dynticks->dynticks_nmi_nesting,
68930 rdp->dynticks_fqs);
68931 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68932 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68933 rdp->qs_pending);
68934 seq_printf(m, ",%d,%llx,%d,%lu",
68935 - atomic_read(&rdp->dynticks->dynticks),
68936 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68937 rdp->dynticks->dynticks_nesting,
68938 rdp->dynticks->dynticks_nmi_nesting,
68939 rdp->dynticks_fqs);
68940 diff --git a/kernel/resource.c b/kernel/resource.c
68941 index 7640b3a..5879283 100644
68942 --- a/kernel/resource.c
68943 +++ b/kernel/resource.c
68944 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68945
68946 static int __init ioresources_init(void)
68947 {
68948 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68949 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68950 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68951 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68952 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68953 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68954 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68955 +#endif
68956 +#else
68957 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68958 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68959 +#endif
68960 return 0;
68961 }
68962 __initcall(ioresources_init);
68963 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68964 index 98ec494..4241d6d 100644
68965 --- a/kernel/rtmutex-tester.c
68966 +++ b/kernel/rtmutex-tester.c
68967 @@ -20,7 +20,7 @@
68968 #define MAX_RT_TEST_MUTEXES 8
68969
68970 static spinlock_t rttest_lock;
68971 -static atomic_t rttest_event;
68972 +static atomic_unchecked_t rttest_event;
68973
68974 struct test_thread_data {
68975 int opcode;
68976 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68977
68978 case RTTEST_LOCKCONT:
68979 td->mutexes[td->opdata] = 1;
68980 - td->event = atomic_add_return(1, &rttest_event);
68981 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68982 return 0;
68983
68984 case RTTEST_RESET:
68985 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68986 return 0;
68987
68988 case RTTEST_RESETEVENT:
68989 - atomic_set(&rttest_event, 0);
68990 + atomic_set_unchecked(&rttest_event, 0);
68991 return 0;
68992
68993 default:
68994 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68995 return ret;
68996
68997 td->mutexes[id] = 1;
68998 - td->event = atomic_add_return(1, &rttest_event);
68999 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69000 rt_mutex_lock(&mutexes[id]);
69001 - td->event = atomic_add_return(1, &rttest_event);
69002 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69003 td->mutexes[id] = 4;
69004 return 0;
69005
69006 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69007 return ret;
69008
69009 td->mutexes[id] = 1;
69010 - td->event = atomic_add_return(1, &rttest_event);
69011 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69012 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69013 - td->event = atomic_add_return(1, &rttest_event);
69014 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69015 td->mutexes[id] = ret ? 0 : 4;
69016 return ret ? -EINTR : 0;
69017
69018 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69019 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69020 return ret;
69021
69022 - td->event = atomic_add_return(1, &rttest_event);
69023 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69024 rt_mutex_unlock(&mutexes[id]);
69025 - td->event = atomic_add_return(1, &rttest_event);
69026 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69027 td->mutexes[id] = 0;
69028 return 0;
69029
69030 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69031 break;
69032
69033 td->mutexes[dat] = 2;
69034 - td->event = atomic_add_return(1, &rttest_event);
69035 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69036 break;
69037
69038 default:
69039 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69040 return;
69041
69042 td->mutexes[dat] = 3;
69043 - td->event = atomic_add_return(1, &rttest_event);
69044 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69045 break;
69046
69047 case RTTEST_LOCKNOWAIT:
69048 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69049 return;
69050
69051 td->mutexes[dat] = 1;
69052 - td->event = atomic_add_return(1, &rttest_event);
69053 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69054 return;
69055
69056 default:
69057 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69058 index e8a1f83..363d17d 100644
69059 --- a/kernel/sched/auto_group.c
69060 +++ b/kernel/sched/auto_group.c
69061 @@ -11,7 +11,7 @@
69062
69063 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69064 static struct autogroup autogroup_default;
69065 -static atomic_t autogroup_seq_nr;
69066 +static atomic_unchecked_t autogroup_seq_nr;
69067
69068 void __init autogroup_init(struct task_struct *init_task)
69069 {
69070 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69071
69072 kref_init(&ag->kref);
69073 init_rwsem(&ag->lock);
69074 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69075 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69076 ag->tg = tg;
69077 #ifdef CONFIG_RT_GROUP_SCHED
69078 /*
69079 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69080 index 478a04c..6970d99 100644
69081 --- a/kernel/sched/core.c
69082 +++ b/kernel/sched/core.c
69083 @@ -3142,6 +3142,19 @@ pick_next_task(struct rq *rq)
69084 BUG(); /* the idle class will always have a runnable task */
69085 }
69086
69087 +#ifdef CONFIG_GRKERNSEC_SETXID
69088 +extern void gr_delayed_cred_worker(void);
69089 +static inline void gr_cred_schedule(void)
69090 +{
69091 + if (unlikely(current->delayed_cred))
69092 + gr_delayed_cred_worker();
69093 +}
69094 +#else
69095 +static inline void gr_cred_schedule(void)
69096 +{
69097 +}
69098 +#endif
69099 +
69100 /*
69101 * __schedule() is the main scheduler function.
69102 */
69103 @@ -3161,6 +3174,8 @@ need_resched:
69104
69105 schedule_debug(prev);
69106
69107 + gr_cred_schedule();
69108 +
69109 if (sched_feat(HRTICK))
69110 hrtick_clear(rq);
69111
69112 @@ -3851,6 +3866,8 @@ int can_nice(const struct task_struct *p, const int nice)
69113 /* convert nice value [19,-20] to rlimit style value [1,40] */
69114 int nice_rlim = 20 - nice;
69115
69116 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69117 +
69118 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69119 capable(CAP_SYS_NICE));
69120 }
69121 @@ -3884,7 +3901,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69122 if (nice > 19)
69123 nice = 19;
69124
69125 - if (increment < 0 && !can_nice(current, nice))
69126 + if (increment < 0 && (!can_nice(current, nice) ||
69127 + gr_handle_chroot_nice()))
69128 return -EPERM;
69129
69130 retval = security_task_setnice(current, nice);
69131 @@ -4041,6 +4059,7 @@ recheck:
69132 unsigned long rlim_rtprio =
69133 task_rlimit(p, RLIMIT_RTPRIO);
69134
69135 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69136 /* can't set/change the rt policy */
69137 if (policy != p->policy && !rlim_rtprio)
69138 return -EPERM;
69139 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69140 index aca16b8..8e3acc4 100644
69141 --- a/kernel/sched/fair.c
69142 +++ b/kernel/sched/fair.c
69143 @@ -5147,7 +5147,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69144 * run_rebalance_domains is triggered when needed from the scheduler tick.
69145 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69146 */
69147 -static void run_rebalance_domains(struct softirq_action *h)
69148 +static void run_rebalance_domains(void)
69149 {
69150 int this_cpu = smp_processor_id();
69151 struct rq *this_rq = cpu_rq(this_cpu);
69152 diff --git a/kernel/signal.c b/kernel/signal.c
69153 index b09cf3b..b291c66 100644
69154 --- a/kernel/signal.c
69155 +++ b/kernel/signal.c
69156 @@ -46,12 +46,12 @@ static struct kmem_cache *sigqueue_cachep;
69157
69158 int print_fatal_signals __read_mostly;
69159
69160 -static void __user *sig_handler(struct task_struct *t, int sig)
69161 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69162 {
69163 return t->sighand->action[sig - 1].sa.sa_handler;
69164 }
69165
69166 -static int sig_handler_ignored(void __user *handler, int sig)
69167 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69168 {
69169 /* Is it explicitly or implicitly ignored? */
69170 return handler == SIG_IGN ||
69171 @@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69172 static int sig_task_ignored(struct task_struct *t, int sig,
69173 int from_ancestor_ns)
69174 {
69175 - void __user *handler;
69176 + __sighandler_t handler;
69177
69178 handler = sig_handler(t, sig);
69179
69180 @@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69181 atomic_inc(&user->sigpending);
69182 rcu_read_unlock();
69183
69184 + if (!override_rlimit)
69185 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69186 +
69187 if (override_rlimit ||
69188 atomic_read(&user->sigpending) <=
69189 task_rlimit(t, RLIMIT_SIGPENDING)) {
69190 @@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69191
69192 int unhandled_signal(struct task_struct *tsk, int sig)
69193 {
69194 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69195 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69196 if (is_global_init(tsk))
69197 return 1;
69198 if (handler != SIG_IGN && handler != SIG_DFL)
69199 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69200 }
69201 }
69202
69203 + /* allow glibc communication via tgkill to other threads in our
69204 + thread group */
69205 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69206 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69207 + && gr_handle_signal(t, sig))
69208 + return -EPERM;
69209 +
69210 return security_task_kill(t, info, sig, 0);
69211 }
69212
69213 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69214 return send_signal(sig, info, p, 1);
69215 }
69216
69217 -static int
69218 +int
69219 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69220 {
69221 return send_signal(sig, info, t, 0);
69222 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69223 unsigned long int flags;
69224 int ret, blocked, ignored;
69225 struct k_sigaction *action;
69226 + int is_unhandled = 0;
69227
69228 spin_lock_irqsave(&t->sighand->siglock, flags);
69229 action = &t->sighand->action[sig-1];
69230 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69231 }
69232 if (action->sa.sa_handler == SIG_DFL)
69233 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69234 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69235 + is_unhandled = 1;
69236 ret = specific_send_sig_info(sig, info, t);
69237 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69238
69239 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
69240 + normal operation */
69241 + if (is_unhandled) {
69242 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69243 + gr_handle_crash(t, sig);
69244 + }
69245 +
69246 return ret;
69247 }
69248
69249 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69250 ret = check_kill_permission(sig, info, p);
69251 rcu_read_unlock();
69252
69253 - if (!ret && sig)
69254 + if (!ret && sig) {
69255 ret = do_send_sig_info(sig, info, p, true);
69256 + if (!ret)
69257 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69258 + }
69259
69260 return ret;
69261 }
69262 @@ -2829,7 +2852,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69263 int error = -ESRCH;
69264
69265 rcu_read_lock();
69266 - p = find_task_by_vpid(pid);
69267 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69268 + /* allow glibc communication via tgkill to other threads in our
69269 + thread group */
69270 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69271 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
69272 + p = find_task_by_vpid_unrestricted(pid);
69273 + else
69274 +#endif
69275 + p = find_task_by_vpid(pid);
69276 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69277 error = check_kill_permission(sig, info, p);
69278 /*
69279 diff --git a/kernel/smp.c b/kernel/smp.c
69280 index db197d6..17aef0b 100644
69281 --- a/kernel/smp.c
69282 +++ b/kernel/smp.c
69283 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69284 }
69285 EXPORT_SYMBOL(smp_call_function);
69286
69287 -void ipi_call_lock(void)
69288 +void ipi_call_lock(void) __acquires(call_function.lock)
69289 {
69290 raw_spin_lock(&call_function.lock);
69291 }
69292
69293 -void ipi_call_unlock(void)
69294 +void ipi_call_unlock(void) __releases(call_function.lock)
69295 {
69296 raw_spin_unlock(&call_function.lock);
69297 }
69298
69299 -void ipi_call_lock_irq(void)
69300 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
69301 {
69302 raw_spin_lock_irq(&call_function.lock);
69303 }
69304
69305 -void ipi_call_unlock_irq(void)
69306 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
69307 {
69308 raw_spin_unlock_irq(&call_function.lock);
69309 }
69310 diff --git a/kernel/softirq.c b/kernel/softirq.c
69311 index 4eb3a0f..6f1fa81 100644
69312 --- a/kernel/softirq.c
69313 +++ b/kernel/softirq.c
69314 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69315
69316 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69317
69318 -char *softirq_to_name[NR_SOFTIRQS] = {
69319 +const char * const softirq_to_name[NR_SOFTIRQS] = {
69320 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69321 "TASKLET", "SCHED", "HRTIMER", "RCU"
69322 };
69323 @@ -235,7 +235,7 @@ restart:
69324 kstat_incr_softirqs_this_cpu(vec_nr);
69325
69326 trace_softirq_entry(vec_nr);
69327 - h->action(h);
69328 + h->action();
69329 trace_softirq_exit(vec_nr);
69330 if (unlikely(prev_count != preempt_count())) {
69331 printk(KERN_ERR "huh, entered softirq %u %s %p"
69332 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
69333 local_irq_restore(flags);
69334 }
69335
69336 -void open_softirq(int nr, void (*action)(struct softirq_action *))
69337 +void open_softirq(int nr, void (*action)(void))
69338 {
69339 - softirq_vec[nr].action = action;
69340 + pax_open_kernel();
69341 + *(void **)&softirq_vec[nr].action = action;
69342 + pax_close_kernel();
69343 }
69344
69345 /*
69346 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69347
69348 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69349
69350 -static void tasklet_action(struct softirq_action *a)
69351 +static void tasklet_action(void)
69352 {
69353 struct tasklet_struct *list;
69354
69355 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
69356 }
69357 }
69358
69359 -static void tasklet_hi_action(struct softirq_action *a)
69360 +static void tasklet_hi_action(void)
69361 {
69362 struct tasklet_struct *list;
69363
69364 diff --git a/kernel/sys.c b/kernel/sys.c
69365 index 888d227..f04b318 100644
69366 --- a/kernel/sys.c
69367 +++ b/kernel/sys.c
69368 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69369 error = -EACCES;
69370 goto out;
69371 }
69372 +
69373 + if (gr_handle_chroot_setpriority(p, niceval)) {
69374 + error = -EACCES;
69375 + goto out;
69376 + }
69377 +
69378 no_nice = security_task_setnice(p, niceval);
69379 if (no_nice) {
69380 error = no_nice;
69381 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69382 goto error;
69383 }
69384
69385 + if (gr_check_group_change(new->gid, new->egid, -1))
69386 + goto error;
69387 +
69388 if (rgid != (gid_t) -1 ||
69389 (egid != (gid_t) -1 && egid != old->gid))
69390 new->sgid = new->egid;
69391 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69392 old = current_cred();
69393
69394 retval = -EPERM;
69395 +
69396 + if (gr_check_group_change(gid, gid, gid))
69397 + goto error;
69398 +
69399 if (nsown_capable(CAP_SETGID))
69400 new->gid = new->egid = new->sgid = new->fsgid = gid;
69401 else if (gid == old->gid || gid == old->sgid)
69402 @@ -618,7 +631,7 @@ error:
69403 /*
69404 * change the user struct in a credentials set to match the new UID
69405 */
69406 -static int set_user(struct cred *new)
69407 +int set_user(struct cred *new)
69408 {
69409 struct user_struct *new_user;
69410
69411 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69412 goto error;
69413 }
69414
69415 + if (gr_check_user_change(new->uid, new->euid, -1))
69416 + goto error;
69417 +
69418 if (new->uid != old->uid) {
69419 retval = set_user(new);
69420 if (retval < 0)
69421 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69422 old = current_cred();
69423
69424 retval = -EPERM;
69425 +
69426 + if (gr_check_crash_uid(uid))
69427 + goto error;
69428 + if (gr_check_user_change(uid, uid, uid))
69429 + goto error;
69430 +
69431 if (nsown_capable(CAP_SETUID)) {
69432 new->suid = new->uid = uid;
69433 if (uid != old->uid) {
69434 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69435 goto error;
69436 }
69437
69438 + if (gr_check_user_change(ruid, euid, -1))
69439 + goto error;
69440 +
69441 if (ruid != (uid_t) -1) {
69442 new->uid = ruid;
69443 if (ruid != old->uid) {
69444 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69445 goto error;
69446 }
69447
69448 + if (gr_check_group_change(rgid, egid, -1))
69449 + goto error;
69450 +
69451 if (rgid != (gid_t) -1)
69452 new->gid = rgid;
69453 if (egid != (gid_t) -1)
69454 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69455 old = current_cred();
69456 old_fsuid = old->fsuid;
69457
69458 + if (gr_check_user_change(-1, -1, uid))
69459 + goto error;
69460 +
69461 if (uid == old->uid || uid == old->euid ||
69462 uid == old->suid || uid == old->fsuid ||
69463 nsown_capable(CAP_SETUID)) {
69464 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69465 }
69466 }
69467
69468 +error:
69469 abort_creds(new);
69470 return old_fsuid;
69471
69472 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69473 if (gid == old->gid || gid == old->egid ||
69474 gid == old->sgid || gid == old->fsgid ||
69475 nsown_capable(CAP_SETGID)) {
69476 + if (gr_check_group_change(-1, -1, gid))
69477 + goto error;
69478 +
69479 if (gid != old_fsgid) {
69480 new->fsgid = gid;
69481 goto change_okay;
69482 }
69483 }
69484
69485 +error:
69486 abort_creds(new);
69487 return old_fsgid;
69488
69489 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
69490 }
69491 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69492 snprintf(buf, len, "2.6.%u%s", v, rest);
69493 - ret = copy_to_user(release, buf, len);
69494 + if (len > sizeof(buf))
69495 + ret = -EFAULT;
69496 + else
69497 + ret = copy_to_user(release, buf, len);
69498 }
69499 return ret;
69500 }
69501 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69502 return -EFAULT;
69503
69504 down_read(&uts_sem);
69505 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
69506 + error = __copy_to_user(name->sysname, &utsname()->sysname,
69507 __OLD_UTS_LEN);
69508 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69509 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69510 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
69511 __OLD_UTS_LEN);
69512 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69513 - error |= __copy_to_user(&name->release, &utsname()->release,
69514 + error |= __copy_to_user(name->release, &utsname()->release,
69515 __OLD_UTS_LEN);
69516 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69517 - error |= __copy_to_user(&name->version, &utsname()->version,
69518 + error |= __copy_to_user(name->version, &utsname()->version,
69519 __OLD_UTS_LEN);
69520 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69521 - error |= __copy_to_user(&name->machine, &utsname()->machine,
69522 + error |= __copy_to_user(name->machine, &utsname()->machine,
69523 __OLD_UTS_LEN);
69524 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69525 up_read(&uts_sem);
69526 @@ -1838,7 +1877,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69527 error = get_dumpable(me->mm);
69528 break;
69529 case PR_SET_DUMPABLE:
69530 - if (arg2 < 0 || arg2 > 1) {
69531 + if (arg2 > 1) {
69532 error = -EINVAL;
69533 break;
69534 }
69535 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69536 index f03a6ef..5fcc8af 100644
69537 --- a/kernel/sysctl.c
69538 +++ b/kernel/sysctl.c
69539 @@ -86,6 +86,13 @@
69540
69541
69542 #if defined(CONFIG_SYSCTL)
69543 +#include <linux/grsecurity.h>
69544 +#include <linux/grinternal.h>
69545 +
69546 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
69547 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
69548 + const int op);
69549 +extern int gr_handle_chroot_sysctl(const int op);
69550
69551 /* External variables not in a header file. */
69552 extern int sysctl_overcommit_memory;
69553 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69554 }
69555
69556 #endif
69557 +extern struct ctl_table grsecurity_table[];
69558
69559 static struct ctl_table root_table[];
69560 static struct ctl_table_root sysctl_table_root;
69561 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
69562 int sysctl_legacy_va_layout;
69563 #endif
69564
69565 +#ifdef CONFIG_PAX_SOFTMODE
69566 +static ctl_table pax_table[] = {
69567 + {
69568 + .procname = "softmode",
69569 + .data = &pax_softmode,
69570 + .maxlen = sizeof(unsigned int),
69571 + .mode = 0600,
69572 + .proc_handler = &proc_dointvec,
69573 + },
69574 +
69575 + { }
69576 +};
69577 +#endif
69578 +
69579 /* The default sysctl tables: */
69580
69581 static struct ctl_table root_table[] = {
69582 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
69583 #endif
69584
69585 static struct ctl_table kern_table[] = {
69586 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69587 + {
69588 + .procname = "grsecurity",
69589 + .mode = 0500,
69590 + .child = grsecurity_table,
69591 + },
69592 +#endif
69593 +
69594 +#ifdef CONFIG_PAX_SOFTMODE
69595 + {
69596 + .procname = "pax",
69597 + .mode = 0500,
69598 + .child = pax_table,
69599 + },
69600 +#endif
69601 +
69602 {
69603 .procname = "sched_child_runs_first",
69604 .data = &sysctl_sched_child_runs_first,
69605 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
69606 .data = &modprobe_path,
69607 .maxlen = KMOD_PATH_LEN,
69608 .mode = 0644,
69609 - .proc_handler = proc_dostring,
69610 + .proc_handler = proc_dostring_modpriv,
69611 },
69612 {
69613 .procname = "modules_disabled",
69614 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
69615 .extra1 = &zero,
69616 .extra2 = &one,
69617 },
69618 +#endif
69619 {
69620 .procname = "kptr_restrict",
69621 .data = &kptr_restrict,
69622 .maxlen = sizeof(int),
69623 .mode = 0644,
69624 .proc_handler = proc_dointvec_minmax_sysadmin,
69625 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69626 + .extra1 = &two,
69627 +#else
69628 .extra1 = &zero,
69629 +#endif
69630 .extra2 = &two,
69631 },
69632 -#endif
69633 {
69634 .procname = "ngroups_max",
69635 .data = &ngroups_max,
69636 @@ -1225,6 +1267,13 @@ static struct ctl_table vm_table[] = {
69637 .proc_handler = proc_dointvec_minmax,
69638 .extra1 = &zero,
69639 },
69640 + {
69641 + .procname = "heap_stack_gap",
69642 + .data = &sysctl_heap_stack_gap,
69643 + .maxlen = sizeof(sysctl_heap_stack_gap),
69644 + .mode = 0644,
69645 + .proc_handler = proc_doulongvec_minmax,
69646 + },
69647 #else
69648 {
69649 .procname = "nr_trim_pages",
69650 @@ -1729,6 +1778,17 @@ static int test_perm(int mode, int op)
69651 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
69652 {
69653 int mode;
69654 + int error;
69655 +
69656 + if (table->parent != NULL && table->parent->procname != NULL &&
69657 + table->procname != NULL &&
69658 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
69659 + return -EACCES;
69660 + if (gr_handle_chroot_sysctl(op))
69661 + return -EACCES;
69662 + error = gr_handle_sysctl(table, op);
69663 + if (error)
69664 + return error;
69665
69666 if (root->permissions)
69667 mode = root->permissions(root, current->nsproxy, table);
69668 @@ -2133,6 +2193,16 @@ int proc_dostring(struct ctl_table *table, int write,
69669 buffer, lenp, ppos);
69670 }
69671
69672 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69673 + void __user *buffer, size_t *lenp, loff_t *ppos)
69674 +{
69675 + if (write && !capable(CAP_SYS_MODULE))
69676 + return -EPERM;
69677 +
69678 + return _proc_do_string(table->data, table->maxlen, write,
69679 + buffer, lenp, ppos);
69680 +}
69681 +
69682 static size_t proc_skip_spaces(char **buf)
69683 {
69684 size_t ret;
69685 @@ -2238,6 +2308,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69686 len = strlen(tmp);
69687 if (len > *size)
69688 len = *size;
69689 + if (len > sizeof(tmp))
69690 + len = sizeof(tmp);
69691 if (copy_to_user(*buf, tmp, len))
69692 return -EFAULT;
69693 *size -= len;
69694 @@ -2554,8 +2626,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69695 *i = val;
69696 } else {
69697 val = convdiv * (*i) / convmul;
69698 - if (!first)
69699 + if (!first) {
69700 err = proc_put_char(&buffer, &left, '\t');
69701 + if (err)
69702 + break;
69703 + }
69704 err = proc_put_long(&buffer, &left, val, false);
69705 if (err)
69706 break;
69707 @@ -2950,6 +3025,12 @@ int proc_dostring(struct ctl_table *table, int write,
69708 return -ENOSYS;
69709 }
69710
69711 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69712 + void __user *buffer, size_t *lenp, loff_t *ppos)
69713 +{
69714 + return -ENOSYS;
69715 +}
69716 +
69717 int proc_dointvec(struct ctl_table *table, int write,
69718 void __user *buffer, size_t *lenp, loff_t *ppos)
69719 {
69720 @@ -3006,6 +3087,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69721 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69722 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69723 EXPORT_SYMBOL(proc_dostring);
69724 +EXPORT_SYMBOL(proc_dostring_modpriv);
69725 EXPORT_SYMBOL(proc_doulongvec_minmax);
69726 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69727 EXPORT_SYMBOL(register_sysctl_table);
69728 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69729 index a650694..aaeeb20 100644
69730 --- a/kernel/sysctl_binary.c
69731 +++ b/kernel/sysctl_binary.c
69732 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69733 int i;
69734
69735 set_fs(KERNEL_DS);
69736 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69737 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69738 set_fs(old_fs);
69739 if (result < 0)
69740 goto out_kfree;
69741 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69742 }
69743
69744 set_fs(KERNEL_DS);
69745 - result = vfs_write(file, buffer, str - buffer, &pos);
69746 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69747 set_fs(old_fs);
69748 if (result < 0)
69749 goto out_kfree;
69750 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69751 int i;
69752
69753 set_fs(KERNEL_DS);
69754 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69755 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69756 set_fs(old_fs);
69757 if (result < 0)
69758 goto out_kfree;
69759 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69760 }
69761
69762 set_fs(KERNEL_DS);
69763 - result = vfs_write(file, buffer, str - buffer, &pos);
69764 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69765 set_fs(old_fs);
69766 if (result < 0)
69767 goto out_kfree;
69768 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69769 int i;
69770
69771 set_fs(KERNEL_DS);
69772 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69773 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69774 set_fs(old_fs);
69775 if (result < 0)
69776 goto out;
69777 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69778 __le16 dnaddr;
69779
69780 set_fs(KERNEL_DS);
69781 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69782 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69783 set_fs(old_fs);
69784 if (result < 0)
69785 goto out;
69786 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69787 le16_to_cpu(dnaddr) & 0x3ff);
69788
69789 set_fs(KERNEL_DS);
69790 - result = vfs_write(file, buf, len, &pos);
69791 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69792 set_fs(old_fs);
69793 if (result < 0)
69794 goto out;
69795 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
69796 index 362da65..ab8ef8c 100644
69797 --- a/kernel/sysctl_check.c
69798 +++ b/kernel/sysctl_check.c
69799 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
69800 set_fail(&fail, table, "Directory with extra2");
69801 } else {
69802 if ((table->proc_handler == proc_dostring) ||
69803 + (table->proc_handler == proc_dostring_modpriv) ||
69804 (table->proc_handler == proc_dointvec) ||
69805 (table->proc_handler == proc_dointvec_minmax) ||
69806 (table->proc_handler == proc_dointvec_jiffies) ||
69807 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69808 index e660464..c8b9e67 100644
69809 --- a/kernel/taskstats.c
69810 +++ b/kernel/taskstats.c
69811 @@ -27,9 +27,12 @@
69812 #include <linux/cgroup.h>
69813 #include <linux/fs.h>
69814 #include <linux/file.h>
69815 +#include <linux/grsecurity.h>
69816 #include <net/genetlink.h>
69817 #include <linux/atomic.h>
69818
69819 +extern int gr_is_taskstats_denied(int pid);
69820 +
69821 /*
69822 * Maximum length of a cpumask that can be specified in
69823 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69824 @@ -556,6 +559,9 @@ err:
69825
69826 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69827 {
69828 + if (gr_is_taskstats_denied(current->pid))
69829 + return -EACCES;
69830 +
69831 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69832 return cmd_attr_register_cpumask(info);
69833 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69834 diff --git a/kernel/time.c b/kernel/time.c
69835 index 73e416d..cfc6f69 100644
69836 --- a/kernel/time.c
69837 +++ b/kernel/time.c
69838 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69839 return error;
69840
69841 if (tz) {
69842 + /* we log in do_settimeofday called below, so don't log twice
69843 + */
69844 + if (!tv)
69845 + gr_log_timechange();
69846 +
69847 /* SMP safe, global irq locking makes it work. */
69848 sys_tz = *tz;
69849 update_vsyscall_tz();
69850 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69851 index 8a46f5d..bbe6f9c 100644
69852 --- a/kernel/time/alarmtimer.c
69853 +++ b/kernel/time/alarmtimer.c
69854 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
69855 struct platform_device *pdev;
69856 int error = 0;
69857 int i;
69858 - struct k_clock alarm_clock = {
69859 + static struct k_clock alarm_clock = {
69860 .clock_getres = alarm_clock_getres,
69861 .clock_get = alarm_clock_get,
69862 .timer_create = alarm_timer_create,
69863 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69864 index fd4a7b1..fae5c2a 100644
69865 --- a/kernel/time/tick-broadcast.c
69866 +++ b/kernel/time/tick-broadcast.c
69867 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69868 * then clear the broadcast bit.
69869 */
69870 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69871 - int cpu = smp_processor_id();
69872 + cpu = smp_processor_id();
69873
69874 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69875 tick_broadcast_clear_oneshot(cpu);
69876 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69877 index 0c63581..e25dcb6 100644
69878 --- a/kernel/time/timekeeping.c
69879 +++ b/kernel/time/timekeeping.c
69880 @@ -14,6 +14,7 @@
69881 #include <linux/init.h>
69882 #include <linux/mm.h>
69883 #include <linux/sched.h>
69884 +#include <linux/grsecurity.h>
69885 #include <linux/syscore_ops.h>
69886 #include <linux/clocksource.h>
69887 #include <linux/jiffies.h>
69888 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
69889 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69890 return -EINVAL;
69891
69892 + gr_log_timechange();
69893 +
69894 write_seqlock_irqsave(&xtime_lock, flags);
69895
69896 timekeeping_forward_now();
69897 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69898 index 3258455..f35227d 100644
69899 --- a/kernel/time/timer_list.c
69900 +++ b/kernel/time/timer_list.c
69901 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69902
69903 static void print_name_offset(struct seq_file *m, void *sym)
69904 {
69905 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69906 + SEQ_printf(m, "<%p>", NULL);
69907 +#else
69908 char symname[KSYM_NAME_LEN];
69909
69910 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69911 SEQ_printf(m, "<%pK>", sym);
69912 else
69913 SEQ_printf(m, "%s", symname);
69914 +#endif
69915 }
69916
69917 static void
69918 @@ -112,7 +116,11 @@ next_one:
69919 static void
69920 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69921 {
69922 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69923 + SEQ_printf(m, " .base: %p\n", NULL);
69924 +#else
69925 SEQ_printf(m, " .base: %pK\n", base);
69926 +#endif
69927 SEQ_printf(m, " .index: %d\n",
69928 base->index);
69929 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69930 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69931 {
69932 struct proc_dir_entry *pe;
69933
69934 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69935 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69936 +#else
69937 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69938 +#endif
69939 if (!pe)
69940 return -ENOMEM;
69941 return 0;
69942 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
69943 index 0b537f2..9e71eca 100644
69944 --- a/kernel/time/timer_stats.c
69945 +++ b/kernel/time/timer_stats.c
69946 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
69947 static unsigned long nr_entries;
69948 static struct entry entries[MAX_ENTRIES];
69949
69950 -static atomic_t overflow_count;
69951 +static atomic_unchecked_t overflow_count;
69952
69953 /*
69954 * The entries are in a hash-table, for fast lookup:
69955 @@ -140,7 +140,7 @@ static void reset_entries(void)
69956 nr_entries = 0;
69957 memset(entries, 0, sizeof(entries));
69958 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
69959 - atomic_set(&overflow_count, 0);
69960 + atomic_set_unchecked(&overflow_count, 0);
69961 }
69962
69963 static struct entry *alloc_entry(void)
69964 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69965 if (likely(entry))
69966 entry->count++;
69967 else
69968 - atomic_inc(&overflow_count);
69969 + atomic_inc_unchecked(&overflow_count);
69970
69971 out_unlock:
69972 raw_spin_unlock_irqrestore(lock, flags);
69973 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69974
69975 static void print_name_offset(struct seq_file *m, unsigned long addr)
69976 {
69977 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69978 + seq_printf(m, "<%p>", NULL);
69979 +#else
69980 char symname[KSYM_NAME_LEN];
69981
69982 if (lookup_symbol_name(addr, symname) < 0)
69983 seq_printf(m, "<%p>", (void *)addr);
69984 else
69985 seq_printf(m, "%s", symname);
69986 +#endif
69987 }
69988
69989 static int tstats_show(struct seq_file *m, void *v)
69990 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
69991
69992 seq_puts(m, "Timer Stats Version: v0.2\n");
69993 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
69994 - if (atomic_read(&overflow_count))
69995 + if (atomic_read_unchecked(&overflow_count))
69996 seq_printf(m, "Overflow: %d entries\n",
69997 - atomic_read(&overflow_count));
69998 + atomic_read_unchecked(&overflow_count));
69999
70000 for (i = 0; i < nr_entries; i++) {
70001 entry = entries + i;
70002 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70003 {
70004 struct proc_dir_entry *pe;
70005
70006 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70007 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70008 +#else
70009 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70010 +#endif
70011 if (!pe)
70012 return -ENOMEM;
70013 return 0;
70014 diff --git a/kernel/timer.c b/kernel/timer.c
70015 index a297ffc..5e16b0b 100644
70016 --- a/kernel/timer.c
70017 +++ b/kernel/timer.c
70018 @@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
70019 /*
70020 * This function runs timers and the timer-tq in bottom half context.
70021 */
70022 -static void run_timer_softirq(struct softirq_action *h)
70023 +static void run_timer_softirq(void)
70024 {
70025 struct tvec_base *base = __this_cpu_read(tvec_bases);
70026
70027 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70028 index cdea7b5..9b820d4 100644
70029 --- a/kernel/trace/blktrace.c
70030 +++ b/kernel/trace/blktrace.c
70031 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70032 struct blk_trace *bt = filp->private_data;
70033 char buf[16];
70034
70035 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70036 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70037
70038 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70039 }
70040 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70041 return 1;
70042
70043 bt = buf->chan->private_data;
70044 - atomic_inc(&bt->dropped);
70045 + atomic_inc_unchecked(&bt->dropped);
70046 return 0;
70047 }
70048
70049 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70050
70051 bt->dir = dir;
70052 bt->dev = dev;
70053 - atomic_set(&bt->dropped, 0);
70054 + atomic_set_unchecked(&bt->dropped, 0);
70055
70056 ret = -EIO;
70057 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70058 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70059 index 683d559..d70d914 100644
70060 --- a/kernel/trace/ftrace.c
70061 +++ b/kernel/trace/ftrace.c
70062 @@ -1726,12 +1726,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70063 if (unlikely(ftrace_disabled))
70064 return 0;
70065
70066 + ret = ftrace_arch_code_modify_prepare();
70067 + FTRACE_WARN_ON(ret);
70068 + if (ret)
70069 + return 0;
70070 +
70071 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70072 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70073 if (ret) {
70074 ftrace_bug(ret, ip);
70075 - return 0;
70076 }
70077 - return 1;
70078 + return ret ? 0 : 1;
70079 }
70080
70081 /*
70082 @@ -2843,7 +2848,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70083
70084 int
70085 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70086 - void *data)
70087 + void *data)
70088 {
70089 struct ftrace_func_probe *entry;
70090 struct ftrace_page *pg;
70091 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70092 index c4579f1..6a439da 100644
70093 --- a/kernel/trace/trace.c
70094 +++ b/kernel/trace/trace.c
70095 @@ -4258,10 +4258,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70096 };
70097 #endif
70098
70099 -static struct dentry *d_tracer;
70100 -
70101 struct dentry *tracing_init_dentry(void)
70102 {
70103 + static struct dentry *d_tracer;
70104 static int once;
70105
70106 if (d_tracer)
70107 @@ -4281,10 +4280,9 @@ struct dentry *tracing_init_dentry(void)
70108 return d_tracer;
70109 }
70110
70111 -static struct dentry *d_percpu;
70112 -
70113 struct dentry *tracing_dentry_percpu(void)
70114 {
70115 + static struct dentry *d_percpu;
70116 static int once;
70117 struct dentry *d_tracer;
70118
70119 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70120 index c212a7f..7b02394 100644
70121 --- a/kernel/trace/trace_events.c
70122 +++ b/kernel/trace/trace_events.c
70123 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
70124 struct ftrace_module_file_ops {
70125 struct list_head list;
70126 struct module *mod;
70127 - struct file_operations id;
70128 - struct file_operations enable;
70129 - struct file_operations format;
70130 - struct file_operations filter;
70131 };
70132
70133 static struct ftrace_module_file_ops *
70134 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
70135
70136 file_ops->mod = mod;
70137
70138 - file_ops->id = ftrace_event_id_fops;
70139 - file_ops->id.owner = mod;
70140 -
70141 - file_ops->enable = ftrace_enable_fops;
70142 - file_ops->enable.owner = mod;
70143 -
70144 - file_ops->filter = ftrace_event_filter_fops;
70145 - file_ops->filter.owner = mod;
70146 -
70147 - file_ops->format = ftrace_event_format_fops;
70148 - file_ops->format.owner = mod;
70149 + pax_open_kernel();
70150 + *(void **)&mod->trace_id.owner = mod;
70151 + *(void **)&mod->trace_enable.owner = mod;
70152 + *(void **)&mod->trace_filter.owner = mod;
70153 + *(void **)&mod->trace_format.owner = mod;
70154 + pax_close_kernel();
70155
70156 list_add(&file_ops->list, &ftrace_module_file_list);
70157
70158 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
70159
70160 for_each_event(call, start, end) {
70161 __trace_add_event_call(*call, mod,
70162 - &file_ops->id, &file_ops->enable,
70163 - &file_ops->filter, &file_ops->format);
70164 + &mod->trace_id, &mod->trace_enable,
70165 + &mod->trace_filter, &mod->trace_format);
70166 }
70167 }
70168
70169 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
70170 index 00d527c..7c5b1a3 100644
70171 --- a/kernel/trace/trace_kprobe.c
70172 +++ b/kernel/trace/trace_kprobe.c
70173 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
70174 long ret;
70175 int maxlen = get_rloc_len(*(u32 *)dest);
70176 u8 *dst = get_rloc_data(dest);
70177 - u8 *src = addr;
70178 + const u8 __user *src = (const u8 __force_user *)addr;
70179 mm_segment_t old_fs = get_fs();
70180 if (!maxlen)
70181 return;
70182 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
70183 pagefault_disable();
70184 do
70185 ret = __copy_from_user_inatomic(dst++, src++, 1);
70186 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
70187 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
70188 dst[-1] = '\0';
70189 pagefault_enable();
70190 set_fs(old_fs);
70191 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
70192 ((u8 *)get_rloc_data(dest))[0] = '\0';
70193 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
70194 } else
70195 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
70196 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
70197 get_rloc_offs(*(u32 *)dest));
70198 }
70199 /* Return the length of string -- including null terminal byte */
70200 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
70201 set_fs(KERNEL_DS);
70202 pagefault_disable();
70203 do {
70204 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
70205 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
70206 len++;
70207 } while (c && ret == 0 && len < MAX_STRING_SIZE);
70208 pagefault_enable();
70209 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70210 index fd3c8aa..5f324a6 100644
70211 --- a/kernel/trace/trace_mmiotrace.c
70212 +++ b/kernel/trace/trace_mmiotrace.c
70213 @@ -24,7 +24,7 @@ struct header_iter {
70214 static struct trace_array *mmio_trace_array;
70215 static bool overrun_detected;
70216 static unsigned long prev_overruns;
70217 -static atomic_t dropped_count;
70218 +static atomic_unchecked_t dropped_count;
70219
70220 static void mmio_reset_data(struct trace_array *tr)
70221 {
70222 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70223
70224 static unsigned long count_overruns(struct trace_iterator *iter)
70225 {
70226 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70227 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70228 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70229
70230 if (over > prev_overruns)
70231 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70232 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70233 sizeof(*entry), 0, pc);
70234 if (!event) {
70235 - atomic_inc(&dropped_count);
70236 + atomic_inc_unchecked(&dropped_count);
70237 return;
70238 }
70239 entry = ring_buffer_event_data(event);
70240 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70241 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70242 sizeof(*entry), 0, pc);
70243 if (!event) {
70244 - atomic_inc(&dropped_count);
70245 + atomic_inc_unchecked(&dropped_count);
70246 return;
70247 }
70248 entry = ring_buffer_event_data(event);
70249 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70250 index d9c07f0..c1eeceb 100644
70251 --- a/kernel/trace/trace_output.c
70252 +++ b/kernel/trace/trace_output.c
70253 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
70254
70255 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70256 if (!IS_ERR(p)) {
70257 - p = mangle_path(s->buffer + s->len, p, "\n");
70258 + p = mangle_path(s->buffer + s->len, p, "\n\\");
70259 if (p) {
70260 s->len = p - s->buffer;
70261 return 1;
70262 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70263 index d4545f4..a9010a1 100644
70264 --- a/kernel/trace/trace_stack.c
70265 +++ b/kernel/trace/trace_stack.c
70266 @@ -53,7 +53,7 @@ static inline void check_stack(void)
70267 return;
70268
70269 /* we do not handle interrupt stacks yet */
70270 - if (!object_is_on_stack(&this_size))
70271 + if (!object_starts_on_stack(&this_size))
70272 return;
70273
70274 local_irq_save(flags);
70275 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
70276 index 209b379..7f76423 100644
70277 --- a/kernel/trace/trace_workqueue.c
70278 +++ b/kernel/trace/trace_workqueue.c
70279 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
70280 int cpu;
70281 pid_t pid;
70282 /* Can be inserted from interrupt or user context, need to be atomic */
70283 - atomic_t inserted;
70284 + atomic_unchecked_t inserted;
70285 /*
70286 * Don't need to be atomic, works are serialized in a single workqueue thread
70287 * on a single CPU.
70288 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
70289 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
70290 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
70291 if (node->pid == wq_thread->pid) {
70292 - atomic_inc(&node->inserted);
70293 + atomic_inc_unchecked(&node->inserted);
70294 goto found;
70295 }
70296 }
70297 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
70298 tsk = get_pid_task(pid, PIDTYPE_PID);
70299 if (tsk) {
70300 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
70301 - atomic_read(&cws->inserted), cws->executed,
70302 + atomic_read_unchecked(&cws->inserted), cws->executed,
70303 tsk->comm);
70304 put_task_struct(tsk);
70305 }
70306 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70307 index 8745ac7..d144e37 100644
70308 --- a/lib/Kconfig.debug
70309 +++ b/lib/Kconfig.debug
70310 @@ -1103,6 +1103,7 @@ config LATENCYTOP
70311 depends on DEBUG_KERNEL
70312 depends on STACKTRACE_SUPPORT
70313 depends on PROC_FS
70314 + depends on !GRKERNSEC_HIDESYM
70315 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70316 select KALLSYMS
70317 select KALLSYMS_ALL
70318 diff --git a/lib/bitmap.c b/lib/bitmap.c
70319 index 0d4a127..33a06c7 100644
70320 --- a/lib/bitmap.c
70321 +++ b/lib/bitmap.c
70322 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70323 {
70324 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70325 u32 chunk;
70326 - const char __user __force *ubuf = (const char __user __force *)buf;
70327 + const char __user *ubuf = (const char __force_user *)buf;
70328
70329 bitmap_zero(maskp, nmaskbits);
70330
70331 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
70332 {
70333 if (!access_ok(VERIFY_READ, ubuf, ulen))
70334 return -EFAULT;
70335 - return __bitmap_parse((const char __force *)ubuf,
70336 + return __bitmap_parse((const char __force_kernel *)ubuf,
70337 ulen, 1, maskp, nmaskbits);
70338
70339 }
70340 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70341 {
70342 unsigned a, b;
70343 int c, old_c, totaldigits;
70344 - const char __user __force *ubuf = (const char __user __force *)buf;
70345 + const char __user *ubuf = (const char __force_user *)buf;
70346 int exp_digit, in_range;
70347
70348 totaldigits = c = 0;
70349 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70350 {
70351 if (!access_ok(VERIFY_READ, ubuf, ulen))
70352 return -EFAULT;
70353 - return __bitmap_parselist((const char __force *)ubuf,
70354 + return __bitmap_parselist((const char __force_kernel *)ubuf,
70355 ulen, 1, maskp, nmaskbits);
70356 }
70357 EXPORT_SYMBOL(bitmap_parselist_user);
70358 diff --git a/lib/bug.c b/lib/bug.c
70359 index a28c141..2bd3d95 100644
70360 --- a/lib/bug.c
70361 +++ b/lib/bug.c
70362 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70363 return BUG_TRAP_TYPE_NONE;
70364
70365 bug = find_bug(bugaddr);
70366 + if (!bug)
70367 + return BUG_TRAP_TYPE_NONE;
70368
70369 file = NULL;
70370 line = 0;
70371 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70372 index 0ab9ae8..f01ceca 100644
70373 --- a/lib/debugobjects.c
70374 +++ b/lib/debugobjects.c
70375 @@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70376 if (limit > 4)
70377 return;
70378
70379 - is_on_stack = object_is_on_stack(addr);
70380 + is_on_stack = object_starts_on_stack(addr);
70381 if (is_on_stack == onstack)
70382 return;
70383
70384 diff --git a/lib/devres.c b/lib/devres.c
70385 index 9676617..5149e15 100644
70386 --- a/lib/devres.c
70387 +++ b/lib/devres.c
70388 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70389 void devm_iounmap(struct device *dev, void __iomem *addr)
70390 {
70391 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70392 - (void *)addr));
70393 + (void __force *)addr));
70394 iounmap(addr);
70395 }
70396 EXPORT_SYMBOL(devm_iounmap);
70397 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70398 {
70399 ioport_unmap(addr);
70400 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70401 - devm_ioport_map_match, (void *)addr));
70402 + devm_ioport_map_match, (void __force *)addr));
70403 }
70404 EXPORT_SYMBOL(devm_ioport_unmap);
70405
70406 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70407 index fea790a..ebb0e82 100644
70408 --- a/lib/dma-debug.c
70409 +++ b/lib/dma-debug.c
70410 @@ -925,7 +925,7 @@ out:
70411
70412 static void check_for_stack(struct device *dev, void *addr)
70413 {
70414 - if (object_is_on_stack(addr))
70415 + if (object_starts_on_stack(addr))
70416 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70417 "stack [addr=%p]\n", addr);
70418 }
70419 diff --git a/lib/extable.c b/lib/extable.c
70420 index 4cac81e..63e9b8f 100644
70421 --- a/lib/extable.c
70422 +++ b/lib/extable.c
70423 @@ -13,6 +13,7 @@
70424 #include <linux/init.h>
70425 #include <linux/sort.h>
70426 #include <asm/uaccess.h>
70427 +#include <asm/pgtable.h>
70428
70429 #ifndef ARCH_HAS_SORT_EXTABLE
70430 /*
70431 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
70432 void sort_extable(struct exception_table_entry *start,
70433 struct exception_table_entry *finish)
70434 {
70435 + pax_open_kernel();
70436 sort(start, finish - start, sizeof(struct exception_table_entry),
70437 cmp_ex, NULL);
70438 + pax_close_kernel();
70439 }
70440
70441 #ifdef CONFIG_MODULES
70442 diff --git a/lib/inflate.c b/lib/inflate.c
70443 index 013a761..c28f3fc 100644
70444 --- a/lib/inflate.c
70445 +++ b/lib/inflate.c
70446 @@ -269,7 +269,7 @@ static void free(void *where)
70447 malloc_ptr = free_mem_ptr;
70448 }
70449 #else
70450 -#define malloc(a) kmalloc(a, GFP_KERNEL)
70451 +#define malloc(a) kmalloc((a), GFP_KERNEL)
70452 #define free(a) kfree(a)
70453 #endif
70454
70455 diff --git a/lib/ioremap.c b/lib/ioremap.c
70456 index da4e2ad..6373b5f 100644
70457 --- a/lib/ioremap.c
70458 +++ b/lib/ioremap.c
70459 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
70460 unsigned long next;
70461
70462 phys_addr -= addr;
70463 - pmd = pmd_alloc(&init_mm, pud, addr);
70464 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
70465 if (!pmd)
70466 return -ENOMEM;
70467 do {
70468 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
70469 unsigned long next;
70470
70471 phys_addr -= addr;
70472 - pud = pud_alloc(&init_mm, pgd, addr);
70473 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
70474 if (!pud)
70475 return -ENOMEM;
70476 do {
70477 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70478 index bd2bea9..6b3c95e 100644
70479 --- a/lib/is_single_threaded.c
70480 +++ b/lib/is_single_threaded.c
70481 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70482 struct task_struct *p, *t;
70483 bool ret;
70484
70485 + if (!mm)
70486 + return true;
70487 +
70488 if (atomic_read(&task->signal->live) != 1)
70489 return false;
70490
70491 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70492 index dc63d08..95ae14a 100644
70493 --- a/lib/radix-tree.c
70494 +++ b/lib/radix-tree.c
70495 @@ -78,7 +78,7 @@ struct radix_tree_preload {
70496 int nr;
70497 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
70498 };
70499 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70500 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70501
70502 static inline void *ptr_to_indirect(void *ptr)
70503 {
70504 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70505 index 38e612e..4fb99a8 100644
70506 --- a/lib/vsprintf.c
70507 +++ b/lib/vsprintf.c
70508 @@ -16,6 +16,9 @@
70509 * - scnprintf and vscnprintf
70510 */
70511
70512 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70513 +#define __INCLUDED_BY_HIDESYM 1
70514 +#endif
70515 #include <stdarg.h>
70516 #include <linux/module.h>
70517 #include <linux/types.h>
70518 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70519 char sym[KSYM_SYMBOL_LEN];
70520 if (ext == 'B')
70521 sprint_backtrace(sym, value);
70522 - else if (ext != 'f' && ext != 's')
70523 + else if (ext != 'f' && ext != 's' && ext != 'a')
70524 sprint_symbol(sym, value);
70525 else
70526 kallsyms_lookup(value, NULL, NULL, NULL, sym);
70527 @@ -789,7 +792,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70528 return number(buf, end, *(const netdev_features_t *)addr, spec);
70529 }
70530
70531 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70532 +int kptr_restrict __read_mostly = 2;
70533 +#else
70534 int kptr_restrict __read_mostly;
70535 +#endif
70536
70537 /*
70538 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70539 @@ -803,6 +810,8 @@ int kptr_restrict __read_mostly;
70540 * - 'S' For symbolic direct pointers with offset
70541 * - 's' For symbolic direct pointers without offset
70542 * - 'B' For backtraced symbolic direct pointers with offset
70543 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70544 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70545 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70546 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70547 * - 'M' For a 6-byte MAC address, it prints the address in the
70548 @@ -848,12 +857,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70549 {
70550 if (!ptr && *fmt != 'K') {
70551 /*
70552 - * Print (null) with the same width as a pointer so it makes
70553 + * Print (nil) with the same width as a pointer so it makes
70554 * tabular output look nice.
70555 */
70556 if (spec.field_width == -1)
70557 spec.field_width = 2 * sizeof(void *);
70558 - return string(buf, end, "(null)", spec);
70559 + return string(buf, end, "(nil)", spec);
70560 }
70561
70562 switch (*fmt) {
70563 @@ -863,6 +872,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70564 /* Fallthrough */
70565 case 'S':
70566 case 's':
70567 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70568 + break;
70569 +#else
70570 + return symbol_string(buf, end, ptr, spec, *fmt);
70571 +#endif
70572 + case 'A':
70573 + case 'a':
70574 case 'B':
70575 return symbol_string(buf, end, ptr, spec, *fmt);
70576 case 'R':
70577 @@ -1633,11 +1649,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70578 typeof(type) value; \
70579 if (sizeof(type) == 8) { \
70580 args = PTR_ALIGN(args, sizeof(u32)); \
70581 - *(u32 *)&value = *(u32 *)args; \
70582 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70583 + *(u32 *)&value = *(const u32 *)args; \
70584 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70585 } else { \
70586 args = PTR_ALIGN(args, sizeof(type)); \
70587 - value = *(typeof(type) *)args; \
70588 + value = *(const typeof(type) *)args; \
70589 } \
70590 args += sizeof(type); \
70591 value; \
70592 @@ -1700,7 +1716,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70593 case FORMAT_TYPE_STR: {
70594 const char *str_arg = args;
70595 args += strlen(str_arg) + 1;
70596 - str = string(str, end, (char *)str_arg, spec);
70597 + str = string(str, end, str_arg, spec);
70598 break;
70599 }
70600
70601 diff --git a/localversion-grsec b/localversion-grsec
70602 new file mode 100644
70603 index 0000000..7cd6065
70604 --- /dev/null
70605 +++ b/localversion-grsec
70606 @@ -0,0 +1 @@
70607 +-grsec
70608 diff --git a/mm/Kconfig b/mm/Kconfig
70609 index e338407..49b5b7a 100644
70610 --- a/mm/Kconfig
70611 +++ b/mm/Kconfig
70612 @@ -247,10 +247,10 @@ config KSM
70613 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70614
70615 config DEFAULT_MMAP_MIN_ADDR
70616 - int "Low address space to protect from user allocation"
70617 + int "Low address space to protect from user allocation"
70618 depends on MMU
70619 - default 4096
70620 - help
70621 + default 65536
70622 + help
70623 This is the portion of low virtual memory which should be protected
70624 from userspace allocation. Keeping a user from writing to low pages
70625 can help reduce the impact of kernel NULL pointer bugs.
70626 diff --git a/mm/filemap.c b/mm/filemap.c
70627 index b662757..3081ddd 100644
70628 --- a/mm/filemap.c
70629 +++ b/mm/filemap.c
70630 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70631 struct address_space *mapping = file->f_mapping;
70632
70633 if (!mapping->a_ops->readpage)
70634 - return -ENOEXEC;
70635 + return -ENODEV;
70636 file_accessed(file);
70637 vma->vm_ops = &generic_file_vm_ops;
70638 vma->vm_flags |= VM_CAN_NONLINEAR;
70639 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70640 *pos = i_size_read(inode);
70641
70642 if (limit != RLIM_INFINITY) {
70643 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70644 if (*pos >= limit) {
70645 send_sig(SIGXFSZ, current, 0);
70646 return -EFBIG;
70647 diff --git a/mm/fremap.c b/mm/fremap.c
70648 index 9ed4fd4..c42648d 100644
70649 --- a/mm/fremap.c
70650 +++ b/mm/fremap.c
70651 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70652 retry:
70653 vma = find_vma(mm, start);
70654
70655 +#ifdef CONFIG_PAX_SEGMEXEC
70656 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70657 + goto out;
70658 +#endif
70659 +
70660 /*
70661 * Make sure the vma is shared, that it supports prefaulting,
70662 * and that the remapped range is valid and fully within
70663 diff --git a/mm/highmem.c b/mm/highmem.c
70664 index 57d82c6..e9e0552 100644
70665 --- a/mm/highmem.c
70666 +++ b/mm/highmem.c
70667 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70668 * So no dangers, even with speculative execution.
70669 */
70670 page = pte_page(pkmap_page_table[i]);
70671 + pax_open_kernel();
70672 pte_clear(&init_mm, (unsigned long)page_address(page),
70673 &pkmap_page_table[i]);
70674 -
70675 + pax_close_kernel();
70676 set_page_address(page, NULL);
70677 need_flush = 1;
70678 }
70679 @@ -186,9 +187,11 @@ start:
70680 }
70681 }
70682 vaddr = PKMAP_ADDR(last_pkmap_nr);
70683 +
70684 + pax_open_kernel();
70685 set_pte_at(&init_mm, vaddr,
70686 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70687 -
70688 + pax_close_kernel();
70689 pkmap_count[last_pkmap_nr] = 1;
70690 set_page_address(page, (void *)vaddr);
70691
70692 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70693 index 8f7fc39..69bf1e9 100644
70694 --- a/mm/huge_memory.c
70695 +++ b/mm/huge_memory.c
70696 @@ -733,7 +733,7 @@ out:
70697 * run pte_offset_map on the pmd, if an huge pmd could
70698 * materialize from under us from a different thread.
70699 */
70700 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70701 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70702 return VM_FAULT_OOM;
70703 /* if an huge pmd materialized from under us just retry later */
70704 if (unlikely(pmd_trans_huge(*pmd)))
70705 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70706 index a7cf829..d60e0e1 100644
70707 --- a/mm/hugetlb.c
70708 +++ b/mm/hugetlb.c
70709 @@ -2346,6 +2346,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70710 return 1;
70711 }
70712
70713 +#ifdef CONFIG_PAX_SEGMEXEC
70714 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70715 +{
70716 + struct mm_struct *mm = vma->vm_mm;
70717 + struct vm_area_struct *vma_m;
70718 + unsigned long address_m;
70719 + pte_t *ptep_m;
70720 +
70721 + vma_m = pax_find_mirror_vma(vma);
70722 + if (!vma_m)
70723 + return;
70724 +
70725 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70726 + address_m = address + SEGMEXEC_TASK_SIZE;
70727 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70728 + get_page(page_m);
70729 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
70730 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70731 +}
70732 +#endif
70733 +
70734 /*
70735 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70736 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70737 @@ -2459,6 +2480,11 @@ retry_avoidcopy:
70738 make_huge_pte(vma, new_page, 1));
70739 page_remove_rmap(old_page);
70740 hugepage_add_new_anon_rmap(new_page, vma, address);
70741 +
70742 +#ifdef CONFIG_PAX_SEGMEXEC
70743 + pax_mirror_huge_pte(vma, address, new_page);
70744 +#endif
70745 +
70746 /* Make the old page be freed below */
70747 new_page = old_page;
70748 mmu_notifier_invalidate_range_end(mm,
70749 @@ -2613,6 +2639,10 @@ retry:
70750 && (vma->vm_flags & VM_SHARED)));
70751 set_huge_pte_at(mm, address, ptep, new_pte);
70752
70753 +#ifdef CONFIG_PAX_SEGMEXEC
70754 + pax_mirror_huge_pte(vma, address, page);
70755 +#endif
70756 +
70757 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70758 /* Optimization, do the COW without a second fault */
70759 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70760 @@ -2642,6 +2672,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70761 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70762 struct hstate *h = hstate_vma(vma);
70763
70764 +#ifdef CONFIG_PAX_SEGMEXEC
70765 + struct vm_area_struct *vma_m;
70766 +#endif
70767 +
70768 address &= huge_page_mask(h);
70769
70770 ptep = huge_pte_offset(mm, address);
70771 @@ -2655,6 +2689,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70772 VM_FAULT_SET_HINDEX(h - hstates);
70773 }
70774
70775 +#ifdef CONFIG_PAX_SEGMEXEC
70776 + vma_m = pax_find_mirror_vma(vma);
70777 + if (vma_m) {
70778 + unsigned long address_m;
70779 +
70780 + if (vma->vm_start > vma_m->vm_start) {
70781 + address_m = address;
70782 + address -= SEGMEXEC_TASK_SIZE;
70783 + vma = vma_m;
70784 + h = hstate_vma(vma);
70785 + } else
70786 + address_m = address + SEGMEXEC_TASK_SIZE;
70787 +
70788 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70789 + return VM_FAULT_OOM;
70790 + address_m &= HPAGE_MASK;
70791 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70792 + }
70793 +#endif
70794 +
70795 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70796 if (!ptep)
70797 return VM_FAULT_OOM;
70798 diff --git a/mm/internal.h b/mm/internal.h
70799 index 2189af4..f2ca332 100644
70800 --- a/mm/internal.h
70801 +++ b/mm/internal.h
70802 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70803 * in mm/page_alloc.c
70804 */
70805 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70806 +extern void free_compound_page(struct page *page);
70807 extern void prep_compound_page(struct page *page, unsigned long order);
70808 #ifdef CONFIG_MEMORY_FAILURE
70809 extern bool is_free_buddy_page(struct page *page);
70810 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70811 index 45eb621..6ccd8ea 100644
70812 --- a/mm/kmemleak.c
70813 +++ b/mm/kmemleak.c
70814 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70815
70816 for (i = 0; i < object->trace_len; i++) {
70817 void *ptr = (void *)object->trace[i];
70818 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70819 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70820 }
70821 }
70822
70823 diff --git a/mm/maccess.c b/mm/maccess.c
70824 index d53adf9..03a24bf 100644
70825 --- a/mm/maccess.c
70826 +++ b/mm/maccess.c
70827 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70828 set_fs(KERNEL_DS);
70829 pagefault_disable();
70830 ret = __copy_from_user_inatomic(dst,
70831 - (__force const void __user *)src, size);
70832 + (const void __force_user *)src, size);
70833 pagefault_enable();
70834 set_fs(old_fs);
70835
70836 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70837
70838 set_fs(KERNEL_DS);
70839 pagefault_disable();
70840 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70841 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70842 pagefault_enable();
70843 set_fs(old_fs);
70844
70845 diff --git a/mm/madvise.c b/mm/madvise.c
70846 index 74bf193..feb6fd3 100644
70847 --- a/mm/madvise.c
70848 +++ b/mm/madvise.c
70849 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70850 pgoff_t pgoff;
70851 unsigned long new_flags = vma->vm_flags;
70852
70853 +#ifdef CONFIG_PAX_SEGMEXEC
70854 + struct vm_area_struct *vma_m;
70855 +#endif
70856 +
70857 switch (behavior) {
70858 case MADV_NORMAL:
70859 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70860 @@ -110,6 +114,13 @@ success:
70861 /*
70862 * vm_flags is protected by the mmap_sem held in write mode.
70863 */
70864 +
70865 +#ifdef CONFIG_PAX_SEGMEXEC
70866 + vma_m = pax_find_mirror_vma(vma);
70867 + if (vma_m)
70868 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70869 +#endif
70870 +
70871 vma->vm_flags = new_flags;
70872
70873 out:
70874 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70875 struct vm_area_struct ** prev,
70876 unsigned long start, unsigned long end)
70877 {
70878 +
70879 +#ifdef CONFIG_PAX_SEGMEXEC
70880 + struct vm_area_struct *vma_m;
70881 +#endif
70882 +
70883 *prev = vma;
70884 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70885 return -EINVAL;
70886 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70887 zap_page_range(vma, start, end - start, &details);
70888 } else
70889 zap_page_range(vma, start, end - start, NULL);
70890 +
70891 +#ifdef CONFIG_PAX_SEGMEXEC
70892 + vma_m = pax_find_mirror_vma(vma);
70893 + if (vma_m) {
70894 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70895 + struct zap_details details = {
70896 + .nonlinear_vma = vma_m,
70897 + .last_index = ULONG_MAX,
70898 + };
70899 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70900 + } else
70901 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70902 + }
70903 +#endif
70904 +
70905 return 0;
70906 }
70907
70908 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70909 if (end < start)
70910 goto out;
70911
70912 +#ifdef CONFIG_PAX_SEGMEXEC
70913 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70914 + if (end > SEGMEXEC_TASK_SIZE)
70915 + goto out;
70916 + } else
70917 +#endif
70918 +
70919 + if (end > TASK_SIZE)
70920 + goto out;
70921 +
70922 error = 0;
70923 if (end == start)
70924 goto out;
70925 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70926 index 56080ea..115071e 100644
70927 --- a/mm/memory-failure.c
70928 +++ b/mm/memory-failure.c
70929 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70930
70931 int sysctl_memory_failure_recovery __read_mostly = 1;
70932
70933 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70934 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70935
70936 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70937
70938 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
70939 si.si_signo = SIGBUS;
70940 si.si_errno = 0;
70941 si.si_code = BUS_MCEERR_AO;
70942 - si.si_addr = (void *)addr;
70943 + si.si_addr = (void __user *)addr;
70944 #ifdef __ARCH_SI_TRAPNO
70945 si.si_trapno = trapno;
70946 #endif
70947 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70948 }
70949
70950 nr_pages = 1 << compound_trans_order(hpage);
70951 - atomic_long_add(nr_pages, &mce_bad_pages);
70952 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70953
70954 /*
70955 * We need/can do nothing about count=0 pages.
70956 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70957 if (!PageHWPoison(hpage)
70958 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70959 || (p != hpage && TestSetPageHWPoison(hpage))) {
70960 - atomic_long_sub(nr_pages, &mce_bad_pages);
70961 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70962 return 0;
70963 }
70964 set_page_hwpoison_huge_page(hpage);
70965 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70966 }
70967 if (hwpoison_filter(p)) {
70968 if (TestClearPageHWPoison(p))
70969 - atomic_long_sub(nr_pages, &mce_bad_pages);
70970 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70971 unlock_page(hpage);
70972 put_page(hpage);
70973 return 0;
70974 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
70975 return 0;
70976 }
70977 if (TestClearPageHWPoison(p))
70978 - atomic_long_sub(nr_pages, &mce_bad_pages);
70979 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70980 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70981 return 0;
70982 }
70983 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
70984 */
70985 if (TestClearPageHWPoison(page)) {
70986 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70987 - atomic_long_sub(nr_pages, &mce_bad_pages);
70988 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70989 freeit = 1;
70990 if (PageHuge(page))
70991 clear_page_hwpoison_huge_page(page);
70992 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
70993 }
70994 done:
70995 if (!PageHWPoison(hpage))
70996 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
70997 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
70998 set_page_hwpoison_huge_page(hpage);
70999 dequeue_hwpoisoned_huge_page(hpage);
71000 /* keep elevated page count for bad page */
71001 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
71002 return ret;
71003
71004 done:
71005 - atomic_long_add(1, &mce_bad_pages);
71006 + atomic_long_add_unchecked(1, &mce_bad_pages);
71007 SetPageHWPoison(page);
71008 /* keep elevated page count for bad page */
71009 return ret;
71010 diff --git a/mm/memory.c b/mm/memory.c
71011 index 10b4dda..06857f3 100644
71012 --- a/mm/memory.c
71013 +++ b/mm/memory.c
71014 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71015 return;
71016
71017 pmd = pmd_offset(pud, start);
71018 +
71019 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71020 pud_clear(pud);
71021 pmd_free_tlb(tlb, pmd, start);
71022 +#endif
71023 +
71024 }
71025
71026 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71027 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71028 if (end - 1 > ceiling - 1)
71029 return;
71030
71031 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71032 pud = pud_offset(pgd, start);
71033 pgd_clear(pgd);
71034 pud_free_tlb(tlb, pud, start);
71035 +#endif
71036 +
71037 }
71038
71039 /*
71040 @@ -1593,12 +1600,6 @@ no_page_table:
71041 return page;
71042 }
71043
71044 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71045 -{
71046 - return stack_guard_page_start(vma, addr) ||
71047 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71048 -}
71049 -
71050 /**
71051 * __get_user_pages() - pin user pages in memory
71052 * @tsk: task_struct of target task
71053 @@ -1671,10 +1672,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71054 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71055 i = 0;
71056
71057 - do {
71058 + while (nr_pages) {
71059 struct vm_area_struct *vma;
71060
71061 - vma = find_extend_vma(mm, start);
71062 + vma = find_vma(mm, start);
71063 if (!vma && in_gate_area(mm, start)) {
71064 unsigned long pg = start & PAGE_MASK;
71065 pgd_t *pgd;
71066 @@ -1722,7 +1723,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71067 goto next_page;
71068 }
71069
71070 - if (!vma ||
71071 + if (!vma || start < vma->vm_start ||
71072 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71073 !(vm_flags & vma->vm_flags))
71074 return i ? : -EFAULT;
71075 @@ -1749,11 +1750,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71076 int ret;
71077 unsigned int fault_flags = 0;
71078
71079 - /* For mlock, just skip the stack guard page. */
71080 - if (foll_flags & FOLL_MLOCK) {
71081 - if (stack_guard_page(vma, start))
71082 - goto next_page;
71083 - }
71084 if (foll_flags & FOLL_WRITE)
71085 fault_flags |= FAULT_FLAG_WRITE;
71086 if (nonblocking)
71087 @@ -1827,7 +1823,7 @@ next_page:
71088 start += PAGE_SIZE;
71089 nr_pages--;
71090 } while (nr_pages && start < vma->vm_end);
71091 - } while (nr_pages);
71092 + }
71093 return i;
71094 }
71095 EXPORT_SYMBOL(__get_user_pages);
71096 @@ -2034,6 +2030,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71097 page_add_file_rmap(page);
71098 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71099
71100 +#ifdef CONFIG_PAX_SEGMEXEC
71101 + pax_mirror_file_pte(vma, addr, page, ptl);
71102 +#endif
71103 +
71104 retval = 0;
71105 pte_unmap_unlock(pte, ptl);
71106 return retval;
71107 @@ -2068,10 +2068,22 @@ out:
71108 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71109 struct page *page)
71110 {
71111 +
71112 +#ifdef CONFIG_PAX_SEGMEXEC
71113 + struct vm_area_struct *vma_m;
71114 +#endif
71115 +
71116 if (addr < vma->vm_start || addr >= vma->vm_end)
71117 return -EFAULT;
71118 if (!page_count(page))
71119 return -EINVAL;
71120 +
71121 +#ifdef CONFIG_PAX_SEGMEXEC
71122 + vma_m = pax_find_mirror_vma(vma);
71123 + if (vma_m)
71124 + vma_m->vm_flags |= VM_INSERTPAGE;
71125 +#endif
71126 +
71127 vma->vm_flags |= VM_INSERTPAGE;
71128 return insert_page(vma, addr, page, vma->vm_page_prot);
71129 }
71130 @@ -2157,6 +2169,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71131 unsigned long pfn)
71132 {
71133 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71134 + BUG_ON(vma->vm_mirror);
71135
71136 if (addr < vma->vm_start || addr >= vma->vm_end)
71137 return -EFAULT;
71138 @@ -2364,7 +2377,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71139
71140 BUG_ON(pud_huge(*pud));
71141
71142 - pmd = pmd_alloc(mm, pud, addr);
71143 + pmd = (mm == &init_mm) ?
71144 + pmd_alloc_kernel(mm, pud, addr) :
71145 + pmd_alloc(mm, pud, addr);
71146 if (!pmd)
71147 return -ENOMEM;
71148 do {
71149 @@ -2384,7 +2399,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71150 unsigned long next;
71151 int err;
71152
71153 - pud = pud_alloc(mm, pgd, addr);
71154 + pud = (mm == &init_mm) ?
71155 + pud_alloc_kernel(mm, pgd, addr) :
71156 + pud_alloc(mm, pgd, addr);
71157 if (!pud)
71158 return -ENOMEM;
71159 do {
71160 @@ -2472,6 +2489,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71161 copy_user_highpage(dst, src, va, vma);
71162 }
71163
71164 +#ifdef CONFIG_PAX_SEGMEXEC
71165 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71166 +{
71167 + struct mm_struct *mm = vma->vm_mm;
71168 + spinlock_t *ptl;
71169 + pte_t *pte, entry;
71170 +
71171 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71172 + entry = *pte;
71173 + if (!pte_present(entry)) {
71174 + if (!pte_none(entry)) {
71175 + BUG_ON(pte_file(entry));
71176 + free_swap_and_cache(pte_to_swp_entry(entry));
71177 + pte_clear_not_present_full(mm, address, pte, 0);
71178 + }
71179 + } else {
71180 + struct page *page;
71181 +
71182 + flush_cache_page(vma, address, pte_pfn(entry));
71183 + entry = ptep_clear_flush(vma, address, pte);
71184 + BUG_ON(pte_dirty(entry));
71185 + page = vm_normal_page(vma, address, entry);
71186 + if (page) {
71187 + update_hiwater_rss(mm);
71188 + if (PageAnon(page))
71189 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71190 + else
71191 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71192 + page_remove_rmap(page);
71193 + page_cache_release(page);
71194 + }
71195 + }
71196 + pte_unmap_unlock(pte, ptl);
71197 +}
71198 +
71199 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71200 + *
71201 + * the ptl of the lower mapped page is held on entry and is not released on exit
71202 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71203 + */
71204 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71205 +{
71206 + struct mm_struct *mm = vma->vm_mm;
71207 + unsigned long address_m;
71208 + spinlock_t *ptl_m;
71209 + struct vm_area_struct *vma_m;
71210 + pmd_t *pmd_m;
71211 + pte_t *pte_m, entry_m;
71212 +
71213 + BUG_ON(!page_m || !PageAnon(page_m));
71214 +
71215 + vma_m = pax_find_mirror_vma(vma);
71216 + if (!vma_m)
71217 + return;
71218 +
71219 + BUG_ON(!PageLocked(page_m));
71220 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71221 + address_m = address + SEGMEXEC_TASK_SIZE;
71222 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71223 + pte_m = pte_offset_map(pmd_m, address_m);
71224 + ptl_m = pte_lockptr(mm, pmd_m);
71225 + if (ptl != ptl_m) {
71226 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71227 + if (!pte_none(*pte_m))
71228 + goto out;
71229 + }
71230 +
71231 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71232 + page_cache_get(page_m);
71233 + page_add_anon_rmap(page_m, vma_m, address_m);
71234 + inc_mm_counter_fast(mm, MM_ANONPAGES);
71235 + set_pte_at(mm, address_m, pte_m, entry_m);
71236 + update_mmu_cache(vma_m, address_m, entry_m);
71237 +out:
71238 + if (ptl != ptl_m)
71239 + spin_unlock(ptl_m);
71240 + pte_unmap(pte_m);
71241 + unlock_page(page_m);
71242 +}
71243 +
71244 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71245 +{
71246 + struct mm_struct *mm = vma->vm_mm;
71247 + unsigned long address_m;
71248 + spinlock_t *ptl_m;
71249 + struct vm_area_struct *vma_m;
71250 + pmd_t *pmd_m;
71251 + pte_t *pte_m, entry_m;
71252 +
71253 + BUG_ON(!page_m || PageAnon(page_m));
71254 +
71255 + vma_m = pax_find_mirror_vma(vma);
71256 + if (!vma_m)
71257 + return;
71258 +
71259 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71260 + address_m = address + SEGMEXEC_TASK_SIZE;
71261 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71262 + pte_m = pte_offset_map(pmd_m, address_m);
71263 + ptl_m = pte_lockptr(mm, pmd_m);
71264 + if (ptl != ptl_m) {
71265 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71266 + if (!pte_none(*pte_m))
71267 + goto out;
71268 + }
71269 +
71270 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71271 + page_cache_get(page_m);
71272 + page_add_file_rmap(page_m);
71273 + inc_mm_counter_fast(mm, MM_FILEPAGES);
71274 + set_pte_at(mm, address_m, pte_m, entry_m);
71275 + update_mmu_cache(vma_m, address_m, entry_m);
71276 +out:
71277 + if (ptl != ptl_m)
71278 + spin_unlock(ptl_m);
71279 + pte_unmap(pte_m);
71280 +}
71281 +
71282 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71283 +{
71284 + struct mm_struct *mm = vma->vm_mm;
71285 + unsigned long address_m;
71286 + spinlock_t *ptl_m;
71287 + struct vm_area_struct *vma_m;
71288 + pmd_t *pmd_m;
71289 + pte_t *pte_m, entry_m;
71290 +
71291 + vma_m = pax_find_mirror_vma(vma);
71292 + if (!vma_m)
71293 + return;
71294 +
71295 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71296 + address_m = address + SEGMEXEC_TASK_SIZE;
71297 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71298 + pte_m = pte_offset_map(pmd_m, address_m);
71299 + ptl_m = pte_lockptr(mm, pmd_m);
71300 + if (ptl != ptl_m) {
71301 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71302 + if (!pte_none(*pte_m))
71303 + goto out;
71304 + }
71305 +
71306 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71307 + set_pte_at(mm, address_m, pte_m, entry_m);
71308 +out:
71309 + if (ptl != ptl_m)
71310 + spin_unlock(ptl_m);
71311 + pte_unmap(pte_m);
71312 +}
71313 +
71314 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71315 +{
71316 + struct page *page_m;
71317 + pte_t entry;
71318 +
71319 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71320 + goto out;
71321 +
71322 + entry = *pte;
71323 + page_m = vm_normal_page(vma, address, entry);
71324 + if (!page_m)
71325 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71326 + else if (PageAnon(page_m)) {
71327 + if (pax_find_mirror_vma(vma)) {
71328 + pte_unmap_unlock(pte, ptl);
71329 + lock_page(page_m);
71330 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71331 + if (pte_same(entry, *pte))
71332 + pax_mirror_anon_pte(vma, address, page_m, ptl);
71333 + else
71334 + unlock_page(page_m);
71335 + }
71336 + } else
71337 + pax_mirror_file_pte(vma, address, page_m, ptl);
71338 +
71339 +out:
71340 + pte_unmap_unlock(pte, ptl);
71341 +}
71342 +#endif
71343 +
71344 /*
71345 * This routine handles present pages, when users try to write
71346 * to a shared page. It is done by copying the page to a new address
71347 @@ -2683,6 +2880,12 @@ gotten:
71348 */
71349 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71350 if (likely(pte_same(*page_table, orig_pte))) {
71351 +
71352 +#ifdef CONFIG_PAX_SEGMEXEC
71353 + if (pax_find_mirror_vma(vma))
71354 + BUG_ON(!trylock_page(new_page));
71355 +#endif
71356 +
71357 if (old_page) {
71358 if (!PageAnon(old_page)) {
71359 dec_mm_counter_fast(mm, MM_FILEPAGES);
71360 @@ -2734,6 +2937,10 @@ gotten:
71361 page_remove_rmap(old_page);
71362 }
71363
71364 +#ifdef CONFIG_PAX_SEGMEXEC
71365 + pax_mirror_anon_pte(vma, address, new_page, ptl);
71366 +#endif
71367 +
71368 /* Free the old page.. */
71369 new_page = old_page;
71370 ret |= VM_FAULT_WRITE;
71371 @@ -3013,6 +3220,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71372 swap_free(entry);
71373 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71374 try_to_free_swap(page);
71375 +
71376 +#ifdef CONFIG_PAX_SEGMEXEC
71377 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71378 +#endif
71379 +
71380 unlock_page(page);
71381 if (swapcache) {
71382 /*
71383 @@ -3036,6 +3248,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71384
71385 /* No need to invalidate - it was non-present before */
71386 update_mmu_cache(vma, address, page_table);
71387 +
71388 +#ifdef CONFIG_PAX_SEGMEXEC
71389 + pax_mirror_anon_pte(vma, address, page, ptl);
71390 +#endif
71391 +
71392 unlock:
71393 pte_unmap_unlock(page_table, ptl);
71394 out:
71395 @@ -3055,40 +3272,6 @@ out_release:
71396 }
71397
71398 /*
71399 - * This is like a special single-page "expand_{down|up}wards()",
71400 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
71401 - * doesn't hit another vma.
71402 - */
71403 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71404 -{
71405 - address &= PAGE_MASK;
71406 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71407 - struct vm_area_struct *prev = vma->vm_prev;
71408 -
71409 - /*
71410 - * Is there a mapping abutting this one below?
71411 - *
71412 - * That's only ok if it's the same stack mapping
71413 - * that has gotten split..
71414 - */
71415 - if (prev && prev->vm_end == address)
71416 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71417 -
71418 - expand_downwards(vma, address - PAGE_SIZE);
71419 - }
71420 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71421 - struct vm_area_struct *next = vma->vm_next;
71422 -
71423 - /* As VM_GROWSDOWN but s/below/above/ */
71424 - if (next && next->vm_start == address + PAGE_SIZE)
71425 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71426 -
71427 - expand_upwards(vma, address + PAGE_SIZE);
71428 - }
71429 - return 0;
71430 -}
71431 -
71432 -/*
71433 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71434 * but allow concurrent faults), and pte mapped but not yet locked.
71435 * We return with mmap_sem still held, but pte unmapped and unlocked.
71436 @@ -3097,27 +3280,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71437 unsigned long address, pte_t *page_table, pmd_t *pmd,
71438 unsigned int flags)
71439 {
71440 - struct page *page;
71441 + struct page *page = NULL;
71442 spinlock_t *ptl;
71443 pte_t entry;
71444
71445 - pte_unmap(page_table);
71446 -
71447 - /* Check if we need to add a guard page to the stack */
71448 - if (check_stack_guard_page(vma, address) < 0)
71449 - return VM_FAULT_SIGBUS;
71450 -
71451 - /* Use the zero-page for reads */
71452 if (!(flags & FAULT_FLAG_WRITE)) {
71453 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71454 vma->vm_page_prot));
71455 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71456 + ptl = pte_lockptr(mm, pmd);
71457 + spin_lock(ptl);
71458 if (!pte_none(*page_table))
71459 goto unlock;
71460 goto setpte;
71461 }
71462
71463 /* Allocate our own private page. */
71464 + pte_unmap(page_table);
71465 +
71466 if (unlikely(anon_vma_prepare(vma)))
71467 goto oom;
71468 page = alloc_zeroed_user_highpage_movable(vma, address);
71469 @@ -3136,6 +3315,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71470 if (!pte_none(*page_table))
71471 goto release;
71472
71473 +#ifdef CONFIG_PAX_SEGMEXEC
71474 + if (pax_find_mirror_vma(vma))
71475 + BUG_ON(!trylock_page(page));
71476 +#endif
71477 +
71478 inc_mm_counter_fast(mm, MM_ANONPAGES);
71479 page_add_new_anon_rmap(page, vma, address);
71480 setpte:
71481 @@ -3143,6 +3327,12 @@ setpte:
71482
71483 /* No need to invalidate - it was non-present before */
71484 update_mmu_cache(vma, address, page_table);
71485 +
71486 +#ifdef CONFIG_PAX_SEGMEXEC
71487 + if (page)
71488 + pax_mirror_anon_pte(vma, address, page, ptl);
71489 +#endif
71490 +
71491 unlock:
71492 pte_unmap_unlock(page_table, ptl);
71493 return 0;
71494 @@ -3286,6 +3476,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71495 */
71496 /* Only go through if we didn't race with anybody else... */
71497 if (likely(pte_same(*page_table, orig_pte))) {
71498 +
71499 +#ifdef CONFIG_PAX_SEGMEXEC
71500 + if (anon && pax_find_mirror_vma(vma))
71501 + BUG_ON(!trylock_page(page));
71502 +#endif
71503 +
71504 flush_icache_page(vma, page);
71505 entry = mk_pte(page, vma->vm_page_prot);
71506 if (flags & FAULT_FLAG_WRITE)
71507 @@ -3305,6 +3501,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71508
71509 /* no need to invalidate: a not-present page won't be cached */
71510 update_mmu_cache(vma, address, page_table);
71511 +
71512 +#ifdef CONFIG_PAX_SEGMEXEC
71513 + if (anon)
71514 + pax_mirror_anon_pte(vma, address, page, ptl);
71515 + else
71516 + pax_mirror_file_pte(vma, address, page, ptl);
71517 +#endif
71518 +
71519 } else {
71520 if (cow_page)
71521 mem_cgroup_uncharge_page(cow_page);
71522 @@ -3458,6 +3662,12 @@ int handle_pte_fault(struct mm_struct *mm,
71523 if (flags & FAULT_FLAG_WRITE)
71524 flush_tlb_fix_spurious_fault(vma, address);
71525 }
71526 +
71527 +#ifdef CONFIG_PAX_SEGMEXEC
71528 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71529 + return 0;
71530 +#endif
71531 +
71532 unlock:
71533 pte_unmap_unlock(pte, ptl);
71534 return 0;
71535 @@ -3474,6 +3684,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71536 pmd_t *pmd;
71537 pte_t *pte;
71538
71539 +#ifdef CONFIG_PAX_SEGMEXEC
71540 + struct vm_area_struct *vma_m;
71541 +#endif
71542 +
71543 __set_current_state(TASK_RUNNING);
71544
71545 count_vm_event(PGFAULT);
71546 @@ -3485,6 +3699,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71547 if (unlikely(is_vm_hugetlb_page(vma)))
71548 return hugetlb_fault(mm, vma, address, flags);
71549
71550 +#ifdef CONFIG_PAX_SEGMEXEC
71551 + vma_m = pax_find_mirror_vma(vma);
71552 + if (vma_m) {
71553 + unsigned long address_m;
71554 + pgd_t *pgd_m;
71555 + pud_t *pud_m;
71556 + pmd_t *pmd_m;
71557 +
71558 + if (vma->vm_start > vma_m->vm_start) {
71559 + address_m = address;
71560 + address -= SEGMEXEC_TASK_SIZE;
71561 + vma = vma_m;
71562 + } else
71563 + address_m = address + SEGMEXEC_TASK_SIZE;
71564 +
71565 + pgd_m = pgd_offset(mm, address_m);
71566 + pud_m = pud_alloc(mm, pgd_m, address_m);
71567 + if (!pud_m)
71568 + return VM_FAULT_OOM;
71569 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71570 + if (!pmd_m)
71571 + return VM_FAULT_OOM;
71572 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71573 + return VM_FAULT_OOM;
71574 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71575 + }
71576 +#endif
71577 +
71578 pgd = pgd_offset(mm, address);
71579 pud = pud_alloc(mm, pgd, address);
71580 if (!pud)
71581 @@ -3514,7 +3756,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71582 * run pte_offset_map on the pmd, if an huge pmd could
71583 * materialize from under us from a different thread.
71584 */
71585 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71586 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71587 return VM_FAULT_OOM;
71588 /* if an huge pmd materialized from under us just retry later */
71589 if (unlikely(pmd_trans_huge(*pmd)))
71590 @@ -3551,6 +3793,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71591 spin_unlock(&mm->page_table_lock);
71592 return 0;
71593 }
71594 +
71595 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71596 +{
71597 + pud_t *new = pud_alloc_one(mm, address);
71598 + if (!new)
71599 + return -ENOMEM;
71600 +
71601 + smp_wmb(); /* See comment in __pte_alloc */
71602 +
71603 + spin_lock(&mm->page_table_lock);
71604 + if (pgd_present(*pgd)) /* Another has populated it */
71605 + pud_free(mm, new);
71606 + else
71607 + pgd_populate_kernel(mm, pgd, new);
71608 + spin_unlock(&mm->page_table_lock);
71609 + return 0;
71610 +}
71611 #endif /* __PAGETABLE_PUD_FOLDED */
71612
71613 #ifndef __PAGETABLE_PMD_FOLDED
71614 @@ -3581,6 +3840,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71615 spin_unlock(&mm->page_table_lock);
71616 return 0;
71617 }
71618 +
71619 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71620 +{
71621 + pmd_t *new = pmd_alloc_one(mm, address);
71622 + if (!new)
71623 + return -ENOMEM;
71624 +
71625 + smp_wmb(); /* See comment in __pte_alloc */
71626 +
71627 + spin_lock(&mm->page_table_lock);
71628 +#ifndef __ARCH_HAS_4LEVEL_HACK
71629 + if (pud_present(*pud)) /* Another has populated it */
71630 + pmd_free(mm, new);
71631 + else
71632 + pud_populate_kernel(mm, pud, new);
71633 +#else
71634 + if (pgd_present(*pud)) /* Another has populated it */
71635 + pmd_free(mm, new);
71636 + else
71637 + pgd_populate_kernel(mm, pud, new);
71638 +#endif /* __ARCH_HAS_4LEVEL_HACK */
71639 + spin_unlock(&mm->page_table_lock);
71640 + return 0;
71641 +}
71642 #endif /* __PAGETABLE_PMD_FOLDED */
71643
71644 int make_pages_present(unsigned long addr, unsigned long end)
71645 @@ -3618,7 +3901,7 @@ static int __init gate_vma_init(void)
71646 gate_vma.vm_start = FIXADDR_USER_START;
71647 gate_vma.vm_end = FIXADDR_USER_END;
71648 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71649 - gate_vma.vm_page_prot = __P101;
71650 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71651 /*
71652 * Make sure the vDSO gets into every core dump.
71653 * Dumping its contents makes post-mortem fully interpretable later
71654 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71655 index 0a37570..2048346 100644
71656 --- a/mm/mempolicy.c
71657 +++ b/mm/mempolicy.c
71658 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71659 unsigned long vmstart;
71660 unsigned long vmend;
71661
71662 +#ifdef CONFIG_PAX_SEGMEXEC
71663 + struct vm_area_struct *vma_m;
71664 +#endif
71665 +
71666 vma = find_vma(mm, start);
71667 if (!vma || vma->vm_start > start)
71668 return -EFAULT;
71669 @@ -679,6 +683,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71670 err = policy_vma(vma, new_pol);
71671 if (err)
71672 goto out;
71673 +
71674 +#ifdef CONFIG_PAX_SEGMEXEC
71675 + vma_m = pax_find_mirror_vma(vma);
71676 + if (vma_m) {
71677 + err = policy_vma(vma_m, new_pol);
71678 + if (err)
71679 + goto out;
71680 + }
71681 +#endif
71682 +
71683 }
71684
71685 out:
71686 @@ -1112,6 +1126,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71687
71688 if (end < start)
71689 return -EINVAL;
71690 +
71691 +#ifdef CONFIG_PAX_SEGMEXEC
71692 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71693 + if (end > SEGMEXEC_TASK_SIZE)
71694 + return -EINVAL;
71695 + } else
71696 +#endif
71697 +
71698 + if (end > TASK_SIZE)
71699 + return -EINVAL;
71700 +
71701 if (end == start)
71702 return 0;
71703
71704 @@ -1330,6 +1355,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71705 if (!mm)
71706 goto out;
71707
71708 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71709 + if (mm != current->mm &&
71710 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71711 + err = -EPERM;
71712 + goto out;
71713 + }
71714 +#endif
71715 +
71716 /*
71717 * Check if this process has the right to modify the specified
71718 * process. The right exists if the process has administrative
71719 @@ -1339,8 +1372,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71720 rcu_read_lock();
71721 tcred = __task_cred(task);
71722 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71723 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71724 - !capable(CAP_SYS_NICE)) {
71725 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71726 rcu_read_unlock();
71727 err = -EPERM;
71728 goto out;
71729 diff --git a/mm/migrate.c b/mm/migrate.c
71730 index 1503b6b..156c672 100644
71731 --- a/mm/migrate.c
71732 +++ b/mm/migrate.c
71733 @@ -1370,6 +1370,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71734 if (!mm)
71735 return -EINVAL;
71736
71737 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71738 + if (mm != current->mm &&
71739 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71740 + err = -EPERM;
71741 + goto out;
71742 + }
71743 +#endif
71744 +
71745 /*
71746 * Check if this process has the right to modify the specified
71747 * process. The right exists if the process has administrative
71748 @@ -1379,8 +1387,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71749 rcu_read_lock();
71750 tcred = __task_cred(task);
71751 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71752 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71753 - !capable(CAP_SYS_NICE)) {
71754 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71755 rcu_read_unlock();
71756 err = -EPERM;
71757 goto out;
71758 diff --git a/mm/mlock.c b/mm/mlock.c
71759 index ef726e8..13e0901 100644
71760 --- a/mm/mlock.c
71761 +++ b/mm/mlock.c
71762 @@ -13,6 +13,7 @@
71763 #include <linux/pagemap.h>
71764 #include <linux/mempolicy.h>
71765 #include <linux/syscalls.h>
71766 +#include <linux/security.h>
71767 #include <linux/sched.h>
71768 #include <linux/export.h>
71769 #include <linux/rmap.h>
71770 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71771 return -EINVAL;
71772 if (end == start)
71773 return 0;
71774 + if (end > TASK_SIZE)
71775 + return -EINVAL;
71776 +
71777 vma = find_vma(current->mm, start);
71778 if (!vma || vma->vm_start > start)
71779 return -ENOMEM;
71780 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71781 for (nstart = start ; ; ) {
71782 vm_flags_t newflags;
71783
71784 +#ifdef CONFIG_PAX_SEGMEXEC
71785 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71786 + break;
71787 +#endif
71788 +
71789 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71790
71791 newflags = vma->vm_flags | VM_LOCKED;
71792 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71793 lock_limit >>= PAGE_SHIFT;
71794
71795 /* check against resource limits */
71796 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71797 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71798 error = do_mlock(start, len, 1);
71799 up_write(&current->mm->mmap_sem);
71800 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71801 static int do_mlockall(int flags)
71802 {
71803 struct vm_area_struct * vma, * prev = NULL;
71804 - unsigned int def_flags = 0;
71805
71806 if (flags & MCL_FUTURE)
71807 - def_flags = VM_LOCKED;
71808 - current->mm->def_flags = def_flags;
71809 + current->mm->def_flags |= VM_LOCKED;
71810 + else
71811 + current->mm->def_flags &= ~VM_LOCKED;
71812 if (flags == MCL_FUTURE)
71813 goto out;
71814
71815 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71816 vm_flags_t newflags;
71817
71818 +#ifdef CONFIG_PAX_SEGMEXEC
71819 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71820 + break;
71821 +#endif
71822 +
71823 + BUG_ON(vma->vm_end > TASK_SIZE);
71824 newflags = vma->vm_flags | VM_LOCKED;
71825 if (!(flags & MCL_CURRENT))
71826 newflags &= ~VM_LOCKED;
71827 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71828 lock_limit >>= PAGE_SHIFT;
71829
71830 ret = -ENOMEM;
71831 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71832 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71833 capable(CAP_IPC_LOCK))
71834 ret = do_mlockall(flags);
71835 diff --git a/mm/mmap.c b/mm/mmap.c
71836 index da15a79..314aef3 100644
71837 --- a/mm/mmap.c
71838 +++ b/mm/mmap.c
71839 @@ -46,6 +46,16 @@
71840 #define arch_rebalance_pgtables(addr, len) (addr)
71841 #endif
71842
71843 +static inline void verify_mm_writelocked(struct mm_struct *mm)
71844 +{
71845 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71846 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71847 + up_read(&mm->mmap_sem);
71848 + BUG();
71849 + }
71850 +#endif
71851 +}
71852 +
71853 static void unmap_region(struct mm_struct *mm,
71854 struct vm_area_struct *vma, struct vm_area_struct *prev,
71855 unsigned long start, unsigned long end);
71856 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
71857 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71858 *
71859 */
71860 -pgprot_t protection_map[16] = {
71861 +pgprot_t protection_map[16] __read_only = {
71862 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71863 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71864 };
71865
71866 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
71867 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71868 {
71869 - return __pgprot(pgprot_val(protection_map[vm_flags &
71870 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71871 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71872 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71873 +
71874 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71875 + if (!(__supported_pte_mask & _PAGE_NX) &&
71876 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71877 + (vm_flags & (VM_READ | VM_WRITE)))
71878 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71879 +#endif
71880 +
71881 + return prot;
71882 }
71883 EXPORT_SYMBOL(vm_get_page_prot);
71884
71885 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71886 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71887 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71888 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71889 /*
71890 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71891 * other variables. It can be updated by several CPUs frequently.
71892 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71893 struct vm_area_struct *next = vma->vm_next;
71894
71895 might_sleep();
71896 + BUG_ON(vma->vm_mirror);
71897 if (vma->vm_ops && vma->vm_ops->close)
71898 vma->vm_ops->close(vma);
71899 if (vma->vm_file) {
71900 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71901 * not page aligned -Ram Gupta
71902 */
71903 rlim = rlimit(RLIMIT_DATA);
71904 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71905 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71906 (mm->end_data - mm->start_data) > rlim)
71907 goto out;
71908 @@ -689,6 +711,12 @@ static int
71909 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71910 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71911 {
71912 +
71913 +#ifdef CONFIG_PAX_SEGMEXEC
71914 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71915 + return 0;
71916 +#endif
71917 +
71918 if (is_mergeable_vma(vma, file, vm_flags) &&
71919 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71920 if (vma->vm_pgoff == vm_pgoff)
71921 @@ -708,6 +736,12 @@ static int
71922 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71923 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71924 {
71925 +
71926 +#ifdef CONFIG_PAX_SEGMEXEC
71927 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71928 + return 0;
71929 +#endif
71930 +
71931 if (is_mergeable_vma(vma, file, vm_flags) &&
71932 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71933 pgoff_t vm_pglen;
71934 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71935 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71936 struct vm_area_struct *prev, unsigned long addr,
71937 unsigned long end, unsigned long vm_flags,
71938 - struct anon_vma *anon_vma, struct file *file,
71939 + struct anon_vma *anon_vma, struct file *file,
71940 pgoff_t pgoff, struct mempolicy *policy)
71941 {
71942 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71943 struct vm_area_struct *area, *next;
71944 int err;
71945
71946 +#ifdef CONFIG_PAX_SEGMEXEC
71947 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71948 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71949 +
71950 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71951 +#endif
71952 +
71953 /*
71954 * We later require that vma->vm_flags == vm_flags,
71955 * so this tests vma->vm_flags & VM_SPECIAL, too.
71956 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71957 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71958 next = next->vm_next;
71959
71960 +#ifdef CONFIG_PAX_SEGMEXEC
71961 + if (prev)
71962 + prev_m = pax_find_mirror_vma(prev);
71963 + if (area)
71964 + area_m = pax_find_mirror_vma(area);
71965 + if (next)
71966 + next_m = pax_find_mirror_vma(next);
71967 +#endif
71968 +
71969 /*
71970 * Can it merge with the predecessor?
71971 */
71972 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71973 /* cases 1, 6 */
71974 err = vma_adjust(prev, prev->vm_start,
71975 next->vm_end, prev->vm_pgoff, NULL);
71976 - } else /* cases 2, 5, 7 */
71977 +
71978 +#ifdef CONFIG_PAX_SEGMEXEC
71979 + if (!err && prev_m)
71980 + err = vma_adjust(prev_m, prev_m->vm_start,
71981 + next_m->vm_end, prev_m->vm_pgoff, NULL);
71982 +#endif
71983 +
71984 + } else { /* cases 2, 5, 7 */
71985 err = vma_adjust(prev, prev->vm_start,
71986 end, prev->vm_pgoff, NULL);
71987 +
71988 +#ifdef CONFIG_PAX_SEGMEXEC
71989 + if (!err && prev_m)
71990 + err = vma_adjust(prev_m, prev_m->vm_start,
71991 + end_m, prev_m->vm_pgoff, NULL);
71992 +#endif
71993 +
71994 + }
71995 if (err)
71996 return NULL;
71997 khugepaged_enter_vma_merge(prev);
71998 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71999 mpol_equal(policy, vma_policy(next)) &&
72000 can_vma_merge_before(next, vm_flags,
72001 anon_vma, file, pgoff+pglen)) {
72002 - if (prev && addr < prev->vm_end) /* case 4 */
72003 + if (prev && addr < prev->vm_end) { /* case 4 */
72004 err = vma_adjust(prev, prev->vm_start,
72005 addr, prev->vm_pgoff, NULL);
72006 - else /* cases 3, 8 */
72007 +
72008 +#ifdef CONFIG_PAX_SEGMEXEC
72009 + if (!err && prev_m)
72010 + err = vma_adjust(prev_m, prev_m->vm_start,
72011 + addr_m, prev_m->vm_pgoff, NULL);
72012 +#endif
72013 +
72014 + } else { /* cases 3, 8 */
72015 err = vma_adjust(area, addr, next->vm_end,
72016 next->vm_pgoff - pglen, NULL);
72017 +
72018 +#ifdef CONFIG_PAX_SEGMEXEC
72019 + if (!err && area_m)
72020 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72021 + next_m->vm_pgoff - pglen, NULL);
72022 +#endif
72023 +
72024 + }
72025 if (err)
72026 return NULL;
72027 khugepaged_enter_vma_merge(area);
72028 @@ -921,14 +1001,11 @@ none:
72029 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72030 struct file *file, long pages)
72031 {
72032 - const unsigned long stack_flags
72033 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72034 -
72035 if (file) {
72036 mm->shared_vm += pages;
72037 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72038 mm->exec_vm += pages;
72039 - } else if (flags & stack_flags)
72040 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72041 mm->stack_vm += pages;
72042 if (flags & (VM_RESERVED|VM_IO))
72043 mm->reserved_vm += pages;
72044 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72045 * (the exception is when the underlying filesystem is noexec
72046 * mounted, in which case we dont add PROT_EXEC.)
72047 */
72048 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72049 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72050 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72051 prot |= PROT_EXEC;
72052
72053 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72054 /* Obtain the address to map to. we verify (or select) it and ensure
72055 * that it represents a valid section of the address space.
72056 */
72057 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72058 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72059 if (addr & ~PAGE_MASK)
72060 return addr;
72061
72062 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72063 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72064 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72065
72066 +#ifdef CONFIG_PAX_MPROTECT
72067 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72068 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72069 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72070 + gr_log_rwxmmap(file);
72071 +
72072 +#ifdef CONFIG_PAX_EMUPLT
72073 + vm_flags &= ~VM_EXEC;
72074 +#else
72075 + return -EPERM;
72076 +#endif
72077 +
72078 + }
72079 +
72080 + if (!(vm_flags & VM_EXEC))
72081 + vm_flags &= ~VM_MAYEXEC;
72082 +#else
72083 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72084 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72085 +#endif
72086 + else
72087 + vm_flags &= ~VM_MAYWRITE;
72088 + }
72089 +#endif
72090 +
72091 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72092 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72093 + vm_flags &= ~VM_PAGEEXEC;
72094 +#endif
72095 +
72096 if (flags & MAP_LOCKED)
72097 if (!can_do_mlock())
72098 return -EPERM;
72099 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72100 locked += mm->locked_vm;
72101 lock_limit = rlimit(RLIMIT_MEMLOCK);
72102 lock_limit >>= PAGE_SHIFT;
72103 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72104 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72105 return -EAGAIN;
72106 }
72107 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72108 if (error)
72109 return error;
72110
72111 + if (!gr_acl_handle_mmap(file, prot))
72112 + return -EACCES;
72113 +
72114 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72115 }
72116 EXPORT_SYMBOL(do_mmap_pgoff);
72117 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72118 vm_flags_t vm_flags = vma->vm_flags;
72119
72120 /* If it was private or non-writable, the write bit is already clear */
72121 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72122 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72123 return 0;
72124
72125 /* The backer wishes to know when pages are first written to? */
72126 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72127 unsigned long charged = 0;
72128 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72129
72130 +#ifdef CONFIG_PAX_SEGMEXEC
72131 + struct vm_area_struct *vma_m = NULL;
72132 +#endif
72133 +
72134 + /*
72135 + * mm->mmap_sem is required to protect against another thread
72136 + * changing the mappings in case we sleep.
72137 + */
72138 + verify_mm_writelocked(mm);
72139 +
72140 /* Clear old maps */
72141 error = -ENOMEM;
72142 -munmap_back:
72143 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72144 if (vma && vma->vm_start < addr + len) {
72145 if (do_munmap(mm, addr, len))
72146 return -ENOMEM;
72147 - goto munmap_back;
72148 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72149 + BUG_ON(vma && vma->vm_start < addr + len);
72150 }
72151
72152 /* Check against address space limit. */
72153 @@ -1258,6 +1379,16 @@ munmap_back:
72154 goto unacct_error;
72155 }
72156
72157 +#ifdef CONFIG_PAX_SEGMEXEC
72158 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72159 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72160 + if (!vma_m) {
72161 + error = -ENOMEM;
72162 + goto free_vma;
72163 + }
72164 + }
72165 +#endif
72166 +
72167 vma->vm_mm = mm;
72168 vma->vm_start = addr;
72169 vma->vm_end = addr + len;
72170 @@ -1282,6 +1413,19 @@ munmap_back:
72171 error = file->f_op->mmap(file, vma);
72172 if (error)
72173 goto unmap_and_free_vma;
72174 +
72175 +#ifdef CONFIG_PAX_SEGMEXEC
72176 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72177 + added_exe_file_vma(mm);
72178 +#endif
72179 +
72180 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72181 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72182 + vma->vm_flags |= VM_PAGEEXEC;
72183 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72184 + }
72185 +#endif
72186 +
72187 if (vm_flags & VM_EXECUTABLE)
72188 added_exe_file_vma(mm);
72189
72190 @@ -1319,6 +1463,11 @@ munmap_back:
72191 vma_link(mm, vma, prev, rb_link, rb_parent);
72192 file = vma->vm_file;
72193
72194 +#ifdef CONFIG_PAX_SEGMEXEC
72195 + if (vma_m)
72196 + BUG_ON(pax_mirror_vma(vma_m, vma));
72197 +#endif
72198 +
72199 /* Once vma denies write, undo our temporary denial count */
72200 if (correct_wcount)
72201 atomic_inc(&inode->i_writecount);
72202 @@ -1327,6 +1476,7 @@ out:
72203
72204 mm->total_vm += len >> PAGE_SHIFT;
72205 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72206 + track_exec_limit(mm, addr, addr + len, vm_flags);
72207 if (vm_flags & VM_LOCKED) {
72208 if (!mlock_vma_pages_range(vma, addr, addr + len))
72209 mm->locked_vm += (len >> PAGE_SHIFT);
72210 @@ -1344,6 +1494,12 @@ unmap_and_free_vma:
72211 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72212 charged = 0;
72213 free_vma:
72214 +
72215 +#ifdef CONFIG_PAX_SEGMEXEC
72216 + if (vma_m)
72217 + kmem_cache_free(vm_area_cachep, vma_m);
72218 +#endif
72219 +
72220 kmem_cache_free(vm_area_cachep, vma);
72221 unacct_error:
72222 if (charged)
72223 @@ -1351,6 +1507,44 @@ unacct_error:
72224 return error;
72225 }
72226
72227 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72228 +{
72229 + if (!vma) {
72230 +#ifdef CONFIG_STACK_GROWSUP
72231 + if (addr > sysctl_heap_stack_gap)
72232 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72233 + else
72234 + vma = find_vma(current->mm, 0);
72235 + if (vma && (vma->vm_flags & VM_GROWSUP))
72236 + return false;
72237 +#endif
72238 + return true;
72239 + }
72240 +
72241 + if (addr + len > vma->vm_start)
72242 + return false;
72243 +
72244 + if (vma->vm_flags & VM_GROWSDOWN)
72245 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72246 +#ifdef CONFIG_STACK_GROWSUP
72247 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72248 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72249 +#endif
72250 +
72251 + return true;
72252 +}
72253 +
72254 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72255 +{
72256 + if (vma->vm_start < len)
72257 + return -ENOMEM;
72258 + if (!(vma->vm_flags & VM_GROWSDOWN))
72259 + return vma->vm_start - len;
72260 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
72261 + return vma->vm_start - len - sysctl_heap_stack_gap;
72262 + return -ENOMEM;
72263 +}
72264 +
72265 /* Get an address range which is currently unmapped.
72266 * For shmat() with addr=0.
72267 *
72268 @@ -1377,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72269 if (flags & MAP_FIXED)
72270 return addr;
72271
72272 +#ifdef CONFIG_PAX_RANDMMAP
72273 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72274 +#endif
72275 +
72276 if (addr) {
72277 addr = PAGE_ALIGN(addr);
72278 - vma = find_vma(mm, addr);
72279 - if (TASK_SIZE - len >= addr &&
72280 - (!vma || addr + len <= vma->vm_start))
72281 - return addr;
72282 + if (TASK_SIZE - len >= addr) {
72283 + vma = find_vma(mm, addr);
72284 + if (check_heap_stack_gap(vma, addr, len))
72285 + return addr;
72286 + }
72287 }
72288 if (len > mm->cached_hole_size) {
72289 - start_addr = addr = mm->free_area_cache;
72290 + start_addr = addr = mm->free_area_cache;
72291 } else {
72292 - start_addr = addr = TASK_UNMAPPED_BASE;
72293 - mm->cached_hole_size = 0;
72294 + start_addr = addr = mm->mmap_base;
72295 + mm->cached_hole_size = 0;
72296 }
72297
72298 full_search:
72299 @@ -1399,34 +1598,40 @@ full_search:
72300 * Start a new search - just in case we missed
72301 * some holes.
72302 */
72303 - if (start_addr != TASK_UNMAPPED_BASE) {
72304 - addr = TASK_UNMAPPED_BASE;
72305 - start_addr = addr;
72306 + if (start_addr != mm->mmap_base) {
72307 + start_addr = addr = mm->mmap_base;
72308 mm->cached_hole_size = 0;
72309 goto full_search;
72310 }
72311 return -ENOMEM;
72312 }
72313 - if (!vma || addr + len <= vma->vm_start) {
72314 - /*
72315 - * Remember the place where we stopped the search:
72316 - */
72317 - mm->free_area_cache = addr + len;
72318 - return addr;
72319 - }
72320 + if (check_heap_stack_gap(vma, addr, len))
72321 + break;
72322 if (addr + mm->cached_hole_size < vma->vm_start)
72323 mm->cached_hole_size = vma->vm_start - addr;
72324 addr = vma->vm_end;
72325 }
72326 +
72327 + /*
72328 + * Remember the place where we stopped the search:
72329 + */
72330 + mm->free_area_cache = addr + len;
72331 + return addr;
72332 }
72333 #endif
72334
72335 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72336 {
72337 +
72338 +#ifdef CONFIG_PAX_SEGMEXEC
72339 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72340 + return;
72341 +#endif
72342 +
72343 /*
72344 * Is this a new hole at the lowest possible address?
72345 */
72346 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
72347 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
72348 mm->free_area_cache = addr;
72349 mm->cached_hole_size = ~0UL;
72350 }
72351 @@ -1444,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72352 {
72353 struct vm_area_struct *vma;
72354 struct mm_struct *mm = current->mm;
72355 - unsigned long addr = addr0;
72356 + unsigned long base = mm->mmap_base, addr = addr0;
72357
72358 /* requested length too big for entire address space */
72359 if (len > TASK_SIZE)
72360 @@ -1453,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72361 if (flags & MAP_FIXED)
72362 return addr;
72363
72364 +#ifdef CONFIG_PAX_RANDMMAP
72365 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72366 +#endif
72367 +
72368 /* requesting a specific address */
72369 if (addr) {
72370 addr = PAGE_ALIGN(addr);
72371 - vma = find_vma(mm, addr);
72372 - if (TASK_SIZE - len >= addr &&
72373 - (!vma || addr + len <= vma->vm_start))
72374 - return addr;
72375 + if (TASK_SIZE - len >= addr) {
72376 + vma = find_vma(mm, addr);
72377 + if (check_heap_stack_gap(vma, addr, len))
72378 + return addr;
72379 + }
72380 }
72381
72382 /* check if free_area_cache is useful for us */
72383 @@ -1474,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72384 /* make sure it can fit in the remaining address space */
72385 if (addr > len) {
72386 vma = find_vma(mm, addr-len);
72387 - if (!vma || addr <= vma->vm_start)
72388 + if (check_heap_stack_gap(vma, addr - len, len))
72389 /* remember the address as a hint for next time */
72390 return (mm->free_area_cache = addr-len);
72391 }
72392 @@ -1491,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72393 * return with success:
72394 */
72395 vma = find_vma(mm, addr);
72396 - if (!vma || addr+len <= vma->vm_start)
72397 + if (check_heap_stack_gap(vma, addr, len))
72398 /* remember the address as a hint for next time */
72399 return (mm->free_area_cache = addr);
72400
72401 @@ -1500,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72402 mm->cached_hole_size = vma->vm_start - addr;
72403
72404 /* try just below the current vma->vm_start */
72405 - addr = vma->vm_start-len;
72406 - } while (len < vma->vm_start);
72407 + addr = skip_heap_stack_gap(vma, len);
72408 + } while (!IS_ERR_VALUE(addr));
72409
72410 bottomup:
72411 /*
72412 @@ -1510,13 +1720,21 @@ bottomup:
72413 * can happen with large stack limits and large mmap()
72414 * allocations.
72415 */
72416 + mm->mmap_base = TASK_UNMAPPED_BASE;
72417 +
72418 +#ifdef CONFIG_PAX_RANDMMAP
72419 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72420 + mm->mmap_base += mm->delta_mmap;
72421 +#endif
72422 +
72423 + mm->free_area_cache = mm->mmap_base;
72424 mm->cached_hole_size = ~0UL;
72425 - mm->free_area_cache = TASK_UNMAPPED_BASE;
72426 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72427 /*
72428 * Restore the topdown base:
72429 */
72430 - mm->free_area_cache = mm->mmap_base;
72431 + mm->mmap_base = base;
72432 + mm->free_area_cache = base;
72433 mm->cached_hole_size = ~0UL;
72434
72435 return addr;
72436 @@ -1525,6 +1743,12 @@ bottomup:
72437
72438 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72439 {
72440 +
72441 +#ifdef CONFIG_PAX_SEGMEXEC
72442 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72443 + return;
72444 +#endif
72445 +
72446 /*
72447 * Is this a new hole at the highest possible address?
72448 */
72449 @@ -1532,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72450 mm->free_area_cache = addr;
72451
72452 /* dont allow allocations above current base */
72453 - if (mm->free_area_cache > mm->mmap_base)
72454 + if (mm->free_area_cache > mm->mmap_base) {
72455 mm->free_area_cache = mm->mmap_base;
72456 + mm->cached_hole_size = ~0UL;
72457 + }
72458 }
72459
72460 unsigned long
72461 @@ -1629,6 +1855,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72462 return vma;
72463 }
72464
72465 +#ifdef CONFIG_PAX_SEGMEXEC
72466 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72467 +{
72468 + struct vm_area_struct *vma_m;
72469 +
72470 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72471 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72472 + BUG_ON(vma->vm_mirror);
72473 + return NULL;
72474 + }
72475 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72476 + vma_m = vma->vm_mirror;
72477 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72478 + BUG_ON(vma->vm_file != vma_m->vm_file);
72479 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72480 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72481 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72482 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72483 + return vma_m;
72484 +}
72485 +#endif
72486 +
72487 /*
72488 * Verify that the stack growth is acceptable and
72489 * update accounting. This is shared with both the
72490 @@ -1645,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72491 return -ENOMEM;
72492
72493 /* Stack limit test */
72494 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
72495 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72496 return -ENOMEM;
72497
72498 @@ -1655,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72499 locked = mm->locked_vm + grow;
72500 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72501 limit >>= PAGE_SHIFT;
72502 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72503 if (locked > limit && !capable(CAP_IPC_LOCK))
72504 return -ENOMEM;
72505 }
72506 @@ -1685,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72507 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72508 * vma is the last one with address > vma->vm_end. Have to extend vma.
72509 */
72510 +#ifndef CONFIG_IA64
72511 +static
72512 +#endif
72513 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72514 {
72515 int error;
72516 + bool locknext;
72517
72518 if (!(vma->vm_flags & VM_GROWSUP))
72519 return -EFAULT;
72520
72521 + /* Also guard against wrapping around to address 0. */
72522 + if (address < PAGE_ALIGN(address+1))
72523 + address = PAGE_ALIGN(address+1);
72524 + else
72525 + return -ENOMEM;
72526 +
72527 /*
72528 * We must make sure the anon_vma is allocated
72529 * so that the anon_vma locking is not a noop.
72530 */
72531 if (unlikely(anon_vma_prepare(vma)))
72532 return -ENOMEM;
72533 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72534 + if (locknext && anon_vma_prepare(vma->vm_next))
72535 + return -ENOMEM;
72536 vma_lock_anon_vma(vma);
72537 + if (locknext)
72538 + vma_lock_anon_vma(vma->vm_next);
72539
72540 /*
72541 * vma->vm_start/vm_end cannot change under us because the caller
72542 * is required to hold the mmap_sem in read mode. We need the
72543 - * anon_vma lock to serialize against concurrent expand_stacks.
72544 - * Also guard against wrapping around to address 0.
72545 + * anon_vma locks to serialize against concurrent expand_stacks
72546 + * and expand_upwards.
72547 */
72548 - if (address < PAGE_ALIGN(address+4))
72549 - address = PAGE_ALIGN(address+4);
72550 - else {
72551 - vma_unlock_anon_vma(vma);
72552 - return -ENOMEM;
72553 - }
72554 error = 0;
72555
72556 /* Somebody else might have raced and expanded it already */
72557 - if (address > vma->vm_end) {
72558 + 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)
72559 + error = -ENOMEM;
72560 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72561 unsigned long size, grow;
72562
72563 size = address - vma->vm_start;
72564 @@ -1730,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72565 }
72566 }
72567 }
72568 + if (locknext)
72569 + vma_unlock_anon_vma(vma->vm_next);
72570 vma_unlock_anon_vma(vma);
72571 khugepaged_enter_vma_merge(vma);
72572 return error;
72573 @@ -1743,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
72574 unsigned long address)
72575 {
72576 int error;
72577 + bool lockprev = false;
72578 + struct vm_area_struct *prev;
72579
72580 /*
72581 * We must make sure the anon_vma is allocated
72582 @@ -1756,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
72583 if (error)
72584 return error;
72585
72586 + prev = vma->vm_prev;
72587 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72588 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72589 +#endif
72590 + if (lockprev && anon_vma_prepare(prev))
72591 + return -ENOMEM;
72592 + if (lockprev)
72593 + vma_lock_anon_vma(prev);
72594 +
72595 vma_lock_anon_vma(vma);
72596
72597 /*
72598 @@ -1765,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
72599 */
72600
72601 /* Somebody else might have raced and expanded it already */
72602 - if (address < vma->vm_start) {
72603 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72604 + error = -ENOMEM;
72605 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72606 unsigned long size, grow;
72607
72608 +#ifdef CONFIG_PAX_SEGMEXEC
72609 + struct vm_area_struct *vma_m;
72610 +
72611 + vma_m = pax_find_mirror_vma(vma);
72612 +#endif
72613 +
72614 size = vma->vm_end - address;
72615 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72616
72617 @@ -1777,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
72618 if (!error) {
72619 vma->vm_start = address;
72620 vma->vm_pgoff -= grow;
72621 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72622 +
72623 +#ifdef CONFIG_PAX_SEGMEXEC
72624 + if (vma_m) {
72625 + vma_m->vm_start -= grow << PAGE_SHIFT;
72626 + vma_m->vm_pgoff -= grow;
72627 + }
72628 +#endif
72629 +
72630 perf_event_mmap(vma);
72631 }
72632 }
72633 }
72634 vma_unlock_anon_vma(vma);
72635 + if (lockprev)
72636 + vma_unlock_anon_vma(prev);
72637 khugepaged_enter_vma_merge(vma);
72638 return error;
72639 }
72640 @@ -1851,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72641 do {
72642 long nrpages = vma_pages(vma);
72643
72644 +#ifdef CONFIG_PAX_SEGMEXEC
72645 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72646 + vma = remove_vma(vma);
72647 + continue;
72648 + }
72649 +#endif
72650 +
72651 mm->total_vm -= nrpages;
72652 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
72653 vma = remove_vma(vma);
72654 @@ -1896,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72655 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72656 vma->vm_prev = NULL;
72657 do {
72658 +
72659 +#ifdef CONFIG_PAX_SEGMEXEC
72660 + if (vma->vm_mirror) {
72661 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72662 + vma->vm_mirror->vm_mirror = NULL;
72663 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72664 + vma->vm_mirror = NULL;
72665 + }
72666 +#endif
72667 +
72668 rb_erase(&vma->vm_rb, &mm->mm_rb);
72669 mm->map_count--;
72670 tail_vma = vma;
72671 @@ -1924,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72672 struct vm_area_struct *new;
72673 int err = -ENOMEM;
72674
72675 +#ifdef CONFIG_PAX_SEGMEXEC
72676 + struct vm_area_struct *vma_m, *new_m = NULL;
72677 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72678 +#endif
72679 +
72680 if (is_vm_hugetlb_page(vma) && (addr &
72681 ~(huge_page_mask(hstate_vma(vma)))))
72682 return -EINVAL;
72683
72684 +#ifdef CONFIG_PAX_SEGMEXEC
72685 + vma_m = pax_find_mirror_vma(vma);
72686 +#endif
72687 +
72688 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72689 if (!new)
72690 goto out_err;
72691
72692 +#ifdef CONFIG_PAX_SEGMEXEC
72693 + if (vma_m) {
72694 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72695 + if (!new_m) {
72696 + kmem_cache_free(vm_area_cachep, new);
72697 + goto out_err;
72698 + }
72699 + }
72700 +#endif
72701 +
72702 /* most fields are the same, copy all, and then fixup */
72703 *new = *vma;
72704
72705 @@ -1944,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72706 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72707 }
72708
72709 +#ifdef CONFIG_PAX_SEGMEXEC
72710 + if (vma_m) {
72711 + *new_m = *vma_m;
72712 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
72713 + new_m->vm_mirror = new;
72714 + new->vm_mirror = new_m;
72715 +
72716 + if (new_below)
72717 + new_m->vm_end = addr_m;
72718 + else {
72719 + new_m->vm_start = addr_m;
72720 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72721 + }
72722 + }
72723 +#endif
72724 +
72725 pol = mpol_dup(vma_policy(vma));
72726 if (IS_ERR(pol)) {
72727 err = PTR_ERR(pol);
72728 @@ -1969,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72729 else
72730 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72731
72732 +#ifdef CONFIG_PAX_SEGMEXEC
72733 + if (!err && vma_m) {
72734 + if (anon_vma_clone(new_m, vma_m))
72735 + goto out_free_mpol;
72736 +
72737 + mpol_get(pol);
72738 + vma_set_policy(new_m, pol);
72739 +
72740 + if (new_m->vm_file) {
72741 + get_file(new_m->vm_file);
72742 + if (vma_m->vm_flags & VM_EXECUTABLE)
72743 + added_exe_file_vma(mm);
72744 + }
72745 +
72746 + if (new_m->vm_ops && new_m->vm_ops->open)
72747 + new_m->vm_ops->open(new_m);
72748 +
72749 + if (new_below)
72750 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72751 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72752 + else
72753 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72754 +
72755 + if (err) {
72756 + if (new_m->vm_ops && new_m->vm_ops->close)
72757 + new_m->vm_ops->close(new_m);
72758 + if (new_m->vm_file) {
72759 + if (vma_m->vm_flags & VM_EXECUTABLE)
72760 + removed_exe_file_vma(mm);
72761 + fput(new_m->vm_file);
72762 + }
72763 + mpol_put(pol);
72764 + }
72765 + }
72766 +#endif
72767 +
72768 /* Success. */
72769 if (!err)
72770 return 0;
72771 @@ -1981,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72772 removed_exe_file_vma(mm);
72773 fput(new->vm_file);
72774 }
72775 - unlink_anon_vmas(new);
72776 out_free_mpol:
72777 mpol_put(pol);
72778 out_free_vma:
72779 +
72780 +#ifdef CONFIG_PAX_SEGMEXEC
72781 + if (new_m) {
72782 + unlink_anon_vmas(new_m);
72783 + kmem_cache_free(vm_area_cachep, new_m);
72784 + }
72785 +#endif
72786 +
72787 + unlink_anon_vmas(new);
72788 kmem_cache_free(vm_area_cachep, new);
72789 out_err:
72790 return err;
72791 @@ -1997,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72792 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72793 unsigned long addr, int new_below)
72794 {
72795 +
72796 +#ifdef CONFIG_PAX_SEGMEXEC
72797 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72798 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72799 + if (mm->map_count >= sysctl_max_map_count-1)
72800 + return -ENOMEM;
72801 + } else
72802 +#endif
72803 +
72804 if (mm->map_count >= sysctl_max_map_count)
72805 return -ENOMEM;
72806
72807 @@ -2008,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72808 * work. This now handles partial unmappings.
72809 * Jeremy Fitzhardinge <jeremy@goop.org>
72810 */
72811 +#ifdef CONFIG_PAX_SEGMEXEC
72812 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72813 {
72814 + int ret = __do_munmap(mm, start, len);
72815 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72816 + return ret;
72817 +
72818 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72819 +}
72820 +
72821 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72822 +#else
72823 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72824 +#endif
72825 +{
72826 unsigned long end;
72827 struct vm_area_struct *vma, *prev, *last;
72828
72829 + /*
72830 + * mm->mmap_sem is required to protect against another thread
72831 + * changing the mappings in case we sleep.
72832 + */
72833 + verify_mm_writelocked(mm);
72834 +
72835 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72836 return -EINVAL;
72837
72838 @@ -2087,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72839 /* Fix up all other VM information */
72840 remove_vma_list(mm, vma);
72841
72842 + track_exec_limit(mm, start, end, 0UL);
72843 +
72844 return 0;
72845 }
72846
72847 @@ -2099,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72848
72849 profile_munmap(addr);
72850
72851 +#ifdef CONFIG_PAX_SEGMEXEC
72852 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72853 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
72854 + return -EINVAL;
72855 +#endif
72856 +
72857 down_write(&mm->mmap_sem);
72858 ret = do_munmap(mm, addr, len);
72859 up_write(&mm->mmap_sem);
72860 return ret;
72861 }
72862
72863 -static inline void verify_mm_writelocked(struct mm_struct *mm)
72864 -{
72865 -#ifdef CONFIG_DEBUG_VM
72866 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72867 - WARN_ON(1);
72868 - up_read(&mm->mmap_sem);
72869 - }
72870 -#endif
72871 -}
72872 -
72873 /*
72874 * this is really a simplified "do_mmap". it only handles
72875 * anonymous maps. eventually we may be able to do some
72876 @@ -2128,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72877 struct rb_node ** rb_link, * rb_parent;
72878 pgoff_t pgoff = addr >> PAGE_SHIFT;
72879 int error;
72880 + unsigned long charged;
72881
72882 len = PAGE_ALIGN(len);
72883 if (!len)
72884 @@ -2139,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72885
72886 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72887
72888 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72889 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72890 + flags &= ~VM_EXEC;
72891 +
72892 +#ifdef CONFIG_PAX_MPROTECT
72893 + if (mm->pax_flags & MF_PAX_MPROTECT)
72894 + flags &= ~VM_MAYEXEC;
72895 +#endif
72896 +
72897 + }
72898 +#endif
72899 +
72900 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72901 if (error & ~PAGE_MASK)
72902 return error;
72903
72904 + charged = len >> PAGE_SHIFT;
72905 +
72906 /*
72907 * mlock MCL_FUTURE?
72908 */
72909 if (mm->def_flags & VM_LOCKED) {
72910 unsigned long locked, lock_limit;
72911 - locked = len >> PAGE_SHIFT;
72912 + locked = charged;
72913 locked += mm->locked_vm;
72914 lock_limit = rlimit(RLIMIT_MEMLOCK);
72915 lock_limit >>= PAGE_SHIFT;
72916 @@ -2165,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72917 /*
72918 * Clear old maps. this also does some error checking for us
72919 */
72920 - munmap_back:
72921 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72922 if (vma && vma->vm_start < addr + len) {
72923 if (do_munmap(mm, addr, len))
72924 return -ENOMEM;
72925 - goto munmap_back;
72926 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72927 + BUG_ON(vma && vma->vm_start < addr + len);
72928 }
72929
72930 /* Check against address space limits *after* clearing old maps... */
72931 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72932 + if (!may_expand_vm(mm, charged))
72933 return -ENOMEM;
72934
72935 if (mm->map_count > sysctl_max_map_count)
72936 return -ENOMEM;
72937
72938 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
72939 + if (security_vm_enough_memory(charged))
72940 return -ENOMEM;
72941
72942 /* Can we just expand an old private anonymous mapping? */
72943 @@ -2194,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72944 */
72945 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72946 if (!vma) {
72947 - vm_unacct_memory(len >> PAGE_SHIFT);
72948 + vm_unacct_memory(charged);
72949 return -ENOMEM;
72950 }
72951
72952 @@ -2208,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72953 vma_link(mm, vma, prev, rb_link, rb_parent);
72954 out:
72955 perf_event_mmap(vma);
72956 - mm->total_vm += len >> PAGE_SHIFT;
72957 + mm->total_vm += charged;
72958 if (flags & VM_LOCKED) {
72959 if (!mlock_vma_pages_range(vma, addr, addr + len))
72960 - mm->locked_vm += (len >> PAGE_SHIFT);
72961 + mm->locked_vm += charged;
72962 }
72963 + track_exec_limit(mm, addr, addr + len, flags);
72964 return addr;
72965 }
72966
72967 @@ -2259,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
72968 * Walk the list again, actually closing and freeing it,
72969 * with preemption enabled, without holding any MM locks.
72970 */
72971 - while (vma)
72972 + while (vma) {
72973 + vma->vm_mirror = NULL;
72974 vma = remove_vma(vma);
72975 + }
72976
72977 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
72978 }
72979 @@ -2274,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72980 struct vm_area_struct * __vma, * prev;
72981 struct rb_node ** rb_link, * rb_parent;
72982
72983 +#ifdef CONFIG_PAX_SEGMEXEC
72984 + struct vm_area_struct *vma_m = NULL;
72985 +#endif
72986 +
72987 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
72988 + return -EPERM;
72989 +
72990 /*
72991 * The vm_pgoff of a purely anonymous vma should be irrelevant
72992 * until its first write fault, when page's anon_vma and index
72993 @@ -2296,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72994 if ((vma->vm_flags & VM_ACCOUNT) &&
72995 security_vm_enough_memory_mm(mm, vma_pages(vma)))
72996 return -ENOMEM;
72997 +
72998 +#ifdef CONFIG_PAX_SEGMEXEC
72999 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73000 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73001 + if (!vma_m)
73002 + return -ENOMEM;
73003 + }
73004 +#endif
73005 +
73006 vma_link(mm, vma, prev, rb_link, rb_parent);
73007 +
73008 +#ifdef CONFIG_PAX_SEGMEXEC
73009 + if (vma_m)
73010 + BUG_ON(pax_mirror_vma(vma_m, vma));
73011 +#endif
73012 +
73013 return 0;
73014 }
73015
73016 @@ -2315,6 +2770,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73017 struct mempolicy *pol;
73018 bool faulted_in_anon_vma = true;
73019
73020 + BUG_ON(vma->vm_mirror);
73021 +
73022 /*
73023 * If anonymous vma has not yet been faulted, update new pgoff
73024 * to match new location, to increase its chance of merging.
73025 @@ -2382,6 +2839,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73026 return NULL;
73027 }
73028
73029 +#ifdef CONFIG_PAX_SEGMEXEC
73030 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73031 +{
73032 + struct vm_area_struct *prev_m;
73033 + struct rb_node **rb_link_m, *rb_parent_m;
73034 + struct mempolicy *pol_m;
73035 +
73036 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73037 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73038 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73039 + *vma_m = *vma;
73040 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73041 + if (anon_vma_clone(vma_m, vma))
73042 + return -ENOMEM;
73043 + pol_m = vma_policy(vma_m);
73044 + mpol_get(pol_m);
73045 + vma_set_policy(vma_m, pol_m);
73046 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73047 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73048 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73049 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73050 + if (vma_m->vm_file)
73051 + get_file(vma_m->vm_file);
73052 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73053 + vma_m->vm_ops->open(vma_m);
73054 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73055 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73056 + vma_m->vm_mirror = vma;
73057 + vma->vm_mirror = vma_m;
73058 + return 0;
73059 +}
73060 +#endif
73061 +
73062 /*
73063 * Return true if the calling process may expand its vm space by the passed
73064 * number of pages
73065 @@ -2393,6 +2883,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73066
73067 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73068
73069 +#ifdef CONFIG_PAX_RANDMMAP
73070 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73071 + cur -= mm->brk_gap;
73072 +#endif
73073 +
73074 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73075 if (cur + npages > lim)
73076 return 0;
73077 return 1;
73078 @@ -2463,6 +2959,22 @@ int install_special_mapping(struct mm_struct *mm,
73079 vma->vm_start = addr;
73080 vma->vm_end = addr + len;
73081
73082 +#ifdef CONFIG_PAX_MPROTECT
73083 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73084 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73085 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73086 + return -EPERM;
73087 + if (!(vm_flags & VM_EXEC))
73088 + vm_flags &= ~VM_MAYEXEC;
73089 +#else
73090 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73091 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73092 +#endif
73093 + else
73094 + vm_flags &= ~VM_MAYWRITE;
73095 + }
73096 +#endif
73097 +
73098 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73099 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73100
73101 diff --git a/mm/mprotect.c b/mm/mprotect.c
73102 index f437d05..e3763f6 100644
73103 --- a/mm/mprotect.c
73104 +++ b/mm/mprotect.c
73105 @@ -23,10 +23,16 @@
73106 #include <linux/mmu_notifier.h>
73107 #include <linux/migrate.h>
73108 #include <linux/perf_event.h>
73109 +
73110 +#ifdef CONFIG_PAX_MPROTECT
73111 +#include <linux/elf.h>
73112 +#endif
73113 +
73114 #include <asm/uaccess.h>
73115 #include <asm/pgtable.h>
73116 #include <asm/cacheflush.h>
73117 #include <asm/tlbflush.h>
73118 +#include <asm/mmu_context.h>
73119
73120 #ifndef pgprot_modify
73121 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73122 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
73123 flush_tlb_range(vma, start, end);
73124 }
73125
73126 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73127 +/* called while holding the mmap semaphor for writing except stack expansion */
73128 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73129 +{
73130 + unsigned long oldlimit, newlimit = 0UL;
73131 +
73132 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73133 + return;
73134 +
73135 + spin_lock(&mm->page_table_lock);
73136 + oldlimit = mm->context.user_cs_limit;
73137 + if ((prot & VM_EXEC) && oldlimit < end)
73138 + /* USER_CS limit moved up */
73139 + newlimit = end;
73140 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73141 + /* USER_CS limit moved down */
73142 + newlimit = start;
73143 +
73144 + if (newlimit) {
73145 + mm->context.user_cs_limit = newlimit;
73146 +
73147 +#ifdef CONFIG_SMP
73148 + wmb();
73149 + cpus_clear(mm->context.cpu_user_cs_mask);
73150 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73151 +#endif
73152 +
73153 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73154 + }
73155 + spin_unlock(&mm->page_table_lock);
73156 + if (newlimit == end) {
73157 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73158 +
73159 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73160 + if (is_vm_hugetlb_page(vma))
73161 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73162 + else
73163 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73164 + }
73165 +}
73166 +#endif
73167 +
73168 int
73169 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73170 unsigned long start, unsigned long end, unsigned long newflags)
73171 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73172 int error;
73173 int dirty_accountable = 0;
73174
73175 +#ifdef CONFIG_PAX_SEGMEXEC
73176 + struct vm_area_struct *vma_m = NULL;
73177 + unsigned long start_m, end_m;
73178 +
73179 + start_m = start + SEGMEXEC_TASK_SIZE;
73180 + end_m = end + SEGMEXEC_TASK_SIZE;
73181 +#endif
73182 +
73183 if (newflags == oldflags) {
73184 *pprev = vma;
73185 return 0;
73186 }
73187
73188 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73189 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73190 +
73191 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73192 + return -ENOMEM;
73193 +
73194 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73195 + return -ENOMEM;
73196 + }
73197 +
73198 /*
73199 * If we make a private mapping writable we increase our commit;
73200 * but (without finer accounting) cannot reduce our commit if we
73201 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73202 }
73203 }
73204
73205 +#ifdef CONFIG_PAX_SEGMEXEC
73206 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73207 + if (start != vma->vm_start) {
73208 + error = split_vma(mm, vma, start, 1);
73209 + if (error)
73210 + goto fail;
73211 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73212 + *pprev = (*pprev)->vm_next;
73213 + }
73214 +
73215 + if (end != vma->vm_end) {
73216 + error = split_vma(mm, vma, end, 0);
73217 + if (error)
73218 + goto fail;
73219 + }
73220 +
73221 + if (pax_find_mirror_vma(vma)) {
73222 + error = __do_munmap(mm, start_m, end_m - start_m);
73223 + if (error)
73224 + goto fail;
73225 + } else {
73226 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73227 + if (!vma_m) {
73228 + error = -ENOMEM;
73229 + goto fail;
73230 + }
73231 + vma->vm_flags = newflags;
73232 + error = pax_mirror_vma(vma_m, vma);
73233 + if (error) {
73234 + vma->vm_flags = oldflags;
73235 + goto fail;
73236 + }
73237 + }
73238 + }
73239 +#endif
73240 +
73241 /*
73242 * First try to merge with previous and/or next vma.
73243 */
73244 @@ -204,9 +306,21 @@ success:
73245 * vm_flags and vm_page_prot are protected by the mmap_sem
73246 * held in write mode.
73247 */
73248 +
73249 +#ifdef CONFIG_PAX_SEGMEXEC
73250 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73251 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73252 +#endif
73253 +
73254 vma->vm_flags = newflags;
73255 +
73256 +#ifdef CONFIG_PAX_MPROTECT
73257 + if (mm->binfmt && mm->binfmt->handle_mprotect)
73258 + mm->binfmt->handle_mprotect(vma, newflags);
73259 +#endif
73260 +
73261 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73262 - vm_get_page_prot(newflags));
73263 + vm_get_page_prot(vma->vm_flags));
73264
73265 if (vma_wants_writenotify(vma)) {
73266 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73267 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73268 end = start + len;
73269 if (end <= start)
73270 return -ENOMEM;
73271 +
73272 +#ifdef CONFIG_PAX_SEGMEXEC
73273 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73274 + if (end > SEGMEXEC_TASK_SIZE)
73275 + return -EINVAL;
73276 + } else
73277 +#endif
73278 +
73279 + if (end > TASK_SIZE)
73280 + return -EINVAL;
73281 +
73282 if (!arch_validate_prot(prot))
73283 return -EINVAL;
73284
73285 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73286 /*
73287 * Does the application expect PROT_READ to imply PROT_EXEC:
73288 */
73289 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73290 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73291 prot |= PROT_EXEC;
73292
73293 vm_flags = calc_vm_prot_bits(prot);
73294 @@ -288,6 +413,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73295 if (start > vma->vm_start)
73296 prev = vma;
73297
73298 +#ifdef CONFIG_PAX_MPROTECT
73299 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73300 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
73301 +#endif
73302 +
73303 for (nstart = start ; ; ) {
73304 unsigned long newflags;
73305
73306 @@ -297,6 +427,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73307
73308 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73309 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73310 + if (prot & (PROT_WRITE | PROT_EXEC))
73311 + gr_log_rwxmprotect(vma->vm_file);
73312 +
73313 + error = -EACCES;
73314 + goto out;
73315 + }
73316 +
73317 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73318 error = -EACCES;
73319 goto out;
73320 }
73321 @@ -311,6 +449,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73322 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73323 if (error)
73324 goto out;
73325 +
73326 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
73327 +
73328 nstart = tmp;
73329
73330 if (nstart < prev->vm_end)
73331 diff --git a/mm/mremap.c b/mm/mremap.c
73332 index 87bb839..c3bfadb 100644
73333 --- a/mm/mremap.c
73334 +++ b/mm/mremap.c
73335 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
73336 continue;
73337 pte = ptep_get_and_clear(mm, old_addr, old_pte);
73338 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73339 +
73340 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73341 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73342 + pte = pte_exprotect(pte);
73343 +#endif
73344 +
73345 set_pte_at(mm, new_addr, new_pte, pte);
73346 }
73347
73348 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
73349 if (is_vm_hugetlb_page(vma))
73350 goto Einval;
73351
73352 +#ifdef CONFIG_PAX_SEGMEXEC
73353 + if (pax_find_mirror_vma(vma))
73354 + goto Einval;
73355 +#endif
73356 +
73357 /* We can't remap across vm area boundaries */
73358 if (old_len > vma->vm_end - addr)
73359 goto Efault;
73360 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
73361 unsigned long ret = -EINVAL;
73362 unsigned long charged = 0;
73363 unsigned long map_flags;
73364 + unsigned long pax_task_size = TASK_SIZE;
73365
73366 if (new_addr & ~PAGE_MASK)
73367 goto out;
73368
73369 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73370 +#ifdef CONFIG_PAX_SEGMEXEC
73371 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73372 + pax_task_size = SEGMEXEC_TASK_SIZE;
73373 +#endif
73374 +
73375 + pax_task_size -= PAGE_SIZE;
73376 +
73377 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73378 goto out;
73379
73380 /* Check if the location we're moving into overlaps the
73381 * old location at all, and fail if it does.
73382 */
73383 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
73384 - goto out;
73385 -
73386 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
73387 + if (addr + old_len > new_addr && new_addr + new_len > addr)
73388 goto out;
73389
73390 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
73391 @@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
73392 struct vm_area_struct *vma;
73393 unsigned long ret = -EINVAL;
73394 unsigned long charged = 0;
73395 + unsigned long pax_task_size = TASK_SIZE;
73396
73397 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
73398 goto out;
73399 @@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
73400 if (!new_len)
73401 goto out;
73402
73403 +#ifdef CONFIG_PAX_SEGMEXEC
73404 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73405 + pax_task_size = SEGMEXEC_TASK_SIZE;
73406 +#endif
73407 +
73408 + pax_task_size -= PAGE_SIZE;
73409 +
73410 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73411 + old_len > pax_task_size || addr > pax_task_size-old_len)
73412 + goto out;
73413 +
73414 if (flags & MREMAP_FIXED) {
73415 if (flags & MREMAP_MAYMOVE)
73416 ret = mremap_to(addr, old_len, new_addr, new_len);
73417 @@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
73418 addr + new_len);
73419 }
73420 ret = addr;
73421 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73422 goto out;
73423 }
73424 }
73425 @@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
73426 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
73427 if (ret)
73428 goto out;
73429 +
73430 + map_flags = vma->vm_flags;
73431 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73432 + if (!(ret & ~PAGE_MASK)) {
73433 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73434 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73435 + }
73436 }
73437 out:
73438 if (ret & ~PAGE_MASK)
73439 diff --git a/mm/nommu.c b/mm/nommu.c
73440 index f59e170..34e2a2b 100644
73441 --- a/mm/nommu.c
73442 +++ b/mm/nommu.c
73443 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73444 int sysctl_overcommit_ratio = 50; /* default is 50% */
73445 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73446 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73447 -int heap_stack_gap = 0;
73448
73449 atomic_long_t mmap_pages_allocated;
73450
73451 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73452 EXPORT_SYMBOL(find_vma);
73453
73454 /*
73455 - * find a VMA
73456 - * - we don't extend stack VMAs under NOMMU conditions
73457 - */
73458 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73459 -{
73460 - return find_vma(mm, addr);
73461 -}
73462 -
73463 -/*
73464 * expand a stack to a given address
73465 * - not supported under NOMMU conditions
73466 */
73467 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73468
73469 /* most fields are the same, copy all, and then fixup */
73470 *new = *vma;
73471 + INIT_LIST_HEAD(&new->anon_vma_chain);
73472 *region = *vma->vm_region;
73473 new->vm_region = region;
73474
73475 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73476 index a13ded1..b949d15 100644
73477 --- a/mm/page_alloc.c
73478 +++ b/mm/page_alloc.c
73479 @@ -335,7 +335,7 @@ out:
73480 * This usage means that zero-order pages may not be compound.
73481 */
73482
73483 -static void free_compound_page(struct page *page)
73484 +void free_compound_page(struct page *page)
73485 {
73486 __free_pages_ok(page, compound_order(page));
73487 }
73488 @@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73489 int i;
73490 int bad = 0;
73491
73492 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73493 + unsigned long index = 1UL << order;
73494 +#endif
73495 +
73496 trace_mm_page_free(page, order);
73497 kmemcheck_free_shadow(page, order);
73498
73499 @@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73500 debug_check_no_obj_freed(page_address(page),
73501 PAGE_SIZE << order);
73502 }
73503 +
73504 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73505 + for (; index; --index)
73506 + sanitize_highpage(page + index - 1);
73507 +#endif
73508 +
73509 arch_free_page(page, order);
73510 kernel_map_pages(page, 1 << order, 0);
73511
73512 @@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73513 arch_alloc_page(page, order);
73514 kernel_map_pages(page, 1 << order, 1);
73515
73516 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
73517 if (gfp_flags & __GFP_ZERO)
73518 prep_zero_page(page, order, gfp_flags);
73519 +#endif
73520
73521 if (order && (gfp_flags & __GFP_COMP))
73522 prep_compound_page(page, order);
73523 @@ -3468,7 +3480,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73524 unsigned long pfn;
73525
73526 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73527 +#ifdef CONFIG_X86_32
73528 + /* boot failures in VMware 8 on 32bit vanilla since
73529 + this change */
73530 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73531 +#else
73532 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73533 +#endif
73534 return 1;
73535 }
73536 return 0;
73537 diff --git a/mm/percpu.c b/mm/percpu.c
73538 index f47af91..7eeef99 100644
73539 --- a/mm/percpu.c
73540 +++ b/mm/percpu.c
73541 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73542 static unsigned int pcpu_high_unit_cpu __read_mostly;
73543
73544 /* the address of the first chunk which starts with the kernel static area */
73545 -void *pcpu_base_addr __read_mostly;
73546 +void *pcpu_base_addr __read_only;
73547 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73548
73549 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73550 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73551 index c20ff48..137702a 100644
73552 --- a/mm/process_vm_access.c
73553 +++ b/mm/process_vm_access.c
73554 @@ -13,6 +13,7 @@
73555 #include <linux/uio.h>
73556 #include <linux/sched.h>
73557 #include <linux/highmem.h>
73558 +#include <linux/security.h>
73559 #include <linux/ptrace.h>
73560 #include <linux/slab.h>
73561 #include <linux/syscalls.h>
73562 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73563 size_t iov_l_curr_offset = 0;
73564 ssize_t iov_len;
73565
73566 + return -ENOSYS; // PaX: until properly audited
73567 +
73568 /*
73569 * Work out how many pages of struct pages we're going to need
73570 * when eventually calling get_user_pages
73571 */
73572 for (i = 0; i < riovcnt; i++) {
73573 iov_len = rvec[i].iov_len;
73574 - if (iov_len > 0) {
73575 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
73576 - + iov_len)
73577 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73578 - / PAGE_SIZE + 1;
73579 - nr_pages = max(nr_pages, nr_pages_iov);
73580 - }
73581 + if (iov_len <= 0)
73582 + continue;
73583 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73584 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73585 + nr_pages = max(nr_pages, nr_pages_iov);
73586 }
73587
73588 if (nr_pages == 0)
73589 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73590 goto free_proc_pages;
73591 }
73592
73593 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73594 + rc = -EPERM;
73595 + goto put_task_struct;
73596 + }
73597 +
73598 mm = mm_access(task, PTRACE_MODE_ATTACH);
73599 if (!mm || IS_ERR(mm)) {
73600 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73601 diff --git a/mm/rmap.c b/mm/rmap.c
73602 index c8454e0..b04f3a2 100644
73603 --- a/mm/rmap.c
73604 +++ b/mm/rmap.c
73605 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73606 struct anon_vma *anon_vma = vma->anon_vma;
73607 struct anon_vma_chain *avc;
73608
73609 +#ifdef CONFIG_PAX_SEGMEXEC
73610 + struct anon_vma_chain *avc_m = NULL;
73611 +#endif
73612 +
73613 might_sleep();
73614 if (unlikely(!anon_vma)) {
73615 struct mm_struct *mm = vma->vm_mm;
73616 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73617 if (!avc)
73618 goto out_enomem;
73619
73620 +#ifdef CONFIG_PAX_SEGMEXEC
73621 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73622 + if (!avc_m)
73623 + goto out_enomem_free_avc;
73624 +#endif
73625 +
73626 anon_vma = find_mergeable_anon_vma(vma);
73627 allocated = NULL;
73628 if (!anon_vma) {
73629 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73630 /* page_table_lock to protect against threads */
73631 spin_lock(&mm->page_table_lock);
73632 if (likely(!vma->anon_vma)) {
73633 +
73634 +#ifdef CONFIG_PAX_SEGMEXEC
73635 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73636 +
73637 + if (vma_m) {
73638 + BUG_ON(vma_m->anon_vma);
73639 + vma_m->anon_vma = anon_vma;
73640 + avc_m->anon_vma = anon_vma;
73641 + avc_m->vma = vma;
73642 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
73643 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
73644 + avc_m = NULL;
73645 + }
73646 +#endif
73647 +
73648 vma->anon_vma = anon_vma;
73649 avc->anon_vma = anon_vma;
73650 avc->vma = vma;
73651 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73652
73653 if (unlikely(allocated))
73654 put_anon_vma(allocated);
73655 +
73656 +#ifdef CONFIG_PAX_SEGMEXEC
73657 + if (unlikely(avc_m))
73658 + anon_vma_chain_free(avc_m);
73659 +#endif
73660 +
73661 if (unlikely(avc))
73662 anon_vma_chain_free(avc);
73663 }
73664 return 0;
73665
73666 out_enomem_free_avc:
73667 +
73668 +#ifdef CONFIG_PAX_SEGMEXEC
73669 + if (avc_m)
73670 + anon_vma_chain_free(avc_m);
73671 +#endif
73672 +
73673 anon_vma_chain_free(avc);
73674 out_enomem:
73675 return -ENOMEM;
73676 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
73677 * Attach the anon_vmas from src to dst.
73678 * Returns 0 on success, -ENOMEM on failure.
73679 */
73680 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73681 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73682 {
73683 struct anon_vma_chain *avc, *pavc;
73684 struct anon_vma *root = NULL;
73685 @@ -321,7 +358,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73686 * the corresponding VMA in the parent process is attached to.
73687 * Returns 0 on success, non-zero on failure.
73688 */
73689 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73690 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73691 {
73692 struct anon_vma_chain *avc;
73693 struct anon_vma *anon_vma;
73694 diff --git a/mm/shmem.c b/mm/shmem.c
73695 index 269d049..a9d2b50 100644
73696 --- a/mm/shmem.c
73697 +++ b/mm/shmem.c
73698 @@ -31,7 +31,7 @@
73699 #include <linux/export.h>
73700 #include <linux/swap.h>
73701
73702 -static struct vfsmount *shm_mnt;
73703 +struct vfsmount *shm_mnt;
73704
73705 #ifdef CONFIG_SHMEM
73706 /*
73707 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
73708 #define BOGO_DIRENT_SIZE 20
73709
73710 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73711 -#define SHORT_SYMLINK_LEN 128
73712 +#define SHORT_SYMLINK_LEN 64
73713
73714 struct shmem_xattr {
73715 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73716 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73717 int err = -ENOMEM;
73718
73719 /* Round up to L1_CACHE_BYTES to resist false sharing */
73720 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73721 - L1_CACHE_BYTES), GFP_KERNEL);
73722 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73723 if (!sbinfo)
73724 return -ENOMEM;
73725
73726 diff --git a/mm/slab.c b/mm/slab.c
73727 index f0bd785..348b96a 100644
73728 --- a/mm/slab.c
73729 +++ b/mm/slab.c
73730 @@ -153,7 +153,7 @@
73731
73732 /* Legal flag mask for kmem_cache_create(). */
73733 #if DEBUG
73734 -# define CREATE_MASK (SLAB_RED_ZONE | \
73735 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73736 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73737 SLAB_CACHE_DMA | \
73738 SLAB_STORE_USER | \
73739 @@ -161,7 +161,7 @@
73740 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73741 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73742 #else
73743 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73744 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73745 SLAB_CACHE_DMA | \
73746 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73747 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73748 @@ -290,7 +290,7 @@ struct kmem_list3 {
73749 * Need this for bootstrapping a per node allocator.
73750 */
73751 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73752 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73753 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73754 #define CACHE_CACHE 0
73755 #define SIZE_AC MAX_NUMNODES
73756 #define SIZE_L3 (2 * MAX_NUMNODES)
73757 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73758 if ((x)->max_freeable < i) \
73759 (x)->max_freeable = i; \
73760 } while (0)
73761 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73762 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73763 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73764 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73765 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73766 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73767 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73768 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73769 #else
73770 #define STATS_INC_ACTIVE(x) do { } while (0)
73771 #define STATS_DEC_ACTIVE(x) do { } while (0)
73772 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73773 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73774 */
73775 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73776 - const struct slab *slab, void *obj)
73777 + const struct slab *slab, const void *obj)
73778 {
73779 u32 offset = (obj - slab->s_mem);
73780 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73781 @@ -568,7 +568,7 @@ struct cache_names {
73782 static struct cache_names __initdata cache_names[] = {
73783 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73784 #include <linux/kmalloc_sizes.h>
73785 - {NULL,}
73786 + {NULL}
73787 #undef CACHE
73788 };
73789
73790 @@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
73791 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73792 sizes[INDEX_AC].cs_size,
73793 ARCH_KMALLOC_MINALIGN,
73794 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73795 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73796 NULL);
73797
73798 if (INDEX_AC != INDEX_L3) {
73799 @@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
73800 kmem_cache_create(names[INDEX_L3].name,
73801 sizes[INDEX_L3].cs_size,
73802 ARCH_KMALLOC_MINALIGN,
73803 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73804 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73805 NULL);
73806 }
73807
73808 @@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
73809 sizes->cs_cachep = kmem_cache_create(names->name,
73810 sizes->cs_size,
73811 ARCH_KMALLOC_MINALIGN,
73812 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73813 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73814 NULL);
73815 }
73816 #ifdef CONFIG_ZONE_DMA
73817 @@ -4339,10 +4339,10 @@ static int s_show(struct seq_file *m, void *p)
73818 }
73819 /* cpu stats */
73820 {
73821 - unsigned long allochit = atomic_read(&cachep->allochit);
73822 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73823 - unsigned long freehit = atomic_read(&cachep->freehit);
73824 - unsigned long freemiss = atomic_read(&cachep->freemiss);
73825 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73826 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73827 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73828 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73829
73830 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73831 allochit, allocmiss, freehit, freemiss);
73832 @@ -4601,13 +4601,62 @@ static int __init slab_proc_init(void)
73833 {
73834 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73835 #ifdef CONFIG_DEBUG_SLAB_LEAK
73836 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73837 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73838 #endif
73839 return 0;
73840 }
73841 module_init(slab_proc_init);
73842 #endif
73843
73844 +void check_object_size(const void *ptr, unsigned long n, bool to)
73845 +{
73846 +
73847 +#ifdef CONFIG_PAX_USERCOPY
73848 + struct page *page;
73849 + struct kmem_cache *cachep = NULL;
73850 + struct slab *slabp;
73851 + unsigned int objnr;
73852 + unsigned long offset;
73853 + const char *type;
73854 +
73855 + if (!n)
73856 + return;
73857 +
73858 + type = "<null>";
73859 + if (ZERO_OR_NULL_PTR(ptr))
73860 + goto report;
73861 +
73862 + if (!virt_addr_valid(ptr))
73863 + return;
73864 +
73865 + page = virt_to_head_page(ptr);
73866 +
73867 + type = "<process stack>";
73868 + if (!PageSlab(page)) {
73869 + if (object_is_on_stack(ptr, n) == -1)
73870 + goto report;
73871 + return;
73872 + }
73873 +
73874 + cachep = page_get_cache(page);
73875 + type = cachep->name;
73876 + if (!(cachep->flags & SLAB_USERCOPY))
73877 + goto report;
73878 +
73879 + slabp = page_get_slab(page);
73880 + objnr = obj_to_index(cachep, slabp, ptr);
73881 + BUG_ON(objnr >= cachep->num);
73882 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73883 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73884 + return;
73885 +
73886 +report:
73887 + pax_report_usercopy(ptr, n, to, type);
73888 +#endif
73889 +
73890 +}
73891 +EXPORT_SYMBOL(check_object_size);
73892 +
73893 /**
73894 * ksize - get the actual amount of memory allocated for a given object
73895 * @objp: Pointer to the object
73896 diff --git a/mm/slob.c b/mm/slob.c
73897 index 8105be4..e045f96 100644
73898 --- a/mm/slob.c
73899 +++ b/mm/slob.c
73900 @@ -29,7 +29,7 @@
73901 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73902 * alloc_pages() directly, allocating compound pages so the page order
73903 * does not have to be separately tracked, and also stores the exact
73904 - * allocation size in page->private so that it can be used to accurately
73905 + * allocation size in slob_page->size so that it can be used to accurately
73906 * provide ksize(). These objects are detected in kfree() because slob_page()
73907 * is false for them.
73908 *
73909 @@ -58,6 +58,7 @@
73910 */
73911
73912 #include <linux/kernel.h>
73913 +#include <linux/sched.h>
73914 #include <linux/slab.h>
73915 #include <linux/mm.h>
73916 #include <linux/swap.h> /* struct reclaim_state */
73917 @@ -102,7 +103,8 @@ struct slob_page {
73918 unsigned long flags; /* mandatory */
73919 atomic_t _count; /* mandatory */
73920 slobidx_t units; /* free units left in page */
73921 - unsigned long pad[2];
73922 + unsigned long pad[1];
73923 + unsigned long size; /* size when >=PAGE_SIZE */
73924 slob_t *free; /* first free slob_t in page */
73925 struct list_head list; /* linked list of free pages */
73926 };
73927 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73928 */
73929 static inline int is_slob_page(struct slob_page *sp)
73930 {
73931 - return PageSlab((struct page *)sp);
73932 + return PageSlab((struct page *)sp) && !sp->size;
73933 }
73934
73935 static inline void set_slob_page(struct slob_page *sp)
73936 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73937
73938 static inline struct slob_page *slob_page(const void *addr)
73939 {
73940 - return (struct slob_page *)virt_to_page(addr);
73941 + return (struct slob_page *)virt_to_head_page(addr);
73942 }
73943
73944 /*
73945 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73946 /*
73947 * Return the size of a slob block.
73948 */
73949 -static slobidx_t slob_units(slob_t *s)
73950 +static slobidx_t slob_units(const slob_t *s)
73951 {
73952 if (s->units > 0)
73953 return s->units;
73954 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73955 /*
73956 * Return the next free slob block pointer after this one.
73957 */
73958 -static slob_t *slob_next(slob_t *s)
73959 +static slob_t *slob_next(const slob_t *s)
73960 {
73961 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73962 slobidx_t next;
73963 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73964 /*
73965 * Returns true if s is the last free block in its page.
73966 */
73967 -static int slob_last(slob_t *s)
73968 +static int slob_last(const slob_t *s)
73969 {
73970 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
73971 }
73972 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
73973 if (!page)
73974 return NULL;
73975
73976 + set_slob_page(page);
73977 return page_address(page);
73978 }
73979
73980 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
73981 if (!b)
73982 return NULL;
73983 sp = slob_page(b);
73984 - set_slob_page(sp);
73985
73986 spin_lock_irqsave(&slob_lock, flags);
73987 sp->units = SLOB_UNITS(PAGE_SIZE);
73988 sp->free = b;
73989 + sp->size = 0;
73990 INIT_LIST_HEAD(&sp->list);
73991 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
73992 set_slob_page_free(sp, slob_list);
73993 @@ -476,10 +479,9 @@ out:
73994 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
73995 */
73996
73997 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73998 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
73999 {
74000 - unsigned int *m;
74001 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74002 + slob_t *m;
74003 void *ret;
74004
74005 gfp &= gfp_allowed_mask;
74006 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74007
74008 if (!m)
74009 return NULL;
74010 - *m = size;
74011 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74012 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74013 + m[0].units = size;
74014 + m[1].units = align;
74015 ret = (void *)m + align;
74016
74017 trace_kmalloc_node(_RET_IP_, ret,
74018 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74019 gfp |= __GFP_COMP;
74020 ret = slob_new_pages(gfp, order, node);
74021 if (ret) {
74022 - struct page *page;
74023 - page = virt_to_page(ret);
74024 - page->private = size;
74025 + struct slob_page *sp;
74026 + sp = slob_page(ret);
74027 + sp->size = size;
74028 }
74029
74030 trace_kmalloc_node(_RET_IP_, ret,
74031 size, PAGE_SIZE << order, gfp, node);
74032 }
74033
74034 - kmemleak_alloc(ret, size, 1, gfp);
74035 + return ret;
74036 +}
74037 +
74038 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74039 +{
74040 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74041 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74042 +
74043 + if (!ZERO_OR_NULL_PTR(ret))
74044 + kmemleak_alloc(ret, size, 1, gfp);
74045 return ret;
74046 }
74047 EXPORT_SYMBOL(__kmalloc_node);
74048 @@ -533,13 +547,92 @@ void kfree(const void *block)
74049 sp = slob_page(block);
74050 if (is_slob_page(sp)) {
74051 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74052 - unsigned int *m = (unsigned int *)(block - align);
74053 - slob_free(m, *m + align);
74054 - } else
74055 + slob_t *m = (slob_t *)(block - align);
74056 + slob_free(m, m[0].units + align);
74057 + } else {
74058 + clear_slob_page(sp);
74059 + free_slob_page(sp);
74060 + sp->size = 0;
74061 put_page(&sp->page);
74062 + }
74063 }
74064 EXPORT_SYMBOL(kfree);
74065
74066 +void check_object_size(const void *ptr, unsigned long n, bool to)
74067 +{
74068 +
74069 +#ifdef CONFIG_PAX_USERCOPY
74070 + struct slob_page *sp;
74071 + const slob_t *free;
74072 + const void *base;
74073 + unsigned long flags;
74074 + const char *type;
74075 +
74076 + if (!n)
74077 + return;
74078 +
74079 + type = "<null>";
74080 + if (ZERO_OR_NULL_PTR(ptr))
74081 + goto report;
74082 +
74083 + if (!virt_addr_valid(ptr))
74084 + return;
74085 +
74086 + type = "<process stack>";
74087 + sp = slob_page(ptr);
74088 + if (!PageSlab((struct page *)sp)) {
74089 + if (object_is_on_stack(ptr, n) == -1)
74090 + goto report;
74091 + return;
74092 + }
74093 +
74094 + type = "<slob>";
74095 + if (sp->size) {
74096 + base = page_address(&sp->page);
74097 + if (base <= ptr && n <= sp->size - (ptr - base))
74098 + return;
74099 + goto report;
74100 + }
74101 +
74102 + /* some tricky double walking to find the chunk */
74103 + spin_lock_irqsave(&slob_lock, flags);
74104 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74105 + free = sp->free;
74106 +
74107 + while (!slob_last(free) && (void *)free <= ptr) {
74108 + base = free + slob_units(free);
74109 + free = slob_next(free);
74110 + }
74111 +
74112 + while (base < (void *)free) {
74113 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74114 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74115 + int offset;
74116 +
74117 + if (ptr < base + align)
74118 + break;
74119 +
74120 + offset = ptr - base - align;
74121 + if (offset >= m) {
74122 + base += size;
74123 + continue;
74124 + }
74125 +
74126 + if (n > m - offset)
74127 + break;
74128 +
74129 + spin_unlock_irqrestore(&slob_lock, flags);
74130 + return;
74131 + }
74132 +
74133 + spin_unlock_irqrestore(&slob_lock, flags);
74134 +report:
74135 + pax_report_usercopy(ptr, n, to, type);
74136 +#endif
74137 +
74138 +}
74139 +EXPORT_SYMBOL(check_object_size);
74140 +
74141 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74142 size_t ksize(const void *block)
74143 {
74144 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
74145 sp = slob_page(block);
74146 if (is_slob_page(sp)) {
74147 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74148 - unsigned int *m = (unsigned int *)(block - align);
74149 - return SLOB_UNITS(*m) * SLOB_UNIT;
74150 + slob_t *m = (slob_t *)(block - align);
74151 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74152 } else
74153 - return sp->page.private;
74154 + return sp->size;
74155 }
74156 EXPORT_SYMBOL(ksize);
74157
74158 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74159 {
74160 struct kmem_cache *c;
74161
74162 +#ifdef CONFIG_PAX_USERCOPY
74163 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74164 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74165 +#else
74166 c = slob_alloc(sizeof(struct kmem_cache),
74167 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74168 +#endif
74169
74170 if (c) {
74171 c->name = name;
74172 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74173
74174 lockdep_trace_alloc(flags);
74175
74176 +#ifdef CONFIG_PAX_USERCOPY
74177 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74178 +#else
74179 if (c->size < PAGE_SIZE) {
74180 b = slob_alloc(c->size, flags, c->align, node);
74181 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74182 SLOB_UNITS(c->size) * SLOB_UNIT,
74183 flags, node);
74184 } else {
74185 + struct slob_page *sp;
74186 +
74187 b = slob_new_pages(flags, get_order(c->size), node);
74188 + sp = slob_page(b);
74189 + sp->size = c->size;
74190 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74191 PAGE_SIZE << get_order(c->size),
74192 flags, node);
74193 }
74194 +#endif
74195
74196 if (c->ctor)
74197 c->ctor(b);
74198 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74199
74200 static void __kmem_cache_free(void *b, int size)
74201 {
74202 - if (size < PAGE_SIZE)
74203 + struct slob_page *sp = slob_page(b);
74204 +
74205 + if (is_slob_page(sp))
74206 slob_free(b, size);
74207 - else
74208 + else {
74209 + clear_slob_page(sp);
74210 + free_slob_page(sp);
74211 + sp->size = 0;
74212 slob_free_pages(b, get_order(size));
74213 + }
74214 }
74215
74216 static void kmem_rcu_free(struct rcu_head *head)
74217 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74218
74219 void kmem_cache_free(struct kmem_cache *c, void *b)
74220 {
74221 + int size = c->size;
74222 +
74223 +#ifdef CONFIG_PAX_USERCOPY
74224 + if (size + c->align < PAGE_SIZE) {
74225 + size += c->align;
74226 + b -= c->align;
74227 + }
74228 +#endif
74229 +
74230 kmemleak_free_recursive(b, c->flags);
74231 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74232 struct slob_rcu *slob_rcu;
74233 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74234 - slob_rcu->size = c->size;
74235 + slob_rcu = b + (size - sizeof(struct slob_rcu));
74236 + slob_rcu->size = size;
74237 call_rcu(&slob_rcu->head, kmem_rcu_free);
74238 } else {
74239 - __kmem_cache_free(b, c->size);
74240 + __kmem_cache_free(b, size);
74241 }
74242
74243 +#ifdef CONFIG_PAX_USERCOPY
74244 + trace_kfree(_RET_IP_, b);
74245 +#else
74246 trace_kmem_cache_free(_RET_IP_, b);
74247 +#endif
74248 +
74249 }
74250 EXPORT_SYMBOL(kmem_cache_free);
74251
74252 diff --git a/mm/slub.c b/mm/slub.c
74253 index 0342a5d..8180ae9 100644
74254 --- a/mm/slub.c
74255 +++ b/mm/slub.c
74256 @@ -208,7 +208,7 @@ struct track {
74257
74258 enum track_item { TRACK_ALLOC, TRACK_FREE };
74259
74260 -#ifdef CONFIG_SYSFS
74261 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74262 static int sysfs_slab_add(struct kmem_cache *);
74263 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74264 static void sysfs_slab_remove(struct kmem_cache *);
74265 @@ -532,7 +532,7 @@ static void print_track(const char *s, struct track *t)
74266 if (!t->addr)
74267 return;
74268
74269 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74270 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74271 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74272 #ifdef CONFIG_STACKTRACE
74273 {
74274 @@ -2571,6 +2571,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74275
74276 page = virt_to_head_page(x);
74277
74278 + BUG_ON(!PageSlab(page));
74279 +
74280 slab_free(s, page, x, _RET_IP_);
74281
74282 trace_kmem_cache_free(_RET_IP_, x);
74283 @@ -2604,7 +2606,7 @@ static int slub_min_objects;
74284 * Merge control. If this is set then no merging of slab caches will occur.
74285 * (Could be removed. This was introduced to pacify the merge skeptics.)
74286 */
74287 -static int slub_nomerge;
74288 +static int slub_nomerge = 1;
74289
74290 /*
74291 * Calculate the order of allocation given an slab object size.
74292 @@ -3057,7 +3059,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74293 else
74294 s->cpu_partial = 30;
74295
74296 - s->refcount = 1;
74297 + atomic_set(&s->refcount, 1);
74298 #ifdef CONFIG_NUMA
74299 s->remote_node_defrag_ratio = 1000;
74300 #endif
74301 @@ -3161,8 +3163,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74302 void kmem_cache_destroy(struct kmem_cache *s)
74303 {
74304 down_write(&slub_lock);
74305 - s->refcount--;
74306 - if (!s->refcount) {
74307 + if (atomic_dec_and_test(&s->refcount)) {
74308 list_del(&s->list);
74309 up_write(&slub_lock);
74310 if (kmem_cache_close(s)) {
74311 @@ -3373,6 +3374,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74312 EXPORT_SYMBOL(__kmalloc_node);
74313 #endif
74314
74315 +void check_object_size(const void *ptr, unsigned long n, bool to)
74316 +{
74317 +
74318 +#ifdef CONFIG_PAX_USERCOPY
74319 + struct page *page;
74320 + struct kmem_cache *s = NULL;
74321 + unsigned long offset;
74322 + const char *type;
74323 +
74324 + if (!n)
74325 + return;
74326 +
74327 + type = "<null>";
74328 + if (ZERO_OR_NULL_PTR(ptr))
74329 + goto report;
74330 +
74331 + if (!virt_addr_valid(ptr))
74332 + return;
74333 +
74334 + page = virt_to_head_page(ptr);
74335 +
74336 + type = "<process stack>";
74337 + if (!PageSlab(page)) {
74338 + if (object_is_on_stack(ptr, n) == -1)
74339 + goto report;
74340 + return;
74341 + }
74342 +
74343 + s = page->slab;
74344 + type = s->name;
74345 + if (!(s->flags & SLAB_USERCOPY))
74346 + goto report;
74347 +
74348 + offset = (ptr - page_address(page)) % s->size;
74349 + if (offset <= s->objsize && n <= s->objsize - offset)
74350 + return;
74351 +
74352 +report:
74353 + pax_report_usercopy(ptr, n, to, type);
74354 +#endif
74355 +
74356 +}
74357 +EXPORT_SYMBOL(check_object_size);
74358 +
74359 size_t ksize(const void *object)
74360 {
74361 struct page *page;
74362 @@ -3647,7 +3692,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74363 int node;
74364
74365 list_add(&s->list, &slab_caches);
74366 - s->refcount = -1;
74367 + atomic_set(&s->refcount, -1);
74368
74369 for_each_node_state(node, N_NORMAL_MEMORY) {
74370 struct kmem_cache_node *n = get_node(s, node);
74371 @@ -3767,17 +3812,17 @@ void __init kmem_cache_init(void)
74372
74373 /* Caches that are not of the two-to-the-power-of size */
74374 if (KMALLOC_MIN_SIZE <= 32) {
74375 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74376 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74377 caches++;
74378 }
74379
74380 if (KMALLOC_MIN_SIZE <= 64) {
74381 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74382 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74383 caches++;
74384 }
74385
74386 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74387 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74388 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74389 caches++;
74390 }
74391
74392 @@ -3845,7 +3890,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74393 /*
74394 * We may have set a slab to be unmergeable during bootstrap.
74395 */
74396 - if (s->refcount < 0)
74397 + if (atomic_read(&s->refcount) < 0)
74398 return 1;
74399
74400 return 0;
74401 @@ -3904,7 +3949,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74402 down_write(&slub_lock);
74403 s = find_mergeable(size, align, flags, name, ctor);
74404 if (s) {
74405 - s->refcount++;
74406 + atomic_inc(&s->refcount);
74407 /*
74408 * Adjust the object sizes so that we clear
74409 * the complete object on kzalloc.
74410 @@ -3913,7 +3958,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74411 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74412
74413 if (sysfs_slab_alias(s, name)) {
74414 - s->refcount--;
74415 + atomic_dec(&s->refcount);
74416 goto err;
74417 }
74418 up_write(&slub_lock);
74419 @@ -4042,7 +4087,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74420 }
74421 #endif
74422
74423 -#ifdef CONFIG_SYSFS
74424 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74425 static int count_inuse(struct page *page)
74426 {
74427 return page->inuse;
74428 @@ -4429,12 +4474,12 @@ static void resiliency_test(void)
74429 validate_slab_cache(kmalloc_caches[9]);
74430 }
74431 #else
74432 -#ifdef CONFIG_SYSFS
74433 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74434 static void resiliency_test(void) {};
74435 #endif
74436 #endif
74437
74438 -#ifdef CONFIG_SYSFS
74439 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74440 enum slab_stat_type {
74441 SL_ALL, /* All slabs */
74442 SL_PARTIAL, /* Only partially allocated slabs */
74443 @@ -4677,7 +4722,7 @@ SLAB_ATTR_RO(ctor);
74444
74445 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74446 {
74447 - return sprintf(buf, "%d\n", s->refcount - 1);
74448 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74449 }
74450 SLAB_ATTR_RO(aliases);
74451
74452 @@ -5244,6 +5289,7 @@ static char *create_unique_id(struct kmem_cache *s)
74453 return name;
74454 }
74455
74456 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74457 static int sysfs_slab_add(struct kmem_cache *s)
74458 {
74459 int err;
74460 @@ -5306,6 +5352,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74461 kobject_del(&s->kobj);
74462 kobject_put(&s->kobj);
74463 }
74464 +#endif
74465
74466 /*
74467 * Need to buffer aliases during bootup until sysfs becomes
74468 @@ -5319,6 +5366,7 @@ struct saved_alias {
74469
74470 static struct saved_alias *alias_list;
74471
74472 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74473 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74474 {
74475 struct saved_alias *al;
74476 @@ -5341,6 +5389,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74477 alias_list = al;
74478 return 0;
74479 }
74480 +#endif
74481
74482 static int __init slab_sysfs_init(void)
74483 {
74484 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74485 index 1b7e22a..3fcd4f3 100644
74486 --- a/mm/sparse-vmemmap.c
74487 +++ b/mm/sparse-vmemmap.c
74488 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74489 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74490 if (!p)
74491 return NULL;
74492 - pud_populate(&init_mm, pud, p);
74493 + pud_populate_kernel(&init_mm, pud, p);
74494 }
74495 return pud;
74496 }
74497 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74498 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74499 if (!p)
74500 return NULL;
74501 - pgd_populate(&init_mm, pgd, p);
74502 + pgd_populate_kernel(&init_mm, pgd, p);
74503 }
74504 return pgd;
74505 }
74506 diff --git a/mm/swap.c b/mm/swap.c
74507 index 14380e9..e244704 100644
74508 --- a/mm/swap.c
74509 +++ b/mm/swap.c
74510 @@ -30,6 +30,7 @@
74511 #include <linux/backing-dev.h>
74512 #include <linux/memcontrol.h>
74513 #include <linux/gfp.h>
74514 +#include <linux/hugetlb.h>
74515
74516 #include "internal.h"
74517
74518 @@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
74519
74520 __page_cache_release(page);
74521 dtor = get_compound_page_dtor(page);
74522 + if (!PageHuge(page))
74523 + BUG_ON(dtor != free_compound_page);
74524 (*dtor)(page);
74525 }
74526
74527 diff --git a/mm/swapfile.c b/mm/swapfile.c
74528 index f31b29d..8bdcae2 100644
74529 --- a/mm/swapfile.c
74530 +++ b/mm/swapfile.c
74531 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
74532
74533 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74534 /* Activity counter to indicate that a swapon or swapoff has occurred */
74535 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74536 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74537
74538 static inline unsigned char swap_count(unsigned char ent)
74539 {
74540 @@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74541 }
74542 filp_close(swap_file, NULL);
74543 err = 0;
74544 - atomic_inc(&proc_poll_event);
74545 + atomic_inc_unchecked(&proc_poll_event);
74546 wake_up_interruptible(&proc_poll_wait);
74547
74548 out_dput:
74549 @@ -1685,8 +1685,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74550
74551 poll_wait(file, &proc_poll_wait, wait);
74552
74553 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74554 - seq->poll_event = atomic_read(&proc_poll_event);
74555 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74556 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74557 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74558 }
74559
74560 @@ -1784,7 +1784,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74561 return ret;
74562
74563 seq = file->private_data;
74564 - seq->poll_event = atomic_read(&proc_poll_event);
74565 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74566 return 0;
74567 }
74568
74569 @@ -2122,7 +2122,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74570 (p->flags & SWP_DISCARDABLE) ? "D" : "");
74571
74572 mutex_unlock(&swapon_mutex);
74573 - atomic_inc(&proc_poll_event);
74574 + atomic_inc_unchecked(&proc_poll_event);
74575 wake_up_interruptible(&proc_poll_wait);
74576
74577 if (S_ISREG(inode->i_mode))
74578 diff --git a/mm/util.c b/mm/util.c
74579 index 136ac4f..f917fa9 100644
74580 --- a/mm/util.c
74581 +++ b/mm/util.c
74582 @@ -243,6 +243,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
74583 void arch_pick_mmap_layout(struct mm_struct *mm)
74584 {
74585 mm->mmap_base = TASK_UNMAPPED_BASE;
74586 +
74587 +#ifdef CONFIG_PAX_RANDMMAP
74588 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74589 + mm->mmap_base += mm->delta_mmap;
74590 +#endif
74591 +
74592 mm->get_unmapped_area = arch_get_unmapped_area;
74593 mm->unmap_area = arch_unmap_area;
74594 }
74595 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74596 index 86ce9a5..e0bd080 100644
74597 --- a/mm/vmalloc.c
74598 +++ b/mm/vmalloc.c
74599 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74600
74601 pte = pte_offset_kernel(pmd, addr);
74602 do {
74603 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74604 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74605 +
74606 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74607 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74608 + BUG_ON(!pte_exec(*pte));
74609 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74610 + continue;
74611 + }
74612 +#endif
74613 +
74614 + {
74615 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74616 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74617 + }
74618 } while (pte++, addr += PAGE_SIZE, addr != end);
74619 }
74620
74621 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74622 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74623 {
74624 pte_t *pte;
74625 + int ret = -ENOMEM;
74626
74627 /*
74628 * nr is a running index into the array which helps higher level
74629 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74630 pte = pte_alloc_kernel(pmd, addr);
74631 if (!pte)
74632 return -ENOMEM;
74633 +
74634 + pax_open_kernel();
74635 do {
74636 struct page *page = pages[*nr];
74637
74638 - if (WARN_ON(!pte_none(*pte)))
74639 - return -EBUSY;
74640 - if (WARN_ON(!page))
74641 - return -ENOMEM;
74642 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74643 + if (pgprot_val(prot) & _PAGE_NX)
74644 +#endif
74645 +
74646 + if (WARN_ON(!pte_none(*pte))) {
74647 + ret = -EBUSY;
74648 + goto out;
74649 + }
74650 + if (WARN_ON(!page)) {
74651 + ret = -ENOMEM;
74652 + goto out;
74653 + }
74654 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74655 (*nr)++;
74656 } while (pte++, addr += PAGE_SIZE, addr != end);
74657 - return 0;
74658 + ret = 0;
74659 +out:
74660 + pax_close_kernel();
74661 + return ret;
74662 }
74663
74664 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74665 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74666 pmd_t *pmd;
74667 unsigned long next;
74668
74669 - pmd = pmd_alloc(&init_mm, pud, addr);
74670 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74671 if (!pmd)
74672 return -ENOMEM;
74673 do {
74674 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
74675 pud_t *pud;
74676 unsigned long next;
74677
74678 - pud = pud_alloc(&init_mm, pgd, addr);
74679 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
74680 if (!pud)
74681 return -ENOMEM;
74682 do {
74683 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74684 * and fall back on vmalloc() if that fails. Others
74685 * just put it in the vmalloc space.
74686 */
74687 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74688 +#ifdef CONFIG_MODULES
74689 +#ifdef MODULES_VADDR
74690 unsigned long addr = (unsigned long)x;
74691 if (addr >= MODULES_VADDR && addr < MODULES_END)
74692 return 1;
74693 #endif
74694 +
74695 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74696 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74697 + return 1;
74698 +#endif
74699 +
74700 +#endif
74701 +
74702 return is_vmalloc_addr(x);
74703 }
74704
74705 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74706
74707 if (!pgd_none(*pgd)) {
74708 pud_t *pud = pud_offset(pgd, addr);
74709 +#ifdef CONFIG_X86
74710 + if (!pud_large(*pud))
74711 +#endif
74712 if (!pud_none(*pud)) {
74713 pmd_t *pmd = pmd_offset(pud, addr);
74714 +#ifdef CONFIG_X86
74715 + if (!pmd_large(*pmd))
74716 +#endif
74717 if (!pmd_none(*pmd)) {
74718 pte_t *ptep, pte;
74719
74720 @@ -1319,6 +1359,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74721 struct vm_struct *area;
74722
74723 BUG_ON(in_interrupt());
74724 +
74725 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74726 + if (flags & VM_KERNEXEC) {
74727 + if (start != VMALLOC_START || end != VMALLOC_END)
74728 + return NULL;
74729 + start = (unsigned long)MODULES_EXEC_VADDR;
74730 + end = (unsigned long)MODULES_EXEC_END;
74731 + }
74732 +#endif
74733 +
74734 if (flags & VM_IOREMAP) {
74735 int bit = fls(size);
74736
74737 @@ -1551,6 +1601,11 @@ void *vmap(struct page **pages, unsigned int count,
74738 if (count > totalram_pages)
74739 return NULL;
74740
74741 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74742 + if (!(pgprot_val(prot) & _PAGE_NX))
74743 + flags |= VM_KERNEXEC;
74744 +#endif
74745 +
74746 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74747 __builtin_return_address(0));
74748 if (!area)
74749 @@ -1652,6 +1707,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74750 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74751 goto fail;
74752
74753 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74754 + if (!(pgprot_val(prot) & _PAGE_NX))
74755 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74756 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74757 + else
74758 +#endif
74759 +
74760 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74761 start, end, node, gfp_mask, caller);
74762 if (!area)
74763 @@ -1825,10 +1887,9 @@ EXPORT_SYMBOL(vzalloc_node);
74764 * For tight control over page level allocator and protection flags
74765 * use __vmalloc() instead.
74766 */
74767 -
74768 void *vmalloc_exec(unsigned long size)
74769 {
74770 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74771 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74772 -1, __builtin_return_address(0));
74773 }
74774
74775 @@ -2123,6 +2184,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74776 unsigned long uaddr = vma->vm_start;
74777 unsigned long usize = vma->vm_end - vma->vm_start;
74778
74779 + BUG_ON(vma->vm_mirror);
74780 +
74781 if ((PAGE_SIZE-1) & (unsigned long)addr)
74782 return -EINVAL;
74783
74784 diff --git a/mm/vmstat.c b/mm/vmstat.c
74785 index f600557..1459fc8 100644
74786 --- a/mm/vmstat.c
74787 +++ b/mm/vmstat.c
74788 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74789 *
74790 * vm_stat contains the global counters
74791 */
74792 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74793 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74794 EXPORT_SYMBOL(vm_stat);
74795
74796 #ifdef CONFIG_SMP
74797 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74798 v = p->vm_stat_diff[i];
74799 p->vm_stat_diff[i] = 0;
74800 local_irq_restore(flags);
74801 - atomic_long_add(v, &zone->vm_stat[i]);
74802 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74803 global_diff[i] += v;
74804 #ifdef CONFIG_NUMA
74805 /* 3 seconds idle till flush */
74806 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74807
74808 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74809 if (global_diff[i])
74810 - atomic_long_add(global_diff[i], &vm_stat[i]);
74811 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74812 }
74813
74814 #endif
74815 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
74816 start_cpu_timer(cpu);
74817 #endif
74818 #ifdef CONFIG_PROC_FS
74819 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74820 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74821 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74822 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74823 + {
74824 + mode_t gr_mode = S_IRUGO;
74825 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74826 + gr_mode = S_IRUSR;
74827 +#endif
74828 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74829 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74830 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74831 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74832 +#else
74833 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74834 +#endif
74835 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74836 + }
74837 #endif
74838 return 0;
74839 }
74840 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74841 index efea35b..9c8dd0b 100644
74842 --- a/net/8021q/vlan.c
74843 +++ b/net/8021q/vlan.c
74844 @@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74845 err = -EPERM;
74846 if (!capable(CAP_NET_ADMIN))
74847 break;
74848 - if ((args.u.name_type >= 0) &&
74849 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74850 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74851 struct vlan_net *vn;
74852
74853 vn = net_generic(net, vlan_net_id);
74854 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74855 index fccae26..e7ece2f 100644
74856 --- a/net/9p/trans_fd.c
74857 +++ b/net/9p/trans_fd.c
74858 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74859 oldfs = get_fs();
74860 set_fs(get_ds());
74861 /* The cast to a user pointer is valid due to the set_fs() */
74862 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74863 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74864 set_fs(oldfs);
74865
74866 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74867 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74868 index 876fbe8..8bbea9f 100644
74869 --- a/net/atm/atm_misc.c
74870 +++ b/net/atm/atm_misc.c
74871 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74872 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74873 return 1;
74874 atm_return(vcc, truesize);
74875 - atomic_inc(&vcc->stats->rx_drop);
74876 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74877 return 0;
74878 }
74879 EXPORT_SYMBOL(atm_charge);
74880 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74881 }
74882 }
74883 atm_return(vcc, guess);
74884 - atomic_inc(&vcc->stats->rx_drop);
74885 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74886 return NULL;
74887 }
74888 EXPORT_SYMBOL(atm_alloc_charge);
74889 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74890
74891 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74892 {
74893 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74894 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74895 __SONET_ITEMS
74896 #undef __HANDLE_ITEM
74897 }
74898 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74899
74900 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74901 {
74902 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74903 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74904 __SONET_ITEMS
74905 #undef __HANDLE_ITEM
74906 }
74907 diff --git a/net/atm/lec.h b/net/atm/lec.h
74908 index dfc0719..47c5322 100644
74909 --- a/net/atm/lec.h
74910 +++ b/net/atm/lec.h
74911 @@ -48,7 +48,7 @@ struct lane2_ops {
74912 const u8 *tlvs, u32 sizeoftlvs);
74913 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
74914 const u8 *tlvs, u32 sizeoftlvs);
74915 -};
74916 +} __no_const;
74917
74918 /*
74919 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
74920 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
74921 index 0919a88..a23d54e 100644
74922 --- a/net/atm/mpc.h
74923 +++ b/net/atm/mpc.h
74924 @@ -33,7 +33,7 @@ struct mpoa_client {
74925 struct mpc_parameters parameters; /* parameters for this client */
74926
74927 const struct net_device_ops *old_ops;
74928 - struct net_device_ops new_ops;
74929 + net_device_ops_no_const new_ops;
74930 };
74931
74932
74933 diff --git a/net/atm/proc.c b/net/atm/proc.c
74934 index 0d020de..011c7bb 100644
74935 --- a/net/atm/proc.c
74936 +++ b/net/atm/proc.c
74937 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
74938 const struct k_atm_aal_stats *stats)
74939 {
74940 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
74941 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
74942 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
74943 - atomic_read(&stats->rx_drop));
74944 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
74945 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
74946 + atomic_read_unchecked(&stats->rx_drop));
74947 }
74948
74949 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
74950 diff --git a/net/atm/resources.c b/net/atm/resources.c
74951 index 23f45ce..c748f1a 100644
74952 --- a/net/atm/resources.c
74953 +++ b/net/atm/resources.c
74954 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
74955 static void copy_aal_stats(struct k_atm_aal_stats *from,
74956 struct atm_aal_stats *to)
74957 {
74958 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74959 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74960 __AAL_STAT_ITEMS
74961 #undef __HANDLE_ITEM
74962 }
74963 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
74964 static void subtract_aal_stats(struct k_atm_aal_stats *from,
74965 struct atm_aal_stats *to)
74966 {
74967 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74968 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
74969 __AAL_STAT_ITEMS
74970 #undef __HANDLE_ITEM
74971 }
74972 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
74973 index 3512e25..2b33401 100644
74974 --- a/net/batman-adv/bat_iv_ogm.c
74975 +++ b/net/batman-adv/bat_iv_ogm.c
74976 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74977
74978 /* change sequence number to network order */
74979 batman_ogm_packet->seqno =
74980 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
74981 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
74982
74983 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
74984 batman_ogm_packet->tt_crc = htons((uint16_t)
74985 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74986 else
74987 batman_ogm_packet->gw_flags = NO_FLAGS;
74988
74989 - atomic_inc(&hard_iface->seqno);
74990 + atomic_inc_unchecked(&hard_iface->seqno);
74991
74992 slide_own_bcast_window(hard_iface);
74993 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
74994 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
74995 return;
74996
74997 /* could be changed by schedule_own_packet() */
74998 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
74999 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75000
75001 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
75002
75003 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75004 index 7704df4..beb4e16 100644
75005 --- a/net/batman-adv/hard-interface.c
75006 +++ b/net/batman-adv/hard-interface.c
75007 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
75008 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75009 dev_add_pack(&hard_iface->batman_adv_ptype);
75010
75011 - atomic_set(&hard_iface->seqno, 1);
75012 - atomic_set(&hard_iface->frag_seqno, 1);
75013 + atomic_set_unchecked(&hard_iface->seqno, 1);
75014 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75015 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75016 hard_iface->net_dev->name);
75017
75018 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75019 index 987c75a..20d6f36 100644
75020 --- a/net/batman-adv/soft-interface.c
75021 +++ b/net/batman-adv/soft-interface.c
75022 @@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
75023
75024 /* set broadcast sequence number */
75025 bcast_packet->seqno =
75026 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75027 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75028
75029 add_bcast_packet_to_list(bat_priv, skb, 1);
75030
75031 @@ -843,7 +843,7 @@ struct net_device *softif_create(const char *name)
75032 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75033
75034 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75035 - atomic_set(&bat_priv->bcast_seqno, 1);
75036 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75037 atomic_set(&bat_priv->ttvn, 0);
75038 atomic_set(&bat_priv->tt_local_changes, 0);
75039 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75040 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75041 index e9eb043..d174eeb 100644
75042 --- a/net/batman-adv/types.h
75043 +++ b/net/batman-adv/types.h
75044 @@ -38,8 +38,8 @@ struct hard_iface {
75045 int16_t if_num;
75046 char if_status;
75047 struct net_device *net_dev;
75048 - atomic_t seqno;
75049 - atomic_t frag_seqno;
75050 + atomic_unchecked_t seqno;
75051 + atomic_unchecked_t frag_seqno;
75052 unsigned char *packet_buff;
75053 int packet_len;
75054 struct kobject *hardif_obj;
75055 @@ -154,7 +154,7 @@ struct bat_priv {
75056 atomic_t orig_interval; /* uint */
75057 atomic_t hop_penalty; /* uint */
75058 atomic_t log_level; /* uint */
75059 - atomic_t bcast_seqno;
75060 + atomic_unchecked_t bcast_seqno;
75061 atomic_t bcast_queue_left;
75062 atomic_t batman_queue_left;
75063 atomic_t ttvn; /* translation table version number */
75064 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75065 index 07d1c1d..7e9bea9 100644
75066 --- a/net/batman-adv/unicast.c
75067 +++ b/net/batman-adv/unicast.c
75068 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
75069 frag1->flags = UNI_FRAG_HEAD | large_tail;
75070 frag2->flags = large_tail;
75071
75072 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75073 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75074 frag1->seqno = htons(seqno - 1);
75075 frag2->seqno = htons(seqno);
75076
75077 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
75078 index 280953b..cd219bb 100644
75079 --- a/net/bluetooth/hci_conn.c
75080 +++ b/net/bluetooth/hci_conn.c
75081 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
75082 memset(&cp, 0, sizeof(cp));
75083
75084 cp.handle = cpu_to_le16(conn->handle);
75085 - memcpy(cp.ltk, ltk, sizeof(ltk));
75086 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
75087
75088 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
75089 }
75090 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75091 index 32d338c..d24bcdb 100644
75092 --- a/net/bluetooth/l2cap_core.c
75093 +++ b/net/bluetooth/l2cap_core.c
75094 @@ -2418,8 +2418,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75095 break;
75096
75097 case L2CAP_CONF_RFC:
75098 - if (olen == sizeof(rfc))
75099 - memcpy(&rfc, (void *)val, olen);
75100 + if (olen != sizeof(rfc))
75101 + break;
75102 +
75103 + memcpy(&rfc, (void *)val, olen);
75104
75105 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75106 rfc.mode != chan->mode)
75107 @@ -2537,8 +2539,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
75108
75109 switch (type) {
75110 case L2CAP_CONF_RFC:
75111 - if (olen == sizeof(rfc))
75112 - memcpy(&rfc, (void *)val, olen);
75113 + if (olen != sizeof(rfc))
75114 + break;
75115 +
75116 + memcpy(&rfc, (void *)val, olen);
75117 goto done;
75118 }
75119 }
75120 diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
75121 index 5449294..7da9a5f 100644
75122 --- a/net/bridge/netfilter/ebt_ulog.c
75123 +++ b/net/bridge/netfilter/ebt_ulog.c
75124 @@ -96,6 +96,7 @@ static void ulog_timer(unsigned long data)
75125 spin_unlock_bh(&ulog_buffers[data].lock);
75126 }
75127
75128 +static struct sk_buff *ulog_alloc_skb(unsigned int size) __size_overflow(1);
75129 static struct sk_buff *ulog_alloc_skb(unsigned int size)
75130 {
75131 struct sk_buff *skb;
75132 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75133 index 5fe2ff3..10968b5 100644
75134 --- a/net/bridge/netfilter/ebtables.c
75135 +++ b/net/bridge/netfilter/ebtables.c
75136 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75137 tmp.valid_hooks = t->table->valid_hooks;
75138 }
75139 mutex_unlock(&ebt_mutex);
75140 - if (copy_to_user(user, &tmp, *len) != 0){
75141 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75142 BUGPRINT("c2u Didn't work\n");
75143 ret = -EFAULT;
75144 break;
75145 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
75146 index a97d97a..6f679ed 100644
75147 --- a/net/caif/caif_socket.c
75148 +++ b/net/caif/caif_socket.c
75149 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
75150 #ifdef CONFIG_DEBUG_FS
75151 struct debug_fs_counter {
75152 atomic_t caif_nr_socks;
75153 - atomic_t caif_sock_create;
75154 - atomic_t num_connect_req;
75155 - atomic_t num_connect_resp;
75156 - atomic_t num_connect_fail_resp;
75157 - atomic_t num_disconnect;
75158 - atomic_t num_remote_shutdown_ind;
75159 - atomic_t num_tx_flow_off_ind;
75160 - atomic_t num_tx_flow_on_ind;
75161 - atomic_t num_rx_flow_off;
75162 - atomic_t num_rx_flow_on;
75163 + atomic_unchecked_t caif_sock_create;
75164 + atomic_unchecked_t num_connect_req;
75165 + atomic_unchecked_t num_connect_resp;
75166 + atomic_unchecked_t num_connect_fail_resp;
75167 + atomic_unchecked_t num_disconnect;
75168 + atomic_unchecked_t num_remote_shutdown_ind;
75169 + atomic_unchecked_t num_tx_flow_off_ind;
75170 + atomic_unchecked_t num_tx_flow_on_ind;
75171 + atomic_unchecked_t num_rx_flow_off;
75172 + atomic_unchecked_t num_rx_flow_on;
75173 };
75174 static struct debug_fs_counter cnt;
75175 #define dbfs_atomic_inc(v) atomic_inc_return(v)
75176 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
75177 #define dbfs_atomic_dec(v) atomic_dec_return(v)
75178 #else
75179 #define dbfs_atomic_inc(v) 0
75180 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75181 atomic_read(&cf_sk->sk.sk_rmem_alloc),
75182 sk_rcvbuf_lowwater(cf_sk));
75183 set_rx_flow_off(cf_sk);
75184 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75185 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75186 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75187 }
75188
75189 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75190 set_rx_flow_off(cf_sk);
75191 if (net_ratelimit())
75192 pr_debug("sending flow OFF due to rmem_schedule\n");
75193 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75194 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75195 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75196 }
75197 skb->dev = NULL;
75198 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
75199 switch (flow) {
75200 case CAIF_CTRLCMD_FLOW_ON_IND:
75201 /* OK from modem to start sending again */
75202 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
75203 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
75204 set_tx_flow_on(cf_sk);
75205 cf_sk->sk.sk_state_change(&cf_sk->sk);
75206 break;
75207
75208 case CAIF_CTRLCMD_FLOW_OFF_IND:
75209 /* Modem asks us to shut up */
75210 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
75211 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
75212 set_tx_flow_off(cf_sk);
75213 cf_sk->sk.sk_state_change(&cf_sk->sk);
75214 break;
75215 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
75216 /* We're now connected */
75217 caif_client_register_refcnt(&cf_sk->layer,
75218 cfsk_hold, cfsk_put);
75219 - dbfs_atomic_inc(&cnt.num_connect_resp);
75220 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
75221 cf_sk->sk.sk_state = CAIF_CONNECTED;
75222 set_tx_flow_on(cf_sk);
75223 cf_sk->sk.sk_state_change(&cf_sk->sk);
75224 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
75225
75226 case CAIF_CTRLCMD_INIT_FAIL_RSP:
75227 /* Connect request failed */
75228 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
75229 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
75230 cf_sk->sk.sk_err = ECONNREFUSED;
75231 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
75232 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75233 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
75234
75235 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
75236 /* Modem has closed this connection, or device is down. */
75237 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
75238 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
75239 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75240 cf_sk->sk.sk_err = ECONNRESET;
75241 set_rx_flow_on(cf_sk);
75242 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
75243 return;
75244
75245 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
75246 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
75247 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
75248 set_rx_flow_on(cf_sk);
75249 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
75250 }
75251 @@ -856,7 +857,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
75252 /*ifindex = id of the interface.*/
75253 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
75254
75255 - dbfs_atomic_inc(&cnt.num_connect_req);
75256 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
75257 cf_sk->layer.receive = caif_sktrecv_cb;
75258
75259 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
75260 @@ -945,7 +946,7 @@ static int caif_release(struct socket *sock)
75261 spin_unlock_bh(&sk->sk_receive_queue.lock);
75262 sock->sk = NULL;
75263
75264 - dbfs_atomic_inc(&cnt.num_disconnect);
75265 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
75266
75267 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
75268 if (cf_sk->debugfs_socket_dir != NULL)
75269 @@ -1124,7 +1125,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
75270 cf_sk->conn_req.protocol = protocol;
75271 /* Increase the number of sockets created. */
75272 dbfs_atomic_inc(&cnt.caif_nr_socks);
75273 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
75274 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
75275 #ifdef CONFIG_DEBUG_FS
75276 if (!IS_ERR(debugfsdir)) {
75277
75278 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75279 index 5cf5222..6f704ad 100644
75280 --- a/net/caif/cfctrl.c
75281 +++ b/net/caif/cfctrl.c
75282 @@ -9,6 +9,7 @@
75283 #include <linux/stddef.h>
75284 #include <linux/spinlock.h>
75285 #include <linux/slab.h>
75286 +#include <linux/sched.h>
75287 #include <net/caif/caif_layer.h>
75288 #include <net/caif/cfpkt.h>
75289 #include <net/caif/cfctrl.h>
75290 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
75291 memset(&dev_info, 0, sizeof(dev_info));
75292 dev_info.id = 0xff;
75293 cfsrvl_init(&this->serv, 0, &dev_info, false);
75294 - atomic_set(&this->req_seq_no, 1);
75295 - atomic_set(&this->rsp_seq_no, 1);
75296 + atomic_set_unchecked(&this->req_seq_no, 1);
75297 + atomic_set_unchecked(&this->rsp_seq_no, 1);
75298 this->serv.layer.receive = cfctrl_recv;
75299 sprintf(this->serv.layer.name, "ctrl");
75300 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75301 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75302 struct cfctrl_request_info *req)
75303 {
75304 spin_lock_bh(&ctrl->info_list_lock);
75305 - atomic_inc(&ctrl->req_seq_no);
75306 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
75307 + atomic_inc_unchecked(&ctrl->req_seq_no);
75308 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75309 list_add_tail(&req->list, &ctrl->list);
75310 spin_unlock_bh(&ctrl->info_list_lock);
75311 }
75312 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75313 if (p != first)
75314 pr_warn("Requests are not received in order\n");
75315
75316 - atomic_set(&ctrl->rsp_seq_no,
75317 + atomic_set_unchecked(&ctrl->rsp_seq_no,
75318 p->sequence_no);
75319 list_del(&p->list);
75320 goto out;
75321 diff --git a/net/can/gw.c b/net/can/gw.c
75322 index 3d79b12..8de85fa 100644
75323 --- a/net/can/gw.c
75324 +++ b/net/can/gw.c
75325 @@ -96,7 +96,7 @@ struct cf_mod {
75326 struct {
75327 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
75328 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
75329 - } csumfunc;
75330 + } __no_const csumfunc;
75331 };
75332
75333
75334 diff --git a/net/compat.c b/net/compat.c
75335 index 6def90e..c6992fa 100644
75336 --- a/net/compat.c
75337 +++ b/net/compat.c
75338 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75339 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75340 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75341 return -EFAULT;
75342 - kmsg->msg_name = compat_ptr(tmp1);
75343 - kmsg->msg_iov = compat_ptr(tmp2);
75344 - kmsg->msg_control = compat_ptr(tmp3);
75345 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75346 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75347 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75348 return 0;
75349 }
75350
75351 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75352
75353 if (kern_msg->msg_namelen) {
75354 if (mode == VERIFY_READ) {
75355 - int err = move_addr_to_kernel(kern_msg->msg_name,
75356 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75357 kern_msg->msg_namelen,
75358 kern_address);
75359 if (err < 0)
75360 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75361 kern_msg->msg_name = NULL;
75362
75363 tot_len = iov_from_user_compat_to_kern(kern_iov,
75364 - (struct compat_iovec __user *)kern_msg->msg_iov,
75365 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
75366 kern_msg->msg_iovlen);
75367 if (tot_len >= 0)
75368 kern_msg->msg_iov = kern_iov;
75369 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75370
75371 #define CMSG_COMPAT_FIRSTHDR(msg) \
75372 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75373 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75374 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75375 (struct compat_cmsghdr __user *)NULL)
75376
75377 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75378 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75379 (ucmlen) <= (unsigned long) \
75380 ((mhdr)->msg_controllen - \
75381 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75382 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75383
75384 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75385 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75386 {
75387 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75388 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75389 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75390 msg->msg_controllen)
75391 return NULL;
75392 return (struct compat_cmsghdr __user *)ptr;
75393 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75394 {
75395 struct compat_timeval ctv;
75396 struct compat_timespec cts[3];
75397 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75398 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75399 struct compat_cmsghdr cmhdr;
75400 int cmlen;
75401
75402 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75403
75404 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75405 {
75406 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75407 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75408 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75409 int fdnum = scm->fp->count;
75410 struct file **fp = scm->fp->fp;
75411 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75412 return -EFAULT;
75413 old_fs = get_fs();
75414 set_fs(KERNEL_DS);
75415 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75416 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75417 set_fs(old_fs);
75418
75419 return err;
75420 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75421 len = sizeof(ktime);
75422 old_fs = get_fs();
75423 set_fs(KERNEL_DS);
75424 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75425 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75426 set_fs(old_fs);
75427
75428 if (!err) {
75429 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75430 case MCAST_JOIN_GROUP:
75431 case MCAST_LEAVE_GROUP:
75432 {
75433 - struct compat_group_req __user *gr32 = (void *)optval;
75434 + struct compat_group_req __user *gr32 = (void __user *)optval;
75435 struct group_req __user *kgr =
75436 compat_alloc_user_space(sizeof(struct group_req));
75437 u32 interface;
75438 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75439 case MCAST_BLOCK_SOURCE:
75440 case MCAST_UNBLOCK_SOURCE:
75441 {
75442 - struct compat_group_source_req __user *gsr32 = (void *)optval;
75443 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75444 struct group_source_req __user *kgsr = compat_alloc_user_space(
75445 sizeof(struct group_source_req));
75446 u32 interface;
75447 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75448 }
75449 case MCAST_MSFILTER:
75450 {
75451 - struct compat_group_filter __user *gf32 = (void *)optval;
75452 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75453 struct group_filter __user *kgf;
75454 u32 interface, fmode, numsrc;
75455
75456 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75457 char __user *optval, int __user *optlen,
75458 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75459 {
75460 - struct compat_group_filter __user *gf32 = (void *)optval;
75461 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75462 struct group_filter __user *kgf;
75463 int __user *koptlen;
75464 u32 interface, fmode, numsrc;
75465 diff --git a/net/core/datagram.c b/net/core/datagram.c
75466 index 68bbf9f..5ef0d12 100644
75467 --- a/net/core/datagram.c
75468 +++ b/net/core/datagram.c
75469 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75470 }
75471
75472 kfree_skb(skb);
75473 - atomic_inc(&sk->sk_drops);
75474 + atomic_inc_unchecked(&sk->sk_drops);
75475 sk_mem_reclaim_partial(sk);
75476
75477 return err;
75478 diff --git a/net/core/dev.c b/net/core/dev.c
75479 index 7f72c9c..e29943b 100644
75480 --- a/net/core/dev.c
75481 +++ b/net/core/dev.c
75482 @@ -1138,10 +1138,14 @@ void dev_load(struct net *net, const char *name)
75483 if (no_module && capable(CAP_NET_ADMIN))
75484 no_module = request_module("netdev-%s", name);
75485 if (no_module && capable(CAP_SYS_MODULE)) {
75486 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75487 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75488 +#else
75489 if (!request_module("%s", name))
75490 pr_err("Loading kernel module for a network device "
75491 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
75492 "instead\n", name);
75493 +#endif
75494 }
75495 }
75496 EXPORT_SYMBOL(dev_load);
75497 @@ -1585,7 +1589,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75498 {
75499 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75500 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75501 - atomic_long_inc(&dev->rx_dropped);
75502 + atomic_long_inc_unchecked(&dev->rx_dropped);
75503 kfree_skb(skb);
75504 return NET_RX_DROP;
75505 }
75506 @@ -1595,7 +1599,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75507 nf_reset(skb);
75508
75509 if (unlikely(!is_skb_forwardable(dev, skb))) {
75510 - atomic_long_inc(&dev->rx_dropped);
75511 + atomic_long_inc_unchecked(&dev->rx_dropped);
75512 kfree_skb(skb);
75513 return NET_RX_DROP;
75514 }
75515 @@ -2057,7 +2061,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75516
75517 struct dev_gso_cb {
75518 void (*destructor)(struct sk_buff *skb);
75519 -};
75520 +} __no_const;
75521
75522 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75523
75524 @@ -2913,7 +2917,7 @@ enqueue:
75525
75526 local_irq_restore(flags);
75527
75528 - atomic_long_inc(&skb->dev->rx_dropped);
75529 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75530 kfree_skb(skb);
75531 return NET_RX_DROP;
75532 }
75533 @@ -2985,7 +2989,7 @@ int netif_rx_ni(struct sk_buff *skb)
75534 }
75535 EXPORT_SYMBOL(netif_rx_ni);
75536
75537 -static void net_tx_action(struct softirq_action *h)
75538 +static void net_tx_action(void)
75539 {
75540 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75541
75542 @@ -3273,7 +3277,7 @@ ncls:
75543 if (pt_prev) {
75544 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75545 } else {
75546 - atomic_long_inc(&skb->dev->rx_dropped);
75547 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75548 kfree_skb(skb);
75549 /* Jamal, now you will not able to escape explaining
75550 * me how you were going to use this. :-)
75551 @@ -3833,7 +3837,7 @@ void netif_napi_del(struct napi_struct *napi)
75552 }
75553 EXPORT_SYMBOL(netif_napi_del);
75554
75555 -static void net_rx_action(struct softirq_action *h)
75556 +static void net_rx_action(void)
75557 {
75558 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75559 unsigned long time_limit = jiffies + 2;
75560 @@ -5858,7 +5862,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75561 } else {
75562 netdev_stats_to_stats64(storage, &dev->stats);
75563 }
75564 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75565 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75566 return storage;
75567 }
75568 EXPORT_SYMBOL(dev_get_stats);
75569 diff --git a/net/core/flow.c b/net/core/flow.c
75570 index e318c7e..168b1d0 100644
75571 --- a/net/core/flow.c
75572 +++ b/net/core/flow.c
75573 @@ -61,7 +61,7 @@ struct flow_cache {
75574 struct timer_list rnd_timer;
75575 };
75576
75577 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75578 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75579 EXPORT_SYMBOL(flow_cache_genid);
75580 static struct flow_cache flow_cache_global;
75581 static struct kmem_cache *flow_cachep __read_mostly;
75582 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75583
75584 static int flow_entry_valid(struct flow_cache_entry *fle)
75585 {
75586 - if (atomic_read(&flow_cache_genid) != fle->genid)
75587 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75588 return 0;
75589 if (fle->object && !fle->object->ops->check(fle->object))
75590 return 0;
75591 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75592 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75593 fcp->hash_count++;
75594 }
75595 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75596 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75597 flo = fle->object;
75598 if (!flo)
75599 goto ret_object;
75600 @@ -280,7 +280,7 @@ nocache:
75601 }
75602 flo = resolver(net, key, family, dir, flo, ctx);
75603 if (fle) {
75604 - fle->genid = atomic_read(&flow_cache_genid);
75605 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75606 if (!IS_ERR(flo))
75607 fle->object = flo;
75608 else
75609 diff --git a/net/core/iovec.c b/net/core/iovec.c
75610 index c40f27e..7f49254 100644
75611 --- a/net/core/iovec.c
75612 +++ b/net/core/iovec.c
75613 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75614 if (m->msg_namelen) {
75615 if (mode == VERIFY_READ) {
75616 void __user *namep;
75617 - namep = (void __user __force *) m->msg_name;
75618 + namep = (void __force_user *) m->msg_name;
75619 err = move_addr_to_kernel(namep, m->msg_namelen,
75620 address);
75621 if (err < 0)
75622 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75623 }
75624
75625 size = m->msg_iovlen * sizeof(struct iovec);
75626 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75627 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75628 return -EFAULT;
75629
75630 m->msg_iov = iov;
75631 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75632 index 5c30296..ebe7b61 100644
75633 --- a/net/core/rtnetlink.c
75634 +++ b/net/core/rtnetlink.c
75635 @@ -57,7 +57,7 @@ struct rtnl_link {
75636 rtnl_doit_func doit;
75637 rtnl_dumpit_func dumpit;
75638 rtnl_calcit_func calcit;
75639 -};
75640 +} __no_const;
75641
75642 static DEFINE_MUTEX(rtnl_mutex);
75643
75644 diff --git a/net/core/scm.c b/net/core/scm.c
75645 index ff52ad0..aff1c0f 100644
75646 --- a/net/core/scm.c
75647 +++ b/net/core/scm.c
75648 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
75649 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75650 {
75651 struct cmsghdr __user *cm
75652 - = (__force struct cmsghdr __user *)msg->msg_control;
75653 + = (struct cmsghdr __force_user *)msg->msg_control;
75654 struct cmsghdr cmhdr;
75655 int cmlen = CMSG_LEN(len);
75656 int err;
75657 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75658 err = -EFAULT;
75659 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75660 goto out;
75661 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75662 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75663 goto out;
75664 cmlen = CMSG_SPACE(len);
75665 if (msg->msg_controllen < cmlen)
75666 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
75667 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75668 {
75669 struct cmsghdr __user *cm
75670 - = (__force struct cmsghdr __user*)msg->msg_control;
75671 + = (struct cmsghdr __force_user *)msg->msg_control;
75672
75673 int fdmax = 0;
75674 int fdnum = scm->fp->count;
75675 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75676 if (fdnum < fdmax)
75677 fdmax = fdnum;
75678
75679 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75680 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75681 i++, cmfptr++)
75682 {
75683 int new_fd;
75684 diff --git a/net/core/sock.c b/net/core/sock.c
75685 index 02f8dfe..86dfd4a 100644
75686 --- a/net/core/sock.c
75687 +++ b/net/core/sock.c
75688 @@ -341,7 +341,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75689 struct sk_buff_head *list = &sk->sk_receive_queue;
75690
75691 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75692 - atomic_inc(&sk->sk_drops);
75693 + atomic_inc_unchecked(&sk->sk_drops);
75694 trace_sock_rcvqueue_full(sk, skb);
75695 return -ENOMEM;
75696 }
75697 @@ -351,7 +351,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75698 return err;
75699
75700 if (!sk_rmem_schedule(sk, skb->truesize)) {
75701 - atomic_inc(&sk->sk_drops);
75702 + atomic_inc_unchecked(&sk->sk_drops);
75703 return -ENOBUFS;
75704 }
75705
75706 @@ -371,7 +371,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75707 skb_dst_force(skb);
75708
75709 spin_lock_irqsave(&list->lock, flags);
75710 - skb->dropcount = atomic_read(&sk->sk_drops);
75711 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75712 __skb_queue_tail(list, skb);
75713 spin_unlock_irqrestore(&list->lock, flags);
75714
75715 @@ -391,7 +391,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75716 skb->dev = NULL;
75717
75718 if (sk_rcvqueues_full(sk, skb)) {
75719 - atomic_inc(&sk->sk_drops);
75720 + atomic_inc_unchecked(&sk->sk_drops);
75721 goto discard_and_relse;
75722 }
75723 if (nested)
75724 @@ -409,7 +409,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75725 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75726 } else if (sk_add_backlog(sk, skb)) {
75727 bh_unlock_sock(sk);
75728 - atomic_inc(&sk->sk_drops);
75729 + atomic_inc_unchecked(&sk->sk_drops);
75730 goto discard_and_relse;
75731 }
75732
75733 @@ -974,7 +974,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75734 if (len > sizeof(peercred))
75735 len = sizeof(peercred);
75736 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75737 - if (copy_to_user(optval, &peercred, len))
75738 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75739 return -EFAULT;
75740 goto lenout;
75741 }
75742 @@ -987,7 +987,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75743 return -ENOTCONN;
75744 if (lv < len)
75745 return -EINVAL;
75746 - if (copy_to_user(optval, address, len))
75747 + if (len > sizeof(address) || copy_to_user(optval, address, len))
75748 return -EFAULT;
75749 goto lenout;
75750 }
75751 @@ -1024,7 +1024,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75752
75753 if (len > lv)
75754 len = lv;
75755 - if (copy_to_user(optval, &v, len))
75756 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
75757 return -EFAULT;
75758 lenout:
75759 if (put_user(len, optlen))
75760 @@ -2108,7 +2108,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75761 */
75762 smp_wmb();
75763 atomic_set(&sk->sk_refcnt, 1);
75764 - atomic_set(&sk->sk_drops, 0);
75765 + atomic_set_unchecked(&sk->sk_drops, 0);
75766 }
75767 EXPORT_SYMBOL(sock_init_data);
75768
75769 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75770 index b9868e1..849f809 100644
75771 --- a/net/core/sock_diag.c
75772 +++ b/net/core/sock_diag.c
75773 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75774
75775 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75776 {
75777 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75778 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75779 cookie[1] != INET_DIAG_NOCOOKIE) &&
75780 ((u32)(unsigned long)sk != cookie[0] ||
75781 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75782 return -ESTALE;
75783 else
75784 +#endif
75785 return 0;
75786 }
75787 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75788
75789 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75790 {
75791 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75792 + cookie[0] = 0;
75793 + cookie[1] = 0;
75794 +#else
75795 cookie[0] = (u32)(unsigned long)sk;
75796 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75797 +#endif
75798 }
75799 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75800
75801 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75802 index 02e75d1..9a57a7c 100644
75803 --- a/net/decnet/sysctl_net_decnet.c
75804 +++ b/net/decnet/sysctl_net_decnet.c
75805 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75806
75807 if (len > *lenp) len = *lenp;
75808
75809 - if (copy_to_user(buffer, addr, len))
75810 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75811 return -EFAULT;
75812
75813 *lenp = len;
75814 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75815
75816 if (len > *lenp) len = *lenp;
75817
75818 - if (copy_to_user(buffer, devname, len))
75819 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75820 return -EFAULT;
75821
75822 *lenp = len;
75823 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
75824 index 39a2d29..f39c0fe 100644
75825 --- a/net/econet/Kconfig
75826 +++ b/net/econet/Kconfig
75827 @@ -4,7 +4,7 @@
75828
75829 config ECONET
75830 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75831 - depends on EXPERIMENTAL && INET
75832 + depends on EXPERIMENTAL && INET && BROKEN
75833 ---help---
75834 Econet is a fairly old and slow networking protocol mainly used by
75835 Acorn computers to access file and print servers. It uses native
75836 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
75837 index 36d1440..44ff28b 100644
75838 --- a/net/ipv4/ah4.c
75839 +++ b/net/ipv4/ah4.c
75840 @@ -19,6 +19,8 @@ struct ah_skb_cb {
75841 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
75842
75843 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75844 + unsigned int size) __size_overflow(3);
75845 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75846 unsigned int size)
75847 {
75848 unsigned int len;
75849 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75850 index 92fc5f6..b790d91 100644
75851 --- a/net/ipv4/fib_frontend.c
75852 +++ b/net/ipv4/fib_frontend.c
75853 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75854 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75855 fib_sync_up(dev);
75856 #endif
75857 - atomic_inc(&net->ipv4.dev_addr_genid);
75858 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75859 rt_cache_flush(dev_net(dev), -1);
75860 break;
75861 case NETDEV_DOWN:
75862 fib_del_ifaddr(ifa, NULL);
75863 - atomic_inc(&net->ipv4.dev_addr_genid);
75864 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75865 if (ifa->ifa_dev->ifa_list == NULL) {
75866 /* Last address was deleted from this interface.
75867 * Disable IP.
75868 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75869 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75870 fib_sync_up(dev);
75871 #endif
75872 - atomic_inc(&net->ipv4.dev_addr_genid);
75873 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75874 rt_cache_flush(dev_net(dev), -1);
75875 break;
75876 case NETDEV_DOWN:
75877 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75878 index 80106d8..232e898 100644
75879 --- a/net/ipv4/fib_semantics.c
75880 +++ b/net/ipv4/fib_semantics.c
75881 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75882 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75883 nh->nh_gw,
75884 nh->nh_parent->fib_scope);
75885 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75886 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75887
75888 return nh->nh_saddr;
75889 }
75890 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75891 index 984ec65..97ac518 100644
75892 --- a/net/ipv4/inet_hashtables.c
75893 +++ b/net/ipv4/inet_hashtables.c
75894 @@ -18,12 +18,15 @@
75895 #include <linux/sched.h>
75896 #include <linux/slab.h>
75897 #include <linux/wait.h>
75898 +#include <linux/security.h>
75899
75900 #include <net/inet_connection_sock.h>
75901 #include <net/inet_hashtables.h>
75902 #include <net/secure_seq.h>
75903 #include <net/ip.h>
75904
75905 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75906 +
75907 /*
75908 * Allocate and initialize a new local port bind bucket.
75909 * The bindhash mutex for snum's hash chain must be held here.
75910 @@ -530,6 +533,8 @@ ok:
75911 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75912 spin_unlock(&head->lock);
75913
75914 + gr_update_task_in_ip_table(current, inet_sk(sk));
75915 +
75916 if (tw) {
75917 inet_twsk_deschedule(tw, death_row);
75918 while (twrefcnt) {
75919 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75920 index d4d61b6..b81aec8 100644
75921 --- a/net/ipv4/inetpeer.c
75922 +++ b/net/ipv4/inetpeer.c
75923 @@ -487,8 +487,8 @@ relookup:
75924 if (p) {
75925 p->daddr = *daddr;
75926 atomic_set(&p->refcnt, 1);
75927 - atomic_set(&p->rid, 0);
75928 - atomic_set(&p->ip_id_count,
75929 + atomic_set_unchecked(&p->rid, 0);
75930 + atomic_set_unchecked(&p->ip_id_count,
75931 (daddr->family == AF_INET) ?
75932 secure_ip_id(daddr->addr.a4) :
75933 secure_ipv6_id(daddr->addr.a6));
75934 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75935 index 1f23a57..7180dfe 100644
75936 --- a/net/ipv4/ip_fragment.c
75937 +++ b/net/ipv4/ip_fragment.c
75938 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75939 return 0;
75940
75941 start = qp->rid;
75942 - end = atomic_inc_return(&peer->rid);
75943 + end = atomic_inc_return_unchecked(&peer->rid);
75944 qp->rid = end;
75945
75946 rc = qp->q.fragments && (end - start) > max;
75947 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75948 index 8aa87c1..35c3248 100644
75949 --- a/net/ipv4/ip_sockglue.c
75950 +++ b/net/ipv4/ip_sockglue.c
75951 @@ -1112,7 +1112,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75952 len = min_t(unsigned int, len, opt->optlen);
75953 if (put_user(len, optlen))
75954 return -EFAULT;
75955 - if (copy_to_user(optval, opt->__data, len))
75956 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75957 + copy_to_user(optval, opt->__data, len))
75958 return -EFAULT;
75959 return 0;
75960 }
75961 @@ -1240,7 +1241,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75962 if (sk->sk_type != SOCK_STREAM)
75963 return -ENOPROTOOPT;
75964
75965 - msg.msg_control = optval;
75966 + msg.msg_control = (void __force_kernel *)optval;
75967 msg.msg_controllen = len;
75968 msg.msg_flags = flags;
75969
75970 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75971 index 6e412a6..6640538 100644
75972 --- a/net/ipv4/ipconfig.c
75973 +++ b/net/ipv4/ipconfig.c
75974 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75975
75976 mm_segment_t oldfs = get_fs();
75977 set_fs(get_ds());
75978 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75979 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75980 set_fs(oldfs);
75981 return res;
75982 }
75983 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75984
75985 mm_segment_t oldfs = get_fs();
75986 set_fs(get_ds());
75987 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75988 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75989 set_fs(oldfs);
75990 return res;
75991 }
75992 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75993
75994 mm_segment_t oldfs = get_fs();
75995 set_fs(get_ds());
75996 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75997 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75998 set_fs(oldfs);
75999 return res;
76000 }
76001 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
76002 index fd7a3f6..a1b1013 100644
76003 --- a/net/ipv4/netfilter/arp_tables.c
76004 +++ b/net/ipv4/netfilter/arp_tables.c
76005 @@ -757,6 +757,9 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
76006
76007 static int copy_entries_to_user(unsigned int total_size,
76008 const struct xt_table *table,
76009 + void __user *userptr) __size_overflow(1);
76010 +static int copy_entries_to_user(unsigned int total_size,
76011 + const struct xt_table *table,
76012 void __user *userptr)
76013 {
76014 unsigned int off, num;
76015 @@ -984,6 +987,11 @@ static int __do_replace(struct net *net, const char *name,
76016 unsigned int valid_hooks,
76017 struct xt_table_info *newinfo,
76018 unsigned int num_counters,
76019 + void __user *counters_ptr) __size_overflow(5);
76020 +static int __do_replace(struct net *net, const char *name,
76021 + unsigned int valid_hooks,
76022 + struct xt_table_info *newinfo,
76023 + unsigned int num_counters,
76024 void __user *counters_ptr)
76025 {
76026 int ret;
76027 @@ -1104,6 +1112,8 @@ static int do_replace(struct net *net, const void __user *user,
76028 }
76029
76030 static int do_add_counters(struct net *net, const void __user *user,
76031 + unsigned int len, int compat) __size_overflow(3);
76032 +static int do_add_counters(struct net *net, const void __user *user,
76033 unsigned int len, int compat)
76034 {
76035 unsigned int i, curcpu;
76036 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
76037 index 24e556e..b073356 100644
76038 --- a/net/ipv4/netfilter/ip_tables.c
76039 +++ b/net/ipv4/netfilter/ip_tables.c
76040 @@ -923,6 +923,10 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
76041 static int
76042 copy_entries_to_user(unsigned int total_size,
76043 const struct xt_table *table,
76044 + void __user *userptr) __size_overflow(1);
76045 +static int
76046 +copy_entries_to_user(unsigned int total_size,
76047 + const struct xt_table *table,
76048 void __user *userptr)
76049 {
76050 unsigned int off, num;
76051 @@ -1172,6 +1176,10 @@ get_entries(struct net *net, struct ipt_get_entries __user *uptr,
76052 static int
76053 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76054 struct xt_table_info *newinfo, unsigned int num_counters,
76055 + void __user *counters_ptr) __size_overflow(5);
76056 +static int
76057 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76058 + struct xt_table_info *newinfo, unsigned int num_counters,
76059 void __user *counters_ptr)
76060 {
76061 int ret;
76062 @@ -1293,6 +1301,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
76063
76064 static int
76065 do_add_counters(struct net *net, const void __user *user,
76066 + unsigned int len, int compat) __size_overflow(3);
76067 +static int
76068 +do_add_counters(struct net *net, const void __user *user,
76069 unsigned int len, int compat)
76070 {
76071 unsigned int i, curcpu;
76072 diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
76073 index ba5756d..8d34d74 100644
76074 --- a/net/ipv4/netfilter/ipt_ULOG.c
76075 +++ b/net/ipv4/netfilter/ipt_ULOG.c
76076 @@ -125,6 +125,7 @@ static void ulog_timer(unsigned long data)
76077 spin_unlock_bh(&ulog_lock);
76078 }
76079
76080 +static struct sk_buff *ulog_alloc_skb(unsigned int size) __size_overflow(1);
76081 static struct sk_buff *ulog_alloc_skb(unsigned int size)
76082 {
76083 struct sk_buff *skb;
76084 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
76085 index 2133c30..0e8047e 100644
76086 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
76087 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
76088 @@ -435,6 +435,10 @@ static unsigned char asn1_subid_decode(struct asn1_ctx *ctx,
76089 static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
76090 unsigned char *eoc,
76091 unsigned long **oid,
76092 + unsigned int *len) __size_overflow(2);
76093 +static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
76094 + unsigned char *eoc,
76095 + unsigned long **oid,
76096 unsigned int *len)
76097 {
76098 unsigned long subid;
76099 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76100 index b072386..abdebcf 100644
76101 --- a/net/ipv4/ping.c
76102 +++ b/net/ipv4/ping.c
76103 @@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76104 sk_rmem_alloc_get(sp),
76105 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76106 atomic_read(&sp->sk_refcnt), sp,
76107 - atomic_read(&sp->sk_drops), len);
76108 + atomic_read_unchecked(&sp->sk_drops), len);
76109 }
76110
76111 static int ping_seq_show(struct seq_file *seq, void *v)
76112 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
76113 index 3ccda5a..3c1e61d 100644
76114 --- a/net/ipv4/raw.c
76115 +++ b/net/ipv4/raw.c
76116 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
76117 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76118 {
76119 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76120 - atomic_inc(&sk->sk_drops);
76121 + atomic_inc_unchecked(&sk->sk_drops);
76122 kfree_skb(skb);
76123 return NET_RX_DROP;
76124 }
76125 @@ -742,16 +742,20 @@ static int raw_init(struct sock *sk)
76126
76127 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76128 {
76129 + struct icmp_filter filter;
76130 +
76131 if (optlen > sizeof(struct icmp_filter))
76132 optlen = sizeof(struct icmp_filter);
76133 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76134 + if (copy_from_user(&filter, optval, optlen))
76135 return -EFAULT;
76136 + raw_sk(sk)->filter = filter;
76137 return 0;
76138 }
76139
76140 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76141 {
76142 int len, ret = -EFAULT;
76143 + struct icmp_filter filter;
76144
76145 if (get_user(len, optlen))
76146 goto out;
76147 @@ -761,8 +765,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76148 if (len > sizeof(struct icmp_filter))
76149 len = sizeof(struct icmp_filter);
76150 ret = -EFAULT;
76151 - if (put_user(len, optlen) ||
76152 - copy_to_user(optval, &raw_sk(sk)->filter, len))
76153 + filter = raw_sk(sk)->filter;
76154 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76155 goto out;
76156 ret = 0;
76157 out: return ret;
76158 @@ -990,7 +994,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76159 sk_wmem_alloc_get(sp),
76160 sk_rmem_alloc_get(sp),
76161 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76162 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76163 + atomic_read(&sp->sk_refcnt),
76164 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76165 + NULL,
76166 +#else
76167 + sp,
76168 +#endif
76169 + atomic_read_unchecked(&sp->sk_drops));
76170 }
76171
76172 static int raw_seq_show(struct seq_file *seq, void *v)
76173 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76174 index 0197747..7adb0dc 100644
76175 --- a/net/ipv4/route.c
76176 +++ b/net/ipv4/route.c
76177 @@ -311,7 +311,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76178
76179 static inline int rt_genid(struct net *net)
76180 {
76181 - return atomic_read(&net->ipv4.rt_genid);
76182 + return atomic_read_unchecked(&net->ipv4.rt_genid);
76183 }
76184
76185 #ifdef CONFIG_PROC_FS
76186 @@ -935,7 +935,7 @@ static void rt_cache_invalidate(struct net *net)
76187 unsigned char shuffle;
76188
76189 get_random_bytes(&shuffle, sizeof(shuffle));
76190 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76191 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76192 inetpeer_invalidate_tree(AF_INET);
76193 }
76194
76195 @@ -3010,7 +3010,7 @@ static int rt_fill_info(struct net *net,
76196 error = rt->dst.error;
76197 if (peer) {
76198 inet_peer_refcheck(rt->peer);
76199 - id = atomic_read(&peer->ip_id_count) & 0xffff;
76200 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76201 if (peer->tcp_ts_stamp) {
76202 ts = peer->tcp_ts;
76203 tsage = get_seconds() - peer->tcp_ts_stamp;
76204 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76205 index fd54c5f..96d6407 100644
76206 --- a/net/ipv4/tcp_ipv4.c
76207 +++ b/net/ipv4/tcp_ipv4.c
76208 @@ -88,6 +88,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
76209 int sysctl_tcp_low_latency __read_mostly;
76210 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76211
76212 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76213 +extern int grsec_enable_blackhole;
76214 +#endif
76215
76216 #ifdef CONFIG_TCP_MD5SIG
76217 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
76218 @@ -1638,6 +1641,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76219 return 0;
76220
76221 reset:
76222 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76223 + if (!grsec_enable_blackhole)
76224 +#endif
76225 tcp_v4_send_reset(rsk, skb);
76226 discard:
76227 kfree_skb(skb);
76228 @@ -1700,12 +1706,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76229 TCP_SKB_CB(skb)->sacked = 0;
76230
76231 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76232 - if (!sk)
76233 + if (!sk) {
76234 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76235 + ret = 1;
76236 +#endif
76237 goto no_tcp_socket;
76238 -
76239 + }
76240 process:
76241 - if (sk->sk_state == TCP_TIME_WAIT)
76242 + if (sk->sk_state == TCP_TIME_WAIT) {
76243 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76244 + ret = 2;
76245 +#endif
76246 goto do_time_wait;
76247 + }
76248
76249 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76250 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76251 @@ -1755,6 +1768,10 @@ no_tcp_socket:
76252 bad_packet:
76253 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76254 } else {
76255 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76256 + if (!grsec_enable_blackhole || (ret == 1 &&
76257 + (skb->dev->flags & IFF_LOOPBACK)))
76258 +#endif
76259 tcp_v4_send_reset(NULL, skb);
76260 }
76261
76262 @@ -2417,7 +2434,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
76263 0, /* non standard timer */
76264 0, /* open_requests have no inode */
76265 atomic_read(&sk->sk_refcnt),
76266 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76267 + NULL,
76268 +#else
76269 req,
76270 +#endif
76271 len);
76272 }
76273
76274 @@ -2467,7 +2488,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76275 sock_i_uid(sk),
76276 icsk->icsk_probes_out,
76277 sock_i_ino(sk),
76278 - atomic_read(&sk->sk_refcnt), sk,
76279 + atomic_read(&sk->sk_refcnt),
76280 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76281 + NULL,
76282 +#else
76283 + sk,
76284 +#endif
76285 jiffies_to_clock_t(icsk->icsk_rto),
76286 jiffies_to_clock_t(icsk->icsk_ack.ato),
76287 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76288 @@ -2495,7 +2521,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
76289 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76290 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76291 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76292 - atomic_read(&tw->tw_refcnt), tw, len);
76293 + atomic_read(&tw->tw_refcnt),
76294 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76295 + NULL,
76296 +#else
76297 + tw,
76298 +#endif
76299 + len);
76300 }
76301
76302 #define TMPSZ 150
76303 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76304 index 550e755..25721b3 100644
76305 --- a/net/ipv4/tcp_minisocks.c
76306 +++ b/net/ipv4/tcp_minisocks.c
76307 @@ -27,6 +27,10 @@
76308 #include <net/inet_common.h>
76309 #include <net/xfrm.h>
76310
76311 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76312 +extern int grsec_enable_blackhole;
76313 +#endif
76314 +
76315 int sysctl_tcp_syncookies __read_mostly = 1;
76316 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76317
76318 @@ -753,6 +757,10 @@ listen_overflow:
76319
76320 embryonic_reset:
76321 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76322 +
76323 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76324 + if (!grsec_enable_blackhole)
76325 +#endif
76326 if (!(flg & TCP_FLAG_RST))
76327 req->rsk_ops->send_reset(sk, skb);
76328
76329 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76330 index 85ee7eb..53277ab 100644
76331 --- a/net/ipv4/tcp_probe.c
76332 +++ b/net/ipv4/tcp_probe.c
76333 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76334 if (cnt + width >= len)
76335 break;
76336
76337 - if (copy_to_user(buf + cnt, tbuf, width))
76338 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76339 return -EFAULT;
76340 cnt += width;
76341 }
76342 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76343 index cd2e072..1fffee2 100644
76344 --- a/net/ipv4/tcp_timer.c
76345 +++ b/net/ipv4/tcp_timer.c
76346 @@ -22,6 +22,10 @@
76347 #include <linux/gfp.h>
76348 #include <net/tcp.h>
76349
76350 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76351 +extern int grsec_lastack_retries;
76352 +#endif
76353 +
76354 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76355 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76356 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76357 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
76358 }
76359 }
76360
76361 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76362 + if ((sk->sk_state == TCP_LAST_ACK) &&
76363 + (grsec_lastack_retries > 0) &&
76364 + (grsec_lastack_retries < retry_until))
76365 + retry_until = grsec_lastack_retries;
76366 +#endif
76367 +
76368 if (retransmits_timed_out(sk, retry_until,
76369 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76370 /* Has it gone just too far? */
76371 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76372 index 5d075b5..d907d5f 100644
76373 --- a/net/ipv4/udp.c
76374 +++ b/net/ipv4/udp.c
76375 @@ -86,6 +86,7 @@
76376 #include <linux/types.h>
76377 #include <linux/fcntl.h>
76378 #include <linux/module.h>
76379 +#include <linux/security.h>
76380 #include <linux/socket.h>
76381 #include <linux/sockios.h>
76382 #include <linux/igmp.h>
76383 @@ -108,6 +109,10 @@
76384 #include <trace/events/udp.h>
76385 #include "udp_impl.h"
76386
76387 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76388 +extern int grsec_enable_blackhole;
76389 +#endif
76390 +
76391 struct udp_table udp_table __read_mostly;
76392 EXPORT_SYMBOL(udp_table);
76393
76394 @@ -566,6 +571,9 @@ found:
76395 return s;
76396 }
76397
76398 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76399 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76400 +
76401 /*
76402 * This routine is called by the ICMP module when it gets some
76403 * sort of error condition. If err < 0 then the socket should
76404 @@ -857,9 +865,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76405 dport = usin->sin_port;
76406 if (dport == 0)
76407 return -EINVAL;
76408 +
76409 + err = gr_search_udp_sendmsg(sk, usin);
76410 + if (err)
76411 + return err;
76412 } else {
76413 if (sk->sk_state != TCP_ESTABLISHED)
76414 return -EDESTADDRREQ;
76415 +
76416 + err = gr_search_udp_sendmsg(sk, NULL);
76417 + if (err)
76418 + return err;
76419 +
76420 daddr = inet->inet_daddr;
76421 dport = inet->inet_dport;
76422 /* Open fast path for connected socket.
76423 @@ -1100,7 +1117,7 @@ static unsigned int first_packet_length(struct sock *sk)
76424 udp_lib_checksum_complete(skb)) {
76425 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76426 IS_UDPLITE(sk));
76427 - atomic_inc(&sk->sk_drops);
76428 + atomic_inc_unchecked(&sk->sk_drops);
76429 __skb_unlink(skb, rcvq);
76430 __skb_queue_tail(&list_kill, skb);
76431 }
76432 @@ -1186,6 +1203,10 @@ try_again:
76433 if (!skb)
76434 goto out;
76435
76436 + err = gr_search_udp_recvmsg(sk, skb);
76437 + if (err)
76438 + goto out_free;
76439 +
76440 ulen = skb->len - sizeof(struct udphdr);
76441 copied = len;
76442 if (copied > ulen)
76443 @@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76444
76445 drop:
76446 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76447 - atomic_inc(&sk->sk_drops);
76448 + atomic_inc_unchecked(&sk->sk_drops);
76449 kfree_skb(skb);
76450 return -1;
76451 }
76452 @@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76453 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76454
76455 if (!skb1) {
76456 - atomic_inc(&sk->sk_drops);
76457 + atomic_inc_unchecked(&sk->sk_drops);
76458 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76459 IS_UDPLITE(sk));
76460 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76461 @@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76462 goto csum_error;
76463
76464 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76465 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76466 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76467 +#endif
76468 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76469
76470 /*
76471 @@ -2100,8 +2124,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76472 sk_wmem_alloc_get(sp),
76473 sk_rmem_alloc_get(sp),
76474 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76475 - atomic_read(&sp->sk_refcnt), sp,
76476 - atomic_read(&sp->sk_drops), len);
76477 + atomic_read(&sp->sk_refcnt),
76478 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76479 + NULL,
76480 +#else
76481 + sp,
76482 +#endif
76483 + atomic_read_unchecked(&sp->sk_drops), len);
76484 }
76485
76486 int udp4_seq_show(struct seq_file *seq, void *v)
76487 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76488 index 6b8ebc5..1d624f4 100644
76489 --- a/net/ipv6/addrconf.c
76490 +++ b/net/ipv6/addrconf.c
76491 @@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76492 p.iph.ihl = 5;
76493 p.iph.protocol = IPPROTO_IPV6;
76494 p.iph.ttl = 64;
76495 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76496 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76497
76498 if (ops->ndo_do_ioctl) {
76499 mm_segment_t oldfs = get_fs();
76500 diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
76501 index 2ae79db..8f101bf 100644
76502 --- a/net/ipv6/ah6.c
76503 +++ b/net/ipv6/ah6.c
76504 @@ -56,6 +56,8 @@ struct ah_skb_cb {
76505 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
76506
76507 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
76508 + unsigned int size) __size_overflow(3);
76509 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
76510 unsigned int size)
76511 {
76512 unsigned int len;
76513 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76514 index 02dd203..e03fcc9 100644
76515 --- a/net/ipv6/inet6_connection_sock.c
76516 +++ b/net/ipv6/inet6_connection_sock.c
76517 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76518 #ifdef CONFIG_XFRM
76519 {
76520 struct rt6_info *rt = (struct rt6_info *)dst;
76521 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76522 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76523 }
76524 #endif
76525 }
76526 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76527 #ifdef CONFIG_XFRM
76528 if (dst) {
76529 struct rt6_info *rt = (struct rt6_info *)dst;
76530 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76531 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76532 __sk_dst_reset(sk);
76533 dst = NULL;
76534 }
76535 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76536 index 18a2719..779f36a 100644
76537 --- a/net/ipv6/ipv6_sockglue.c
76538 +++ b/net/ipv6/ipv6_sockglue.c
76539 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76540 if (sk->sk_type != SOCK_STREAM)
76541 return -ENOPROTOOPT;
76542
76543 - msg.msg_control = optval;
76544 + msg.msg_control = (void __force_kernel *)optval;
76545 msg.msg_controllen = len;
76546 msg.msg_flags = flags;
76547
76548 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
76549 index 94874b0..108a94d 100644
76550 --- a/net/ipv6/netfilter/ip6_tables.c
76551 +++ b/net/ipv6/netfilter/ip6_tables.c
76552 @@ -945,6 +945,10 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
76553 static int
76554 copy_entries_to_user(unsigned int total_size,
76555 const struct xt_table *table,
76556 + void __user *userptr) __size_overflow(1);
76557 +static int
76558 +copy_entries_to_user(unsigned int total_size,
76559 + const struct xt_table *table,
76560 void __user *userptr)
76561 {
76562 unsigned int off, num;
76563 @@ -1194,6 +1198,10 @@ get_entries(struct net *net, struct ip6t_get_entries __user *uptr,
76564 static int
76565 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76566 struct xt_table_info *newinfo, unsigned int num_counters,
76567 + void __user *counters_ptr) __size_overflow(5);
76568 +static int
76569 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76570 + struct xt_table_info *newinfo, unsigned int num_counters,
76571 void __user *counters_ptr)
76572 {
76573 int ret;
76574 @@ -1315,6 +1323,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
76575
76576 static int
76577 do_add_counters(struct net *net, const void __user *user, unsigned int len,
76578 + int compat) __size_overflow(3);
76579 +static int
76580 +do_add_counters(struct net *net, const void __user *user, unsigned int len,
76581 int compat)
76582 {
76583 unsigned int i, curcpu;
76584 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76585 index d02f7e4..2d2a0f1 100644
76586 --- a/net/ipv6/raw.c
76587 +++ b/net/ipv6/raw.c
76588 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76589 {
76590 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76591 skb_checksum_complete(skb)) {
76592 - atomic_inc(&sk->sk_drops);
76593 + atomic_inc_unchecked(&sk->sk_drops);
76594 kfree_skb(skb);
76595 return NET_RX_DROP;
76596 }
76597 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76598 struct raw6_sock *rp = raw6_sk(sk);
76599
76600 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76601 - atomic_inc(&sk->sk_drops);
76602 + atomic_inc_unchecked(&sk->sk_drops);
76603 kfree_skb(skb);
76604 return NET_RX_DROP;
76605 }
76606 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76607
76608 if (inet->hdrincl) {
76609 if (skb_checksum_complete(skb)) {
76610 - atomic_inc(&sk->sk_drops);
76611 + atomic_inc_unchecked(&sk->sk_drops);
76612 kfree_skb(skb);
76613 return NET_RX_DROP;
76614 }
76615 @@ -602,7 +602,7 @@ out:
76616 return err;
76617 }
76618
76619 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76620 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76621 struct flowi6 *fl6, struct dst_entry **dstp,
76622 unsigned int flags)
76623 {
76624 @@ -912,12 +912,15 @@ do_confirm:
76625 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76626 char __user *optval, int optlen)
76627 {
76628 + struct icmp6_filter filter;
76629 +
76630 switch (optname) {
76631 case ICMPV6_FILTER:
76632 if (optlen > sizeof(struct icmp6_filter))
76633 optlen = sizeof(struct icmp6_filter);
76634 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76635 + if (copy_from_user(&filter, optval, optlen))
76636 return -EFAULT;
76637 + raw6_sk(sk)->filter = filter;
76638 return 0;
76639 default:
76640 return -ENOPROTOOPT;
76641 @@ -930,6 +933,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76642 char __user *optval, int __user *optlen)
76643 {
76644 int len;
76645 + struct icmp6_filter filter;
76646
76647 switch (optname) {
76648 case ICMPV6_FILTER:
76649 @@ -941,7 +945,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76650 len = sizeof(struct icmp6_filter);
76651 if (put_user(len, optlen))
76652 return -EFAULT;
76653 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76654 + filter = raw6_sk(sk)->filter;
76655 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76656 return -EFAULT;
76657 return 0;
76658 default:
76659 @@ -1248,7 +1253,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76660 0, 0L, 0,
76661 sock_i_uid(sp), 0,
76662 sock_i_ino(sp),
76663 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76664 + atomic_read(&sp->sk_refcnt),
76665 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76666 + NULL,
76667 +#else
76668 + sp,
76669 +#endif
76670 + atomic_read_unchecked(&sp->sk_drops));
76671 }
76672
76673 static int raw6_seq_show(struct seq_file *seq, void *v)
76674 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76675 index a89ca8d..12e66b0 100644
76676 --- a/net/ipv6/tcp_ipv6.c
76677 +++ b/net/ipv6/tcp_ipv6.c
76678 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76679 }
76680 #endif
76681
76682 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76683 +extern int grsec_enable_blackhole;
76684 +#endif
76685 +
76686 static void tcp_v6_hash(struct sock *sk)
76687 {
76688 if (sk->sk_state != TCP_CLOSE) {
76689 @@ -1654,6 +1658,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76690 return 0;
76691
76692 reset:
76693 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76694 + if (!grsec_enable_blackhole)
76695 +#endif
76696 tcp_v6_send_reset(sk, skb);
76697 discard:
76698 if (opt_skb)
76699 @@ -1733,12 +1740,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76700 TCP_SKB_CB(skb)->sacked = 0;
76701
76702 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76703 - if (!sk)
76704 + if (!sk) {
76705 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76706 + ret = 1;
76707 +#endif
76708 goto no_tcp_socket;
76709 + }
76710
76711 process:
76712 - if (sk->sk_state == TCP_TIME_WAIT)
76713 + if (sk->sk_state == TCP_TIME_WAIT) {
76714 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76715 + ret = 2;
76716 +#endif
76717 goto do_time_wait;
76718 + }
76719
76720 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76721 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76722 @@ -1786,6 +1801,10 @@ no_tcp_socket:
76723 bad_packet:
76724 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76725 } else {
76726 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76727 + if (!grsec_enable_blackhole || (ret == 1 &&
76728 + (skb->dev->flags & IFF_LOOPBACK)))
76729 +#endif
76730 tcp_v6_send_reset(NULL, skb);
76731 }
76732
76733 @@ -2047,7 +2066,13 @@ static void get_openreq6(struct seq_file *seq,
76734 uid,
76735 0, /* non standard timer */
76736 0, /* open_requests have no inode */
76737 - 0, req);
76738 + 0,
76739 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76740 + NULL
76741 +#else
76742 + req
76743 +#endif
76744 + );
76745 }
76746
76747 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76748 @@ -2097,7 +2122,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76749 sock_i_uid(sp),
76750 icsk->icsk_probes_out,
76751 sock_i_ino(sp),
76752 - atomic_read(&sp->sk_refcnt), sp,
76753 + atomic_read(&sp->sk_refcnt),
76754 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76755 + NULL,
76756 +#else
76757 + sp,
76758 +#endif
76759 jiffies_to_clock_t(icsk->icsk_rto),
76760 jiffies_to_clock_t(icsk->icsk_ack.ato),
76761 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76762 @@ -2132,7 +2162,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76763 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76764 tw->tw_substate, 0, 0,
76765 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76766 - atomic_read(&tw->tw_refcnt), tw);
76767 + atomic_read(&tw->tw_refcnt),
76768 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76769 + NULL
76770 +#else
76771 + tw
76772 +#endif
76773 + );
76774 }
76775
76776 static int tcp6_seq_show(struct seq_file *seq, void *v)
76777 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76778 index 4f96b5c..75543d7 100644
76779 --- a/net/ipv6/udp.c
76780 +++ b/net/ipv6/udp.c
76781 @@ -50,6 +50,10 @@
76782 #include <linux/seq_file.h>
76783 #include "udp_impl.h"
76784
76785 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76786 +extern int grsec_enable_blackhole;
76787 +#endif
76788 +
76789 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76790 {
76791 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76792 @@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
76793
76794 return 0;
76795 drop:
76796 - atomic_inc(&sk->sk_drops);
76797 + atomic_inc_unchecked(&sk->sk_drops);
76798 drop_no_sk_drops_inc:
76799 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76800 kfree_skb(skb);
76801 @@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76802 continue;
76803 }
76804 drop:
76805 - atomic_inc(&sk->sk_drops);
76806 + atomic_inc_unchecked(&sk->sk_drops);
76807 UDP6_INC_STATS_BH(sock_net(sk),
76808 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76809 UDP6_INC_STATS_BH(sock_net(sk),
76810 @@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76811 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76812 proto == IPPROTO_UDPLITE);
76813
76814 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76815 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76816 +#endif
76817 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76818
76819 kfree_skb(skb);
76820 @@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76821 if (!sock_owned_by_user(sk))
76822 udpv6_queue_rcv_skb(sk, skb);
76823 else if (sk_add_backlog(sk, skb)) {
76824 - atomic_inc(&sk->sk_drops);
76825 + atomic_inc_unchecked(&sk->sk_drops);
76826 bh_unlock_sock(sk);
76827 sock_put(sk);
76828 goto discard;
76829 @@ -1410,8 +1417,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76830 0, 0L, 0,
76831 sock_i_uid(sp), 0,
76832 sock_i_ino(sp),
76833 - atomic_read(&sp->sk_refcnt), sp,
76834 - atomic_read(&sp->sk_drops));
76835 + atomic_read(&sp->sk_refcnt),
76836 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76837 + NULL,
76838 +#else
76839 + sp,
76840 +#endif
76841 + atomic_read_unchecked(&sp->sk_drops));
76842 }
76843
76844 int udp6_seq_show(struct seq_file *seq, void *v)
76845 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76846 index 253695d..9481ce8 100644
76847 --- a/net/irda/ircomm/ircomm_tty.c
76848 +++ b/net/irda/ircomm/ircomm_tty.c
76849 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76850 add_wait_queue(&self->open_wait, &wait);
76851
76852 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76853 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76854 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76855
76856 /* As far as I can see, we protect open_count - Jean II */
76857 spin_lock_irqsave(&self->spinlock, flags);
76858 if (!tty_hung_up_p(filp)) {
76859 extra_count = 1;
76860 - self->open_count--;
76861 + local_dec(&self->open_count);
76862 }
76863 spin_unlock_irqrestore(&self->spinlock, flags);
76864 - self->blocked_open++;
76865 + local_inc(&self->blocked_open);
76866
76867 while (1) {
76868 if (tty->termios->c_cflag & CBAUD) {
76869 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76870 }
76871
76872 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76873 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76874 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76875
76876 schedule();
76877 }
76878 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76879 if (extra_count) {
76880 /* ++ is not atomic, so this should be protected - Jean II */
76881 spin_lock_irqsave(&self->spinlock, flags);
76882 - self->open_count++;
76883 + local_inc(&self->open_count);
76884 spin_unlock_irqrestore(&self->spinlock, flags);
76885 }
76886 - self->blocked_open--;
76887 + local_dec(&self->blocked_open);
76888
76889 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76890 - __FILE__,__LINE__, tty->driver->name, self->open_count);
76891 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76892
76893 if (!retval)
76894 self->flags |= ASYNC_NORMAL_ACTIVE;
76895 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76896 }
76897 /* ++ is not atomic, so this should be protected - Jean II */
76898 spin_lock_irqsave(&self->spinlock, flags);
76899 - self->open_count++;
76900 + local_inc(&self->open_count);
76901
76902 tty->driver_data = self;
76903 self->tty = tty;
76904 spin_unlock_irqrestore(&self->spinlock, flags);
76905
76906 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76907 - self->line, self->open_count);
76908 + self->line, local_read(&self->open_count));
76909
76910 /* Not really used by us, but lets do it anyway */
76911 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76912 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76913 return;
76914 }
76915
76916 - if ((tty->count == 1) && (self->open_count != 1)) {
76917 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76918 /*
76919 * Uh, oh. tty->count is 1, which means that the tty
76920 * structure will be freed. state->count should always
76921 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76922 */
76923 IRDA_DEBUG(0, "%s(), bad serial port count; "
76924 "tty->count is 1, state->count is %d\n", __func__ ,
76925 - self->open_count);
76926 - self->open_count = 1;
76927 + local_read(&self->open_count));
76928 + local_set(&self->open_count, 1);
76929 }
76930
76931 - if (--self->open_count < 0) {
76932 + if (local_dec_return(&self->open_count) < 0) {
76933 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76934 - __func__, self->line, self->open_count);
76935 - self->open_count = 0;
76936 + __func__, self->line, local_read(&self->open_count));
76937 + local_set(&self->open_count, 0);
76938 }
76939 - if (self->open_count) {
76940 + if (local_read(&self->open_count)) {
76941 spin_unlock_irqrestore(&self->spinlock, flags);
76942
76943 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76944 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76945 tty->closing = 0;
76946 self->tty = NULL;
76947
76948 - if (self->blocked_open) {
76949 + if (local_read(&self->blocked_open)) {
76950 if (self->close_delay)
76951 schedule_timeout_interruptible(self->close_delay);
76952 wake_up_interruptible(&self->open_wait);
76953 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76954 spin_lock_irqsave(&self->spinlock, flags);
76955 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76956 self->tty = NULL;
76957 - self->open_count = 0;
76958 + local_set(&self->open_count, 0);
76959 spin_unlock_irqrestore(&self->spinlock, flags);
76960
76961 wake_up_interruptible(&self->open_wait);
76962 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76963 seq_putc(m, '\n');
76964
76965 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76966 - seq_printf(m, "Open count: %d\n", self->open_count);
76967 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76968 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76969 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76970
76971 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76972 index d5c5b8f..33beff0 100644
76973 --- a/net/iucv/af_iucv.c
76974 +++ b/net/iucv/af_iucv.c
76975 @@ -764,10 +764,10 @@ static int iucv_sock_autobind(struct sock *sk)
76976
76977 write_lock_bh(&iucv_sk_list.lock);
76978
76979 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76980 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76981 while (__iucv_get_sock_by_name(name)) {
76982 sprintf(name, "%08x",
76983 - atomic_inc_return(&iucv_sk_list.autobind_name));
76984 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76985 }
76986
76987 write_unlock_bh(&iucv_sk_list.lock);
76988 diff --git a/net/key/af_key.c b/net/key/af_key.c
76989 index 11dbb22..c20f667 100644
76990 --- a/net/key/af_key.c
76991 +++ b/net/key/af_key.c
76992 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76993 static u32 get_acqseq(void)
76994 {
76995 u32 res;
76996 - static atomic_t acqseq;
76997 + static atomic_unchecked_t acqseq;
76998
76999 do {
77000 - res = atomic_inc_return(&acqseq);
77001 + res = atomic_inc_return_unchecked(&acqseq);
77002 } while (!res);
77003 return res;
77004 }
77005 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77006 index 2f0642d..e5c6fba 100644
77007 --- a/net/mac80211/ieee80211_i.h
77008 +++ b/net/mac80211/ieee80211_i.h
77009 @@ -28,6 +28,7 @@
77010 #include <net/ieee80211_radiotap.h>
77011 #include <net/cfg80211.h>
77012 #include <net/mac80211.h>
77013 +#include <asm/local.h>
77014 #include "key.h"
77015 #include "sta_info.h"
77016
77017 @@ -781,7 +782,7 @@ struct ieee80211_local {
77018 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77019 spinlock_t queue_stop_reason_lock;
77020
77021 - int open_count;
77022 + local_t open_count;
77023 int monitors, cooked_mntrs;
77024 /* number of interfaces with corresponding FIF_ flags */
77025 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77026 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77027 index 8e2137b..2974283 100644
77028 --- a/net/mac80211/iface.c
77029 +++ b/net/mac80211/iface.c
77030 @@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77031 break;
77032 }
77033
77034 - if (local->open_count == 0) {
77035 + if (local_read(&local->open_count) == 0) {
77036 res = drv_start(local);
77037 if (res)
77038 goto err_del_bss;
77039 @@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77040 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
77041
77042 if (!is_valid_ether_addr(dev->dev_addr)) {
77043 - if (!local->open_count)
77044 + if (!local_read(&local->open_count))
77045 drv_stop(local);
77046 return -EADDRNOTAVAIL;
77047 }
77048 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77049 mutex_unlock(&local->mtx);
77050
77051 if (coming_up)
77052 - local->open_count++;
77053 + local_inc(&local->open_count);
77054
77055 if (hw_reconf_flags)
77056 ieee80211_hw_config(local, hw_reconf_flags);
77057 @@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77058 err_del_interface:
77059 drv_remove_interface(local, sdata);
77060 err_stop:
77061 - if (!local->open_count)
77062 + if (!local_read(&local->open_count))
77063 drv_stop(local);
77064 err_del_bss:
77065 sdata->bss = NULL;
77066 @@ -489,7 +489,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77067 }
77068
77069 if (going_down)
77070 - local->open_count--;
77071 + local_dec(&local->open_count);
77072
77073 switch (sdata->vif.type) {
77074 case NL80211_IFTYPE_AP_VLAN:
77075 @@ -548,7 +548,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77076
77077 ieee80211_recalc_ps(local, -1);
77078
77079 - if (local->open_count == 0) {
77080 + if (local_read(&local->open_count) == 0) {
77081 if (local->ops->napi_poll)
77082 napi_disable(&local->napi);
77083 ieee80211_clear_tx_pending(local);
77084 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77085 index b142bd4..a651749 100644
77086 --- a/net/mac80211/main.c
77087 +++ b/net/mac80211/main.c
77088 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77089 local->hw.conf.power_level = power;
77090 }
77091
77092 - if (changed && local->open_count) {
77093 + if (changed && local_read(&local->open_count)) {
77094 ret = drv_config(local, changed);
77095 /*
77096 * Goal:
77097 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77098 index 596efaf..8f1911f 100644
77099 --- a/net/mac80211/pm.c
77100 +++ b/net/mac80211/pm.c
77101 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77102 struct ieee80211_sub_if_data *sdata;
77103 struct sta_info *sta;
77104
77105 - if (!local->open_count)
77106 + if (!local_read(&local->open_count))
77107 goto suspend;
77108
77109 ieee80211_scan_cancel(local);
77110 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77111 cancel_work_sync(&local->dynamic_ps_enable_work);
77112 del_timer_sync(&local->dynamic_ps_timer);
77113
77114 - local->wowlan = wowlan && local->open_count;
77115 + local->wowlan = wowlan && local_read(&local->open_count);
77116 if (local->wowlan) {
77117 int err = drv_suspend(local, wowlan);
77118 if (err < 0) {
77119 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77120 }
77121
77122 /* stop hardware - this must stop RX */
77123 - if (local->open_count)
77124 + if (local_read(&local->open_count))
77125 ieee80211_stop_device(local);
77126
77127 suspend:
77128 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
77129 index f9b8e81..bb89b46 100644
77130 --- a/net/mac80211/rate.c
77131 +++ b/net/mac80211/rate.c
77132 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
77133
77134 ASSERT_RTNL();
77135
77136 - if (local->open_count)
77137 + if (local_read(&local->open_count))
77138 return -EBUSY;
77139
77140 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77141 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
77142 index c97a065..ff61928 100644
77143 --- a/net/mac80211/rc80211_pid_debugfs.c
77144 +++ b/net/mac80211/rc80211_pid_debugfs.c
77145 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
77146
77147 spin_unlock_irqrestore(&events->lock, status);
77148
77149 - if (copy_to_user(buf, pb, p))
77150 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77151 return -EFAULT;
77152
77153 return p;
77154 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
77155 index 9919892..8c49803 100644
77156 --- a/net/mac80211/util.c
77157 +++ b/net/mac80211/util.c
77158 @@ -1143,7 +1143,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
77159 }
77160 #endif
77161 /* everything else happens only if HW was up & running */
77162 - if (!local->open_count)
77163 + if (!local_read(&local->open_count))
77164 goto wake_up;
77165
77166 /*
77167 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
77168 index f8ac4ef..b02560b 100644
77169 --- a/net/netfilter/Kconfig
77170 +++ b/net/netfilter/Kconfig
77171 @@ -806,6 +806,16 @@ config NETFILTER_XT_MATCH_ESP
77172
77173 To compile it as a module, choose M here. If unsure, say N.
77174
77175 +config NETFILTER_XT_MATCH_GRADM
77176 + tristate '"gradm" match support'
77177 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77178 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77179 + ---help---
77180 + The gradm match allows to match on grsecurity RBAC being enabled.
77181 + It is useful when iptables rules are applied early on bootup to
77182 + prevent connections to the machine (except from a trusted host)
77183 + while the RBAC system is disabled.
77184 +
77185 config NETFILTER_XT_MATCH_HASHLIMIT
77186 tristate '"hashlimit" match support'
77187 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77188 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
77189 index 40f4c3d..0d5dd6b 100644
77190 --- a/net/netfilter/Makefile
77191 +++ b/net/netfilter/Makefile
77192 @@ -83,6 +83,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77193 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77194 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
77195 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77196 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77197 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77198 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77199 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77200 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77201 index 29fa5ba..8debc79 100644
77202 --- a/net/netfilter/ipvs/ip_vs_conn.c
77203 +++ b/net/netfilter/ipvs/ip_vs_conn.c
77204 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77205 /* Increase the refcnt counter of the dest */
77206 atomic_inc(&dest->refcnt);
77207
77208 - conn_flags = atomic_read(&dest->conn_flags);
77209 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
77210 if (cp->protocol != IPPROTO_UDP)
77211 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77212 /* Bind with the destination and its corresponding transmitter */
77213 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77214 atomic_set(&cp->refcnt, 1);
77215
77216 atomic_set(&cp->n_control, 0);
77217 - atomic_set(&cp->in_pkts, 0);
77218 + atomic_set_unchecked(&cp->in_pkts, 0);
77219
77220 atomic_inc(&ipvs->conn_count);
77221 if (flags & IP_VS_CONN_F_NO_CPORT)
77222 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77223
77224 /* Don't drop the entry if its number of incoming packets is not
77225 located in [0, 8] */
77226 - i = atomic_read(&cp->in_pkts);
77227 + i = atomic_read_unchecked(&cp->in_pkts);
77228 if (i > 8 || i < 0) return 0;
77229
77230 if (!todrop_rate[i]) return 0;
77231 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77232 index 2555816..31492d9 100644
77233 --- a/net/netfilter/ipvs/ip_vs_core.c
77234 +++ b/net/netfilter/ipvs/ip_vs_core.c
77235 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77236 ret = cp->packet_xmit(skb, cp, pd->pp);
77237 /* do not touch skb anymore */
77238
77239 - atomic_inc(&cp->in_pkts);
77240 + atomic_inc_unchecked(&cp->in_pkts);
77241 ip_vs_conn_put(cp);
77242 return ret;
77243 }
77244 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77245 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77246 pkts = sysctl_sync_threshold(ipvs);
77247 else
77248 - pkts = atomic_add_return(1, &cp->in_pkts);
77249 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77250
77251 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
77252 cp->protocol == IPPROTO_SCTP) {
77253 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77254 index b3afe18..08ec940 100644
77255 --- a/net/netfilter/ipvs/ip_vs_ctl.c
77256 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
77257 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77258 ip_vs_rs_hash(ipvs, dest);
77259 write_unlock_bh(&ipvs->rs_lock);
77260 }
77261 - atomic_set(&dest->conn_flags, conn_flags);
77262 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77263
77264 /* bind the service */
77265 if (!dest->svc) {
77266 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77267 " %-7s %-6d %-10d %-10d\n",
77268 &dest->addr.in6,
77269 ntohs(dest->port),
77270 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77271 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77272 atomic_read(&dest->weight),
77273 atomic_read(&dest->activeconns),
77274 atomic_read(&dest->inactconns));
77275 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77276 "%-7s %-6d %-10d %-10d\n",
77277 ntohl(dest->addr.ip),
77278 ntohs(dest->port),
77279 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77280 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77281 atomic_read(&dest->weight),
77282 atomic_read(&dest->activeconns),
77283 atomic_read(&dest->inactconns));
77284 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77285
77286 entry.addr = dest->addr.ip;
77287 entry.port = dest->port;
77288 - entry.conn_flags = atomic_read(&dest->conn_flags);
77289 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77290 entry.weight = atomic_read(&dest->weight);
77291 entry.u_threshold = dest->u_threshold;
77292 entry.l_threshold = dest->l_threshold;
77293 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77294 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
77295
77296 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77297 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77298 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77299 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
77300 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
77301 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
77302 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77303 index 8a0d6d6..90ec197 100644
77304 --- a/net/netfilter/ipvs/ip_vs_sync.c
77305 +++ b/net/netfilter/ipvs/ip_vs_sync.c
77306 @@ -649,7 +649,7 @@ control:
77307 * i.e only increment in_pkts for Templates.
77308 */
77309 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
77310 - int pkts = atomic_add_return(1, &cp->in_pkts);
77311 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77312
77313 if (pkts % sysctl_sync_period(ipvs) != 1)
77314 return;
77315 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77316
77317 if (opt)
77318 memcpy(&cp->in_seq, opt, sizeof(*opt));
77319 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77320 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77321 cp->state = state;
77322 cp->old_state = cp->state;
77323 /*
77324 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77325 index 7fd66de..e6fb361 100644
77326 --- a/net/netfilter/ipvs/ip_vs_xmit.c
77327 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
77328 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
77329 else
77330 rc = NF_ACCEPT;
77331 /* do not touch skb anymore */
77332 - atomic_inc(&cp->in_pkts);
77333 + atomic_inc_unchecked(&cp->in_pkts);
77334 goto out;
77335 }
77336
77337 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77338 else
77339 rc = NF_ACCEPT;
77340 /* do not touch skb anymore */
77341 - atomic_inc(&cp->in_pkts);
77342 + atomic_inc_unchecked(&cp->in_pkts);
77343 goto out;
77344 }
77345
77346 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77347 index 66b2c54..c7884e3 100644
77348 --- a/net/netfilter/nfnetlink_log.c
77349 +++ b/net/netfilter/nfnetlink_log.c
77350 @@ -70,7 +70,7 @@ struct nfulnl_instance {
77351 };
77352
77353 static DEFINE_SPINLOCK(instances_lock);
77354 -static atomic_t global_seq;
77355 +static atomic_unchecked_t global_seq;
77356
77357 #define INSTANCE_BUCKETS 16
77358 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77359 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77360 /* global sequence number */
77361 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
77362 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
77363 - htonl(atomic_inc_return(&global_seq)));
77364 + htonl(atomic_inc_return_unchecked(&global_seq)));
77365
77366 if (data_len) {
77367 struct nlattr *nla;
77368 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77369 new file mode 100644
77370 index 0000000..6905327
77371 --- /dev/null
77372 +++ b/net/netfilter/xt_gradm.c
77373 @@ -0,0 +1,51 @@
77374 +/*
77375 + * gradm match for netfilter
77376 + * Copyright © Zbigniew Krzystolik, 2010
77377 + *
77378 + * This program is free software; you can redistribute it and/or modify
77379 + * it under the terms of the GNU General Public License; either version
77380 + * 2 or 3 as published by the Free Software Foundation.
77381 + */
77382 +#include <linux/module.h>
77383 +#include <linux/moduleparam.h>
77384 +#include <linux/skbuff.h>
77385 +#include <linux/netfilter/x_tables.h>
77386 +#include <linux/grsecurity.h>
77387 +#include <linux/netfilter/xt_gradm.h>
77388 +
77389 +static bool
77390 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
77391 +{
77392 + const struct xt_gradm_mtinfo *info = par->matchinfo;
77393 + bool retval = false;
77394 + if (gr_acl_is_enabled())
77395 + retval = true;
77396 + return retval ^ info->invflags;
77397 +}
77398 +
77399 +static struct xt_match gradm_mt_reg __read_mostly = {
77400 + .name = "gradm",
77401 + .revision = 0,
77402 + .family = NFPROTO_UNSPEC,
77403 + .match = gradm_mt,
77404 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
77405 + .me = THIS_MODULE,
77406 +};
77407 +
77408 +static int __init gradm_mt_init(void)
77409 +{
77410 + return xt_register_match(&gradm_mt_reg);
77411 +}
77412 +
77413 +static void __exit gradm_mt_exit(void)
77414 +{
77415 + xt_unregister_match(&gradm_mt_reg);
77416 +}
77417 +
77418 +module_init(gradm_mt_init);
77419 +module_exit(gradm_mt_exit);
77420 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77421 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77422 +MODULE_LICENSE("GPL");
77423 +MODULE_ALIAS("ipt_gradm");
77424 +MODULE_ALIAS("ip6t_gradm");
77425 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
77426 index 4fe4fb4..87a89e5 100644
77427 --- a/net/netfilter/xt_statistic.c
77428 +++ b/net/netfilter/xt_statistic.c
77429 @@ -19,7 +19,7 @@
77430 #include <linux/module.h>
77431
77432 struct xt_statistic_priv {
77433 - atomic_t count;
77434 + atomic_unchecked_t count;
77435 } ____cacheline_aligned_in_smp;
77436
77437 MODULE_LICENSE("GPL");
77438 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
77439 break;
77440 case XT_STATISTIC_MODE_NTH:
77441 do {
77442 - oval = atomic_read(&info->master->count);
77443 + oval = atomic_read_unchecked(&info->master->count);
77444 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
77445 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
77446 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
77447 if (nval == 0)
77448 ret = !ret;
77449 break;
77450 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
77451 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
77452 if (info->master == NULL)
77453 return -ENOMEM;
77454 - atomic_set(&info->master->count, info->u.nth.count);
77455 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
77456
77457 return 0;
77458 }
77459 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
77460 index 467af9c..8f415cc 100644
77461 --- a/net/netlink/af_netlink.c
77462 +++ b/net/netlink/af_netlink.c
77463 @@ -741,7 +741,7 @@ static void netlink_overrun(struct sock *sk)
77464 sk->sk_error_report(sk);
77465 }
77466 }
77467 - atomic_inc(&sk->sk_drops);
77468 + atomic_inc_unchecked(&sk->sk_drops);
77469 }
77470
77471 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77472 @@ -1997,7 +1997,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
77473 sk_wmem_alloc_get(s),
77474 nlk->cb,
77475 atomic_read(&s->sk_refcnt),
77476 - atomic_read(&s->sk_drops),
77477 + atomic_read_unchecked(&s->sk_drops),
77478 sock_i_ino(s)
77479 );
77480
77481 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
77482 index 7dab229..212156f 100644
77483 --- a/net/netrom/af_netrom.c
77484 +++ b/net/netrom/af_netrom.c
77485 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77486 struct sock *sk = sock->sk;
77487 struct nr_sock *nr = nr_sk(sk);
77488
77489 + memset(sax, 0, sizeof(*sax));
77490 lock_sock(sk);
77491 if (peer != 0) {
77492 if (sk->sk_state != TCP_ESTABLISHED) {
77493 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77494 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77495 } else {
77496 sax->fsa_ax25.sax25_family = AF_NETROM;
77497 - sax->fsa_ax25.sax25_ndigis = 0;
77498 sax->fsa_ax25.sax25_call = nr->source_addr;
77499 *uaddr_len = sizeof(struct sockaddr_ax25);
77500 }
77501 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
77502 index 2dbb32b..a1b4722 100644
77503 --- a/net/packet/af_packet.c
77504 +++ b/net/packet/af_packet.c
77505 @@ -1676,7 +1676,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77506
77507 spin_lock(&sk->sk_receive_queue.lock);
77508 po->stats.tp_packets++;
77509 - skb->dropcount = atomic_read(&sk->sk_drops);
77510 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77511 __skb_queue_tail(&sk->sk_receive_queue, skb);
77512 spin_unlock(&sk->sk_receive_queue.lock);
77513 sk->sk_data_ready(sk, skb->len);
77514 @@ -1685,7 +1685,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77515 drop_n_acct:
77516 spin_lock(&sk->sk_receive_queue.lock);
77517 po->stats.tp_drops++;
77518 - atomic_inc(&sk->sk_drops);
77519 + atomic_inc_unchecked(&sk->sk_drops);
77520 spin_unlock(&sk->sk_receive_queue.lock);
77521
77522 drop_n_restore:
77523 @@ -3271,7 +3271,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77524 case PACKET_HDRLEN:
77525 if (len > sizeof(int))
77526 len = sizeof(int);
77527 - if (copy_from_user(&val, optval, len))
77528 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77529 return -EFAULT;
77530 switch (val) {
77531 case TPACKET_V1:
77532 @@ -3321,7 +3321,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77533
77534 if (put_user(len, optlen))
77535 return -EFAULT;
77536 - if (copy_to_user(optval, data, len))
77537 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77538 return -EFAULT;
77539 return 0;
77540 }
77541 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
77542 index d65f699..05aa6ce 100644
77543 --- a/net/phonet/af_phonet.c
77544 +++ b/net/phonet/af_phonet.c
77545 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
77546 {
77547 struct phonet_protocol *pp;
77548
77549 - if (protocol >= PHONET_NPROTO)
77550 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77551 return NULL;
77552
77553 rcu_read_lock();
77554 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
77555 {
77556 int err = 0;
77557
77558 - if (protocol >= PHONET_NPROTO)
77559 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77560 return -EINVAL;
77561
77562 err = proto_register(pp->prot, 1);
77563 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
77564 index 9726fe6..fc4e3a4 100644
77565 --- a/net/phonet/pep.c
77566 +++ b/net/phonet/pep.c
77567 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77568
77569 case PNS_PEP_CTRL_REQ:
77570 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77571 - atomic_inc(&sk->sk_drops);
77572 + atomic_inc_unchecked(&sk->sk_drops);
77573 break;
77574 }
77575 __skb_pull(skb, 4);
77576 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77577 }
77578
77579 if (pn->rx_credits == 0) {
77580 - atomic_inc(&sk->sk_drops);
77581 + atomic_inc_unchecked(&sk->sk_drops);
77582 err = -ENOBUFS;
77583 break;
77584 }
77585 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77586 }
77587
77588 if (pn->rx_credits == 0) {
77589 - atomic_inc(&sk->sk_drops);
77590 + atomic_inc_unchecked(&sk->sk_drops);
77591 err = NET_RX_DROP;
77592 break;
77593 }
77594 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77595 index 4c7eff3..59c727f 100644
77596 --- a/net/phonet/socket.c
77597 +++ b/net/phonet/socket.c
77598 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
77599 pn->resource, sk->sk_state,
77600 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77601 sock_i_uid(sk), sock_i_ino(sk),
77602 - atomic_read(&sk->sk_refcnt), sk,
77603 - atomic_read(&sk->sk_drops), &len);
77604 + atomic_read(&sk->sk_refcnt),
77605 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77606 + NULL,
77607 +#else
77608 + sk,
77609 +#endif
77610 + atomic_read_unchecked(&sk->sk_drops), &len);
77611 }
77612 seq_printf(seq, "%*s\n", 127 - len, "");
77613 return 0;
77614 diff --git a/net/rds/cong.c b/net/rds/cong.c
77615 index e5b65ac..f3b6fb7 100644
77616 --- a/net/rds/cong.c
77617 +++ b/net/rds/cong.c
77618 @@ -78,7 +78,7 @@
77619 * finds that the saved generation number is smaller than the global generation
77620 * number, it wakes up the process.
77621 */
77622 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77623 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77624
77625 /*
77626 * Congestion monitoring
77627 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
77628 rdsdebug("waking map %p for %pI4\n",
77629 map, &map->m_addr);
77630 rds_stats_inc(s_cong_update_received);
77631 - atomic_inc(&rds_cong_generation);
77632 + atomic_inc_unchecked(&rds_cong_generation);
77633 if (waitqueue_active(&map->m_waitq))
77634 wake_up(&map->m_waitq);
77635 if (waitqueue_active(&rds_poll_waitq))
77636 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77637
77638 int rds_cong_updated_since(unsigned long *recent)
77639 {
77640 - unsigned long gen = atomic_read(&rds_cong_generation);
77641 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77642
77643 if (likely(*recent == gen))
77644 return 0;
77645 diff --git a/net/rds/ib.h b/net/rds/ib.h
77646 index edfaaaf..8c89879 100644
77647 --- a/net/rds/ib.h
77648 +++ b/net/rds/ib.h
77649 @@ -128,7 +128,7 @@ struct rds_ib_connection {
77650 /* sending acks */
77651 unsigned long i_ack_flags;
77652 #ifdef KERNEL_HAS_ATOMIC64
77653 - atomic64_t i_ack_next; /* next ACK to send */
77654 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77655 #else
77656 spinlock_t i_ack_lock; /* protect i_ack_next */
77657 u64 i_ack_next; /* next ACK to send */
77658 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
77659 index 51c8689..36c555f 100644
77660 --- a/net/rds/ib_cm.c
77661 +++ b/net/rds/ib_cm.c
77662 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
77663 /* Clear the ACK state */
77664 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77665 #ifdef KERNEL_HAS_ATOMIC64
77666 - atomic64_set(&ic->i_ack_next, 0);
77667 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77668 #else
77669 ic->i_ack_next = 0;
77670 #endif
77671 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
77672 index e29e0ca..fa3a6a3 100644
77673 --- a/net/rds/ib_recv.c
77674 +++ b/net/rds/ib_recv.c
77675 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77676 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77677 int ack_required)
77678 {
77679 - atomic64_set(&ic->i_ack_next, seq);
77680 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77681 if (ack_required) {
77682 smp_mb__before_clear_bit();
77683 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77684 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77685 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77686 smp_mb__after_clear_bit();
77687
77688 - return atomic64_read(&ic->i_ack_next);
77689 + return atomic64_read_unchecked(&ic->i_ack_next);
77690 }
77691 #endif
77692
77693 diff --git a/net/rds/iw.h b/net/rds/iw.h
77694 index 04ce3b1..48119a6 100644
77695 --- a/net/rds/iw.h
77696 +++ b/net/rds/iw.h
77697 @@ -134,7 +134,7 @@ struct rds_iw_connection {
77698 /* sending acks */
77699 unsigned long i_ack_flags;
77700 #ifdef KERNEL_HAS_ATOMIC64
77701 - atomic64_t i_ack_next; /* next ACK to send */
77702 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77703 #else
77704 spinlock_t i_ack_lock; /* protect i_ack_next */
77705 u64 i_ack_next; /* next ACK to send */
77706 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
77707 index 9556d28..f046d0e 100644
77708 --- a/net/rds/iw_cm.c
77709 +++ b/net/rds/iw_cm.c
77710 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
77711 /* Clear the ACK state */
77712 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77713 #ifdef KERNEL_HAS_ATOMIC64
77714 - atomic64_set(&ic->i_ack_next, 0);
77715 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77716 #else
77717 ic->i_ack_next = 0;
77718 #endif
77719 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
77720 index 5e57347..3916042 100644
77721 --- a/net/rds/iw_recv.c
77722 +++ b/net/rds/iw_recv.c
77723 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77724 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
77725 int ack_required)
77726 {
77727 - atomic64_set(&ic->i_ack_next, seq);
77728 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77729 if (ack_required) {
77730 smp_mb__before_clear_bit();
77731 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77732 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77733 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77734 smp_mb__after_clear_bit();
77735
77736 - return atomic64_read(&ic->i_ack_next);
77737 + return atomic64_read_unchecked(&ic->i_ack_next);
77738 }
77739 #endif
77740
77741 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
77742 index edac9ef..16bcb98 100644
77743 --- a/net/rds/tcp.c
77744 +++ b/net/rds/tcp.c
77745 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
77746 int val = 1;
77747
77748 set_fs(KERNEL_DS);
77749 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
77750 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
77751 sizeof(val));
77752 set_fs(oldfs);
77753 }
77754 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
77755 index 1b4fd68..2234175 100644
77756 --- a/net/rds/tcp_send.c
77757 +++ b/net/rds/tcp_send.c
77758 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
77759
77760 oldfs = get_fs();
77761 set_fs(KERNEL_DS);
77762 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
77763 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
77764 sizeof(val));
77765 set_fs(oldfs);
77766 }
77767 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
77768 index 74c064c..fdec26f 100644
77769 --- a/net/rxrpc/af_rxrpc.c
77770 +++ b/net/rxrpc/af_rxrpc.c
77771 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
77772 __be32 rxrpc_epoch;
77773
77774 /* current debugging ID */
77775 -atomic_t rxrpc_debug_id;
77776 +atomic_unchecked_t rxrpc_debug_id;
77777
77778 /* count of skbs currently in use */
77779 atomic_t rxrpc_n_skbs;
77780 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
77781 index c3126e8..21facc7 100644
77782 --- a/net/rxrpc/ar-ack.c
77783 +++ b/net/rxrpc/ar-ack.c
77784 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77785
77786 _enter("{%d,%d,%d,%d},",
77787 call->acks_hard, call->acks_unacked,
77788 - atomic_read(&call->sequence),
77789 + atomic_read_unchecked(&call->sequence),
77790 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77791
77792 stop = 0;
77793 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77794
77795 /* each Tx packet has a new serial number */
77796 sp->hdr.serial =
77797 - htonl(atomic_inc_return(&call->conn->serial));
77798 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77799
77800 hdr = (struct rxrpc_header *) txb->head;
77801 hdr->serial = sp->hdr.serial;
77802 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
77803 */
77804 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77805 {
77806 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77807 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77808 }
77809
77810 /*
77811 @@ -629,7 +629,7 @@ process_further:
77812
77813 latest = ntohl(sp->hdr.serial);
77814 hard = ntohl(ack.firstPacket);
77815 - tx = atomic_read(&call->sequence);
77816 + tx = atomic_read_unchecked(&call->sequence);
77817
77818 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77819 latest,
77820 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
77821 goto maybe_reschedule;
77822
77823 send_ACK_with_skew:
77824 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
77825 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
77826 ntohl(ack.serial));
77827 send_ACK:
77828 mtu = call->conn->trans->peer->if_mtu;
77829 @@ -1173,7 +1173,7 @@ send_ACK:
77830 ackinfo.rxMTU = htonl(5692);
77831 ackinfo.jumbo_max = htonl(4);
77832
77833 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77834 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77835 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77836 ntohl(hdr.serial),
77837 ntohs(ack.maxSkew),
77838 @@ -1191,7 +1191,7 @@ send_ACK:
77839 send_message:
77840 _debug("send message");
77841
77842 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77843 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77844 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
77845 send_message_2:
77846
77847 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
77848 index bf656c2..48f9d27 100644
77849 --- a/net/rxrpc/ar-call.c
77850 +++ b/net/rxrpc/ar-call.c
77851 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
77852 spin_lock_init(&call->lock);
77853 rwlock_init(&call->state_lock);
77854 atomic_set(&call->usage, 1);
77855 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
77856 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77857 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
77858
77859 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
77860 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
77861 index 4106ca9..a338d7a 100644
77862 --- a/net/rxrpc/ar-connection.c
77863 +++ b/net/rxrpc/ar-connection.c
77864 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
77865 rwlock_init(&conn->lock);
77866 spin_lock_init(&conn->state_lock);
77867 atomic_set(&conn->usage, 1);
77868 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
77869 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77870 conn->avail_calls = RXRPC_MAXCALLS;
77871 conn->size_align = 4;
77872 conn->header_size = sizeof(struct rxrpc_header);
77873 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
77874 index e7ed43a..6afa140 100644
77875 --- a/net/rxrpc/ar-connevent.c
77876 +++ b/net/rxrpc/ar-connevent.c
77877 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
77878
77879 len = iov[0].iov_len + iov[1].iov_len;
77880
77881 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77882 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77883 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
77884
77885 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77886 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
77887 index 1a2b0633..e8d1382 100644
77888 --- a/net/rxrpc/ar-input.c
77889 +++ b/net/rxrpc/ar-input.c
77890 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
77891 /* track the latest serial number on this connection for ACK packet
77892 * information */
77893 serial = ntohl(sp->hdr.serial);
77894 - hi_serial = atomic_read(&call->conn->hi_serial);
77895 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
77896 while (serial > hi_serial)
77897 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
77898 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
77899 serial);
77900
77901 /* request ACK generation for any ACK or DATA packet that requests
77902 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
77903 index 8e22bd3..f66d1c0 100644
77904 --- a/net/rxrpc/ar-internal.h
77905 +++ b/net/rxrpc/ar-internal.h
77906 @@ -272,8 +272,8 @@ struct rxrpc_connection {
77907 int error; /* error code for local abort */
77908 int debug_id; /* debug ID for printks */
77909 unsigned call_counter; /* call ID counter */
77910 - atomic_t serial; /* packet serial number counter */
77911 - atomic_t hi_serial; /* highest serial number received */
77912 + atomic_unchecked_t serial; /* packet serial number counter */
77913 + atomic_unchecked_t hi_serial; /* highest serial number received */
77914 u8 avail_calls; /* number of calls available */
77915 u8 size_align; /* data size alignment (for security) */
77916 u8 header_size; /* rxrpc + security header size */
77917 @@ -346,7 +346,7 @@ struct rxrpc_call {
77918 spinlock_t lock;
77919 rwlock_t state_lock; /* lock for state transition */
77920 atomic_t usage;
77921 - atomic_t sequence; /* Tx data packet sequence counter */
77922 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
77923 u32 abort_code; /* local/remote abort code */
77924 enum { /* current state of call */
77925 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
77926 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
77927 */
77928 extern atomic_t rxrpc_n_skbs;
77929 extern __be32 rxrpc_epoch;
77930 -extern atomic_t rxrpc_debug_id;
77931 +extern atomic_unchecked_t rxrpc_debug_id;
77932 extern struct workqueue_struct *rxrpc_workqueue;
77933
77934 /*
77935 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
77936 index 87f7135..74d3703 100644
77937 --- a/net/rxrpc/ar-local.c
77938 +++ b/net/rxrpc/ar-local.c
77939 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
77940 spin_lock_init(&local->lock);
77941 rwlock_init(&local->services_lock);
77942 atomic_set(&local->usage, 1);
77943 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
77944 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77945 memcpy(&local->srx, srx, sizeof(*srx));
77946 }
77947
77948 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
77949 index 16ae887..d24f12b 100644
77950 --- a/net/rxrpc/ar-output.c
77951 +++ b/net/rxrpc/ar-output.c
77952 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
77953 sp->hdr.cid = call->cid;
77954 sp->hdr.callNumber = call->call_id;
77955 sp->hdr.seq =
77956 - htonl(atomic_inc_return(&call->sequence));
77957 + htonl(atomic_inc_return_unchecked(&call->sequence));
77958 sp->hdr.serial =
77959 - htonl(atomic_inc_return(&conn->serial));
77960 + htonl(atomic_inc_return_unchecked(&conn->serial));
77961 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
77962 sp->hdr.userStatus = 0;
77963 sp->hdr.securityIndex = conn->security_ix;
77964 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
77965 index 2754f09..b20e38f 100644
77966 --- a/net/rxrpc/ar-peer.c
77967 +++ b/net/rxrpc/ar-peer.c
77968 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
77969 INIT_LIST_HEAD(&peer->error_targets);
77970 spin_lock_init(&peer->lock);
77971 atomic_set(&peer->usage, 1);
77972 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
77973 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77974 memcpy(&peer->srx, srx, sizeof(*srx));
77975
77976 rxrpc_assess_MTU_size(peer);
77977 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
77978 index 38047f7..9f48511 100644
77979 --- a/net/rxrpc/ar-proc.c
77980 +++ b/net/rxrpc/ar-proc.c
77981 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
77982 atomic_read(&conn->usage),
77983 rxrpc_conn_states[conn->state],
77984 key_serial(conn->key),
77985 - atomic_read(&conn->serial),
77986 - atomic_read(&conn->hi_serial));
77987 + atomic_read_unchecked(&conn->serial),
77988 + atomic_read_unchecked(&conn->hi_serial));
77989
77990 return 0;
77991 }
77992 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
77993 index 92df566..87ec1bf 100644
77994 --- a/net/rxrpc/ar-transport.c
77995 +++ b/net/rxrpc/ar-transport.c
77996 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
77997 spin_lock_init(&trans->client_lock);
77998 rwlock_init(&trans->conn_lock);
77999 atomic_set(&trans->usage, 1);
78000 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78001 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78002
78003 if (peer->srx.transport.family == AF_INET) {
78004 switch (peer->srx.transport_type) {
78005 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
78006 index 7635107..4670276 100644
78007 --- a/net/rxrpc/rxkad.c
78008 +++ b/net/rxrpc/rxkad.c
78009 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
78010
78011 len = iov[0].iov_len + iov[1].iov_len;
78012
78013 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78014 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78015 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78016
78017 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78018 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
78019
78020 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78021
78022 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78023 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78024 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78025
78026 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78027 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
78028 index 1e2eee8..ce3967e 100644
78029 --- a/net/sctp/proc.c
78030 +++ b/net/sctp/proc.c
78031 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
78032 seq_printf(seq,
78033 "%8pK %8pK %-3d %-3d %-2d %-4d "
78034 "%4d %8d %8d %7d %5lu %-5d %5d ",
78035 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78036 + assoc, sk,
78037 + sctp_sk(sk)->type, sk->sk_state,
78038 assoc->state, hash,
78039 assoc->assoc_id,
78040 assoc->sndbuf_used,
78041 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
78042 index d043722..6903416 100644
78043 --- a/net/sctp/socket.c
78044 +++ b/net/sctp/socket.c
78045 @@ -4575,7 +4575,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
78046 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
78047 if (space_left < addrlen)
78048 return -ENOMEM;
78049 - if (copy_to_user(to, &temp, addrlen))
78050 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
78051 return -EFAULT;
78052 to += addrlen;
78053 cnt++;
78054 diff --git a/net/socket.c b/net/socket.c
78055 index 0de4131..7e7ddab 100644
78056 --- a/net/socket.c
78057 +++ b/net/socket.c
78058 @@ -88,6 +88,7 @@
78059 #include <linux/nsproxy.h>
78060 #include <linux/magic.h>
78061 #include <linux/slab.h>
78062 +#include <linux/in.h>
78063
78064 #include <asm/uaccess.h>
78065 #include <asm/unistd.h>
78066 @@ -105,6 +106,8 @@
78067 #include <linux/sockios.h>
78068 #include <linux/atalk.h>
78069
78070 +#include <linux/grsock.h>
78071 +
78072 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
78073 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
78074 unsigned long nr_segs, loff_t pos);
78075 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
78076 &sockfs_dentry_operations, SOCKFS_MAGIC);
78077 }
78078
78079 -static struct vfsmount *sock_mnt __read_mostly;
78080 +struct vfsmount *sock_mnt __read_mostly;
78081
78082 static struct file_system_type sock_fs_type = {
78083 .name = "sockfs",
78084 @@ -1207,6 +1210,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
78085 return -EAFNOSUPPORT;
78086 if (type < 0 || type >= SOCK_MAX)
78087 return -EINVAL;
78088 + if (protocol < 0)
78089 + return -EINVAL;
78090
78091 /* Compatibility.
78092
78093 @@ -1339,6 +1344,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
78094 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
78095 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
78096
78097 + if(!gr_search_socket(family, type, protocol)) {
78098 + retval = -EACCES;
78099 + goto out;
78100 + }
78101 +
78102 + if (gr_handle_sock_all(family, type, protocol)) {
78103 + retval = -EACCES;
78104 + goto out;
78105 + }
78106 +
78107 retval = sock_create(family, type, protocol, &sock);
78108 if (retval < 0)
78109 goto out;
78110 @@ -1451,6 +1466,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78111 if (sock) {
78112 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
78113 if (err >= 0) {
78114 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
78115 + err = -EACCES;
78116 + goto error;
78117 + }
78118 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
78119 + if (err)
78120 + goto error;
78121 +
78122 err = security_socket_bind(sock,
78123 (struct sockaddr *)&address,
78124 addrlen);
78125 @@ -1459,6 +1482,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78126 (struct sockaddr *)
78127 &address, addrlen);
78128 }
78129 +error:
78130 fput_light(sock->file, fput_needed);
78131 }
78132 return err;
78133 @@ -1482,10 +1506,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
78134 if ((unsigned)backlog > somaxconn)
78135 backlog = somaxconn;
78136
78137 + if (gr_handle_sock_server_other(sock->sk)) {
78138 + err = -EPERM;
78139 + goto error;
78140 + }
78141 +
78142 + err = gr_search_listen(sock);
78143 + if (err)
78144 + goto error;
78145 +
78146 err = security_socket_listen(sock, backlog);
78147 if (!err)
78148 err = sock->ops->listen(sock, backlog);
78149
78150 +error:
78151 fput_light(sock->file, fput_needed);
78152 }
78153 return err;
78154 @@ -1529,6 +1563,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78155 newsock->type = sock->type;
78156 newsock->ops = sock->ops;
78157
78158 + if (gr_handle_sock_server_other(sock->sk)) {
78159 + err = -EPERM;
78160 + sock_release(newsock);
78161 + goto out_put;
78162 + }
78163 +
78164 + err = gr_search_accept(sock);
78165 + if (err) {
78166 + sock_release(newsock);
78167 + goto out_put;
78168 + }
78169 +
78170 /*
78171 * We don't need try_module_get here, as the listening socket (sock)
78172 * has the protocol module (sock->ops->owner) held.
78173 @@ -1567,6 +1613,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78174 fd_install(newfd, newfile);
78175 err = newfd;
78176
78177 + gr_attach_curr_ip(newsock->sk);
78178 +
78179 out_put:
78180 fput_light(sock->file, fput_needed);
78181 out:
78182 @@ -1599,6 +1647,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78183 int, addrlen)
78184 {
78185 struct socket *sock;
78186 + struct sockaddr *sck;
78187 struct sockaddr_storage address;
78188 int err, fput_needed;
78189
78190 @@ -1609,6 +1658,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78191 if (err < 0)
78192 goto out_put;
78193
78194 + sck = (struct sockaddr *)&address;
78195 +
78196 + if (gr_handle_sock_client(sck)) {
78197 + err = -EACCES;
78198 + goto out_put;
78199 + }
78200 +
78201 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78202 + if (err)
78203 + goto out_put;
78204 +
78205 err =
78206 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78207 if (err)
78208 @@ -1970,7 +2030,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
78209 * checking falls down on this.
78210 */
78211 if (copy_from_user(ctl_buf,
78212 - (void __user __force *)msg_sys->msg_control,
78213 + (void __force_user *)msg_sys->msg_control,
78214 ctl_len))
78215 goto out_freectl;
78216 msg_sys->msg_control = ctl_buf;
78217 @@ -2140,7 +2200,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
78218 * kernel msghdr to use the kernel address space)
78219 */
78220
78221 - uaddr = (__force void __user *)msg_sys->msg_name;
78222 + uaddr = (void __force_user *)msg_sys->msg_name;
78223 uaddr_len = COMPAT_NAMELEN(msg);
78224 if (MSG_CMSG_COMPAT & flags) {
78225 err = verify_compat_iovec(msg_sys, iov,
78226 @@ -2768,7 +2828,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78227 }
78228
78229 ifr = compat_alloc_user_space(buf_size);
78230 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
78231 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
78232
78233 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
78234 return -EFAULT;
78235 @@ -2792,12 +2852,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78236 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
78237
78238 if (copy_in_user(rxnfc, compat_rxnfc,
78239 - (void *)(&rxnfc->fs.m_ext + 1) -
78240 - (void *)rxnfc) ||
78241 + (void __user *)(&rxnfc->fs.m_ext + 1) -
78242 + (void __user *)rxnfc) ||
78243 copy_in_user(&rxnfc->fs.ring_cookie,
78244 &compat_rxnfc->fs.ring_cookie,
78245 - (void *)(&rxnfc->fs.location + 1) -
78246 - (void *)&rxnfc->fs.ring_cookie) ||
78247 + (void __user *)(&rxnfc->fs.location + 1) -
78248 + (void __user *)&rxnfc->fs.ring_cookie) ||
78249 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
78250 sizeof(rxnfc->rule_cnt)))
78251 return -EFAULT;
78252 @@ -2809,12 +2869,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78253
78254 if (convert_out) {
78255 if (copy_in_user(compat_rxnfc, rxnfc,
78256 - (const void *)(&rxnfc->fs.m_ext + 1) -
78257 - (const void *)rxnfc) ||
78258 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
78259 + (const void __user *)rxnfc) ||
78260 copy_in_user(&compat_rxnfc->fs.ring_cookie,
78261 &rxnfc->fs.ring_cookie,
78262 - (const void *)(&rxnfc->fs.location + 1) -
78263 - (const void *)&rxnfc->fs.ring_cookie) ||
78264 + (const void __user *)(&rxnfc->fs.location + 1) -
78265 + (const void __user *)&rxnfc->fs.ring_cookie) ||
78266 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
78267 sizeof(rxnfc->rule_cnt)))
78268 return -EFAULT;
78269 @@ -2884,7 +2944,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
78270 old_fs = get_fs();
78271 set_fs(KERNEL_DS);
78272 err = dev_ioctl(net, cmd,
78273 - (struct ifreq __user __force *) &kifr);
78274 + (struct ifreq __force_user *) &kifr);
78275 set_fs(old_fs);
78276
78277 return err;
78278 @@ -2993,7 +3053,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
78279
78280 old_fs = get_fs();
78281 set_fs(KERNEL_DS);
78282 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
78283 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
78284 set_fs(old_fs);
78285
78286 if (cmd == SIOCGIFMAP && !err) {
78287 @@ -3098,7 +3158,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
78288 ret |= __get_user(rtdev, &(ur4->rt_dev));
78289 if (rtdev) {
78290 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
78291 - r4.rt_dev = (char __user __force *)devname;
78292 + r4.rt_dev = (char __force_user *)devname;
78293 devname[15] = 0;
78294 } else
78295 r4.rt_dev = NULL;
78296 @@ -3324,8 +3384,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
78297 int __user *uoptlen;
78298 int err;
78299
78300 - uoptval = (char __user __force *) optval;
78301 - uoptlen = (int __user __force *) optlen;
78302 + uoptval = (char __force_user *) optval;
78303 + uoptlen = (int __force_user *) optlen;
78304
78305 set_fs(KERNEL_DS);
78306 if (level == SOL_SOCKET)
78307 @@ -3345,7 +3405,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
78308 char __user *uoptval;
78309 int err;
78310
78311 - uoptval = (char __user __force *) optval;
78312 + uoptval = (char __force_user *) optval;
78313
78314 set_fs(KERNEL_DS);
78315 if (level == SOL_SOCKET)
78316 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
78317 index 8efd96c..b492ab2 100644
78318 --- a/net/sunrpc/sched.c
78319 +++ b/net/sunrpc/sched.c
78320 @@ -239,9 +239,9 @@ static int rpc_wait_bit_killable(void *word)
78321 #ifdef RPC_DEBUG
78322 static void rpc_task_set_debuginfo(struct rpc_task *task)
78323 {
78324 - static atomic_t rpc_pid;
78325 + static atomic_unchecked_t rpc_pid;
78326
78327 - task->tk_pid = atomic_inc_return(&rpc_pid);
78328 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
78329 }
78330 #else
78331 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
78332 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
78333 index 4645709..d41d668 100644
78334 --- a/net/sunrpc/svcsock.c
78335 +++ b/net/sunrpc/svcsock.c
78336 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
78337 int buflen, unsigned int base)
78338 {
78339 size_t save_iovlen;
78340 - void __user *save_iovbase;
78341 + void *save_iovbase;
78342 unsigned int i;
78343 int ret;
78344
78345 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
78346 index 09af4fa..77110a9 100644
78347 --- a/net/sunrpc/xprtrdma/svc_rdma.c
78348 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
78349 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
78350 static unsigned int min_max_inline = 4096;
78351 static unsigned int max_max_inline = 65536;
78352
78353 -atomic_t rdma_stat_recv;
78354 -atomic_t rdma_stat_read;
78355 -atomic_t rdma_stat_write;
78356 -atomic_t rdma_stat_sq_starve;
78357 -atomic_t rdma_stat_rq_starve;
78358 -atomic_t rdma_stat_rq_poll;
78359 -atomic_t rdma_stat_rq_prod;
78360 -atomic_t rdma_stat_sq_poll;
78361 -atomic_t rdma_stat_sq_prod;
78362 +atomic_unchecked_t rdma_stat_recv;
78363 +atomic_unchecked_t rdma_stat_read;
78364 +atomic_unchecked_t rdma_stat_write;
78365 +atomic_unchecked_t rdma_stat_sq_starve;
78366 +atomic_unchecked_t rdma_stat_rq_starve;
78367 +atomic_unchecked_t rdma_stat_rq_poll;
78368 +atomic_unchecked_t rdma_stat_rq_prod;
78369 +atomic_unchecked_t rdma_stat_sq_poll;
78370 +atomic_unchecked_t rdma_stat_sq_prod;
78371
78372 /* Temporary NFS request map and context caches */
78373 struct kmem_cache *svc_rdma_map_cachep;
78374 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
78375 len -= *ppos;
78376 if (len > *lenp)
78377 len = *lenp;
78378 - if (len && copy_to_user(buffer, str_buf, len))
78379 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78380 return -EFAULT;
78381 *lenp = len;
78382 *ppos += len;
78383 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
78384 {
78385 .procname = "rdma_stat_read",
78386 .data = &rdma_stat_read,
78387 - .maxlen = sizeof(atomic_t),
78388 + .maxlen = sizeof(atomic_unchecked_t),
78389 .mode = 0644,
78390 .proc_handler = read_reset_stat,
78391 },
78392 {
78393 .procname = "rdma_stat_recv",
78394 .data = &rdma_stat_recv,
78395 - .maxlen = sizeof(atomic_t),
78396 + .maxlen = sizeof(atomic_unchecked_t),
78397 .mode = 0644,
78398 .proc_handler = read_reset_stat,
78399 },
78400 {
78401 .procname = "rdma_stat_write",
78402 .data = &rdma_stat_write,
78403 - .maxlen = sizeof(atomic_t),
78404 + .maxlen = sizeof(atomic_unchecked_t),
78405 .mode = 0644,
78406 .proc_handler = read_reset_stat,
78407 },
78408 {
78409 .procname = "rdma_stat_sq_starve",
78410 .data = &rdma_stat_sq_starve,
78411 - .maxlen = sizeof(atomic_t),
78412 + .maxlen = sizeof(atomic_unchecked_t),
78413 .mode = 0644,
78414 .proc_handler = read_reset_stat,
78415 },
78416 {
78417 .procname = "rdma_stat_rq_starve",
78418 .data = &rdma_stat_rq_starve,
78419 - .maxlen = sizeof(atomic_t),
78420 + .maxlen = sizeof(atomic_unchecked_t),
78421 .mode = 0644,
78422 .proc_handler = read_reset_stat,
78423 },
78424 {
78425 .procname = "rdma_stat_rq_poll",
78426 .data = &rdma_stat_rq_poll,
78427 - .maxlen = sizeof(atomic_t),
78428 + .maxlen = sizeof(atomic_unchecked_t),
78429 .mode = 0644,
78430 .proc_handler = read_reset_stat,
78431 },
78432 {
78433 .procname = "rdma_stat_rq_prod",
78434 .data = &rdma_stat_rq_prod,
78435 - .maxlen = sizeof(atomic_t),
78436 + .maxlen = sizeof(atomic_unchecked_t),
78437 .mode = 0644,
78438 .proc_handler = read_reset_stat,
78439 },
78440 {
78441 .procname = "rdma_stat_sq_poll",
78442 .data = &rdma_stat_sq_poll,
78443 - .maxlen = sizeof(atomic_t),
78444 + .maxlen = sizeof(atomic_unchecked_t),
78445 .mode = 0644,
78446 .proc_handler = read_reset_stat,
78447 },
78448 {
78449 .procname = "rdma_stat_sq_prod",
78450 .data = &rdma_stat_sq_prod,
78451 - .maxlen = sizeof(atomic_t),
78452 + .maxlen = sizeof(atomic_unchecked_t),
78453 .mode = 0644,
78454 .proc_handler = read_reset_stat,
78455 },
78456 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78457 index df67211..c354b13 100644
78458 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78459 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78460 @@ -499,7 +499,7 @@ next_sge:
78461 svc_rdma_put_context(ctxt, 0);
78462 goto out;
78463 }
78464 - atomic_inc(&rdma_stat_read);
78465 + atomic_inc_unchecked(&rdma_stat_read);
78466
78467 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78468 chl_map->ch[ch_no].count -= read_wr.num_sge;
78469 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78470 dto_q);
78471 list_del_init(&ctxt->dto_q);
78472 } else {
78473 - atomic_inc(&rdma_stat_rq_starve);
78474 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78475 clear_bit(XPT_DATA, &xprt->xpt_flags);
78476 ctxt = NULL;
78477 }
78478 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78479 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78480 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78481 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78482 - atomic_inc(&rdma_stat_recv);
78483 + atomic_inc_unchecked(&rdma_stat_recv);
78484
78485 /* Build up the XDR from the receive buffers. */
78486 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78487 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78488 index 249a835..fb2794b 100644
78489 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78490 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78491 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
78492 write_wr.wr.rdma.remote_addr = to;
78493
78494 /* Post It */
78495 - atomic_inc(&rdma_stat_write);
78496 + atomic_inc_unchecked(&rdma_stat_write);
78497 if (svc_rdma_send(xprt, &write_wr))
78498 goto err;
78499 return 0;
78500 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78501 index 894cb42..cf5bafb 100644
78502 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
78503 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78504 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78505 return;
78506
78507 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78508 - atomic_inc(&rdma_stat_rq_poll);
78509 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78510
78511 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78512 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78513 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78514 }
78515
78516 if (ctxt)
78517 - atomic_inc(&rdma_stat_rq_prod);
78518 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78519
78520 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78521 /*
78522 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78523 return;
78524
78525 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78526 - atomic_inc(&rdma_stat_sq_poll);
78527 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78528 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78529 if (wc.status != IB_WC_SUCCESS)
78530 /* Close the transport */
78531 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78532 }
78533
78534 if (ctxt)
78535 - atomic_inc(&rdma_stat_sq_prod);
78536 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78537 }
78538
78539 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78540 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
78541 spin_lock_bh(&xprt->sc_lock);
78542 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78543 spin_unlock_bh(&xprt->sc_lock);
78544 - atomic_inc(&rdma_stat_sq_starve);
78545 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78546
78547 /* See if we can opportunistically reap SQ WR to make room */
78548 sq_cq_reap(xprt);
78549 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
78550 index e758139..d29ea47 100644
78551 --- a/net/sysctl_net.c
78552 +++ b/net/sysctl_net.c
78553 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
78554 struct ctl_table *table)
78555 {
78556 /* Allow network administrator to have same access as root. */
78557 - if (capable(CAP_NET_ADMIN)) {
78558 + if (capable_nolog(CAP_NET_ADMIN)) {
78559 int mode = (table->mode >> 6) & 7;
78560 return (mode << 6) | (mode << 3) | mode;
78561 }
78562 diff --git a/net/tipc/link.c b/net/tipc/link.c
78563 index ac1832a..533ed97 100644
78564 --- a/net/tipc/link.c
78565 +++ b/net/tipc/link.c
78566 @@ -1205,7 +1205,7 @@ static int link_send_sections_long(struct tipc_port *sender,
78567 struct tipc_msg fragm_hdr;
78568 struct sk_buff *buf, *buf_chain, *prev;
78569 u32 fragm_crs, fragm_rest, hsz, sect_rest;
78570 - const unchar *sect_crs;
78571 + const unchar __user *sect_crs;
78572 int curr_sect;
78573 u32 fragm_no;
78574
78575 @@ -1249,7 +1249,7 @@ again:
78576
78577 if (!sect_rest) {
78578 sect_rest = msg_sect[++curr_sect].iov_len;
78579 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78580 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
78581 }
78582
78583 if (sect_rest < fragm_rest)
78584 @@ -1268,7 +1268,7 @@ error:
78585 }
78586 } else
78587 skb_copy_to_linear_data_offset(buf, fragm_crs,
78588 - sect_crs, sz);
78589 + (const void __force_kernel *)sect_crs, sz);
78590 sect_crs += sz;
78591 sect_rest -= sz;
78592 fragm_crs += sz;
78593 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
78594 index 3e4d3e2..27b55dc 100644
78595 --- a/net/tipc/msg.c
78596 +++ b/net/tipc/msg.c
78597 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
78598 msg_sect[cnt].iov_len);
78599 else
78600 skb_copy_to_linear_data_offset(*buf, pos,
78601 - msg_sect[cnt].iov_base,
78602 + (const void __force_kernel *)msg_sect[cnt].iov_base,
78603 msg_sect[cnt].iov_len);
78604 pos += msg_sect[cnt].iov_len;
78605 }
78606 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
78607 index 8c49566..14510cb 100644
78608 --- a/net/tipc/subscr.c
78609 +++ b/net/tipc/subscr.c
78610 @@ -101,7 +101,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
78611 {
78612 struct iovec msg_sect;
78613
78614 - msg_sect.iov_base = (void *)&sub->evt;
78615 + msg_sect.iov_base = (void __force_user *)&sub->evt;
78616 msg_sect.iov_len = sizeof(struct tipc_event);
78617
78618 sub->evt.event = htohl(event, sub->swap);
78619 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
78620 index 85d3bb7..79f4487 100644
78621 --- a/net/unix/af_unix.c
78622 +++ b/net/unix/af_unix.c
78623 @@ -770,6 +770,12 @@ static struct sock *unix_find_other(struct net *net,
78624 err = -ECONNREFUSED;
78625 if (!S_ISSOCK(inode->i_mode))
78626 goto put_fail;
78627 +
78628 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78629 + err = -EACCES;
78630 + goto put_fail;
78631 + }
78632 +
78633 u = unix_find_socket_byinode(inode);
78634 if (!u)
78635 goto put_fail;
78636 @@ -790,6 +796,13 @@ static struct sock *unix_find_other(struct net *net,
78637 if (u) {
78638 struct dentry *dentry;
78639 dentry = unix_sk(u)->dentry;
78640 +
78641 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
78642 + err = -EPERM;
78643 + sock_put(u);
78644 + goto fail;
78645 + }
78646 +
78647 if (dentry)
78648 touch_atime(unix_sk(u)->mnt, dentry);
78649 } else
78650 @@ -872,11 +885,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
78651 err = security_path_mknod(&path, dentry, mode, 0);
78652 if (err)
78653 goto out_mknod_drop_write;
78654 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
78655 + err = -EACCES;
78656 + goto out_mknod_drop_write;
78657 + }
78658 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
78659 out_mknod_drop_write:
78660 mnt_drop_write(path.mnt);
78661 if (err)
78662 goto out_mknod_dput;
78663 +
78664 + gr_handle_create(dentry, path.mnt);
78665 +
78666 mutex_unlock(&path.dentry->d_inode->i_mutex);
78667 dput(path.dentry);
78668 path.dentry = dentry;
78669 diff --git a/net/wireless/core.h b/net/wireless/core.h
78670 index 43ad9c8..ab5127c 100644
78671 --- a/net/wireless/core.h
78672 +++ b/net/wireless/core.h
78673 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
78674 struct mutex mtx;
78675
78676 /* rfkill support */
78677 - struct rfkill_ops rfkill_ops;
78678 + rfkill_ops_no_const rfkill_ops;
78679 struct rfkill *rfkill;
78680 struct work_struct rfkill_sync;
78681
78682 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
78683 index 0af7f54..c916d2f 100644
78684 --- a/net/wireless/wext-core.c
78685 +++ b/net/wireless/wext-core.c
78686 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78687 */
78688
78689 /* Support for very large requests */
78690 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78691 - (user_length > descr->max_tokens)) {
78692 + if (user_length > descr->max_tokens) {
78693 /* Allow userspace to GET more than max so
78694 * we can support any size GET requests.
78695 * There is still a limit : -ENOMEM.
78696 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78697 }
78698 }
78699
78700 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78701 - /*
78702 - * If this is a GET, but not NOMAX, it means that the extra
78703 - * data is not bounded by userspace, but by max_tokens. Thus
78704 - * set the length to max_tokens. This matches the extra data
78705 - * allocation.
78706 - * The driver should fill it with the number of tokens it
78707 - * provided, and it may check iwp->length rather than having
78708 - * knowledge of max_tokens. If the driver doesn't change the
78709 - * iwp->length, this ioctl just copies back max_token tokens
78710 - * filled with zeroes. Hopefully the driver isn't claiming
78711 - * them to be valid data.
78712 - */
78713 - iwp->length = descr->max_tokens;
78714 - }
78715 -
78716 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78717
78718 iwp->length += essid_compat;
78719 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
78720 index 7661576..80f7627 100644
78721 --- a/net/xfrm/xfrm_policy.c
78722 +++ b/net/xfrm/xfrm_policy.c
78723 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
78724 {
78725 policy->walk.dead = 1;
78726
78727 - atomic_inc(&policy->genid);
78728 + atomic_inc_unchecked(&policy->genid);
78729
78730 if (del_timer(&policy->timer))
78731 xfrm_pol_put(policy);
78732 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
78733 hlist_add_head(&policy->bydst, chain);
78734 xfrm_pol_hold(policy);
78735 net->xfrm.policy_count[dir]++;
78736 - atomic_inc(&flow_cache_genid);
78737 + atomic_inc_unchecked(&flow_cache_genid);
78738 if (delpol)
78739 __xfrm_policy_unlink(delpol, dir);
78740 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78741 @@ -1530,7 +1530,7 @@ free_dst:
78742 goto out;
78743 }
78744
78745 -static int inline
78746 +static inline int
78747 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78748 {
78749 if (!*target) {
78750 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
78751 return 0;
78752 }
78753
78754 -static int inline
78755 +static inline int
78756 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78757 {
78758 #ifdef CONFIG_XFRM_SUB_POLICY
78759 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78760 #endif
78761 }
78762
78763 -static int inline
78764 +static inline int
78765 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78766 {
78767 #ifdef CONFIG_XFRM_SUB_POLICY
78768 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
78769
78770 xdst->num_pols = num_pols;
78771 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78772 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78773 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78774
78775 return xdst;
78776 }
78777 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
78778 if (xdst->xfrm_genid != dst->xfrm->genid)
78779 return 0;
78780 if (xdst->num_pols > 0 &&
78781 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78782 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78783 return 0;
78784
78785 mtu = dst_mtu(dst->child);
78786 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
78787 sizeof(pol->xfrm_vec[i].saddr));
78788 pol->xfrm_vec[i].encap_family = mp->new_family;
78789 /* flush bundles */
78790 - atomic_inc(&pol->genid);
78791 + atomic_inc_unchecked(&pol->genid);
78792 }
78793 }
78794
78795 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
78796 index d2b366c..51ff91ebc 100644
78797 --- a/scripts/Makefile.build
78798 +++ b/scripts/Makefile.build
78799 @@ -109,7 +109,7 @@ endif
78800 endif
78801
78802 # Do not include host rules unless needed
78803 -ifneq ($(hostprogs-y)$(hostprogs-m),)
78804 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
78805 include scripts/Makefile.host
78806 endif
78807
78808 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
78809 index 686cb0d..9d653bf 100644
78810 --- a/scripts/Makefile.clean
78811 +++ b/scripts/Makefile.clean
78812 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
78813 __clean-files := $(extra-y) $(always) \
78814 $(targets) $(clean-files) \
78815 $(host-progs) \
78816 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
78817 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
78818 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
78819
78820 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
78821
78822 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
78823 index 1ac414f..a1c1451 100644
78824 --- a/scripts/Makefile.host
78825 +++ b/scripts/Makefile.host
78826 @@ -31,6 +31,7 @@
78827 # Note: Shared libraries consisting of C++ files are not supported
78828
78829 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
78830 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
78831
78832 # C code
78833 # Executables compiled from a single .c file
78834 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
78835 # Shared libaries (only .c supported)
78836 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
78837 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
78838 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
78839 # Remove .so files from "xxx-objs"
78840 host-cobjs := $(filter-out %.so,$(host-cobjs))
78841
78842 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
78843 index cb1f50c..cef2a7c 100644
78844 --- a/scripts/basic/fixdep.c
78845 +++ b/scripts/basic/fixdep.c
78846 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
78847 /*
78848 * Lookup a value in the configuration string.
78849 */
78850 -static int is_defined_config(const char *name, int len, unsigned int hash)
78851 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
78852 {
78853 struct item *aux;
78854
78855 @@ -211,10 +211,10 @@ static void clear_config(void)
78856 /*
78857 * Record the use of a CONFIG_* word.
78858 */
78859 -static void use_config(const char *m, int slen)
78860 +static void use_config(const char *m, unsigned int slen)
78861 {
78862 unsigned int hash = strhash(m, slen);
78863 - int c, i;
78864 + unsigned int c, i;
78865
78866 if (is_defined_config(m, slen, hash))
78867 return;
78868 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
78869
78870 static void parse_config_file(const char *map, size_t len)
78871 {
78872 - const int *end = (const int *) (map + len);
78873 + const unsigned int *end = (const unsigned int *) (map + len);
78874 /* start at +1, so that p can never be < map */
78875 - const int *m = (const int *) map + 1;
78876 + const unsigned int *m = (const unsigned int *) map + 1;
78877 const char *p, *q;
78878
78879 for (; m < end; m++) {
78880 @@ -406,7 +406,7 @@ static void print_deps(void)
78881 static void traps(void)
78882 {
78883 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
78884 - int *p = (int *)test;
78885 + unsigned int *p = (unsigned int *)test;
78886
78887 if (*p != INT_CONF) {
78888 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
78889 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
78890 new file mode 100644
78891 index 0000000..8729101
78892 --- /dev/null
78893 +++ b/scripts/gcc-plugin.sh
78894 @@ -0,0 +1,2 @@
78895 +#!/bin/sh
78896 +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"
78897 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
78898 index e047e17..ea646ec 100644
78899 --- a/scripts/mod/file2alias.c
78900 +++ b/scripts/mod/file2alias.c
78901 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
78902 unsigned long size, unsigned long id_size,
78903 void *symval)
78904 {
78905 - int i;
78906 + unsigned int i;
78907
78908 if (size % id_size || size < id_size) {
78909 if (cross_build != 0)
78910 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
78911 /* USB is special because the bcdDevice can be matched against a numeric range */
78912 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
78913 static void do_usb_entry(struct usb_device_id *id,
78914 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
78915 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
78916 unsigned char range_lo, unsigned char range_hi,
78917 unsigned char max, struct module *mod)
78918 {
78919 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
78920 {
78921 unsigned int devlo, devhi;
78922 unsigned char chi, clo, max;
78923 - int ndigits;
78924 + unsigned int ndigits;
78925
78926 id->match_flags = TO_NATIVE(id->match_flags);
78927 id->idVendor = TO_NATIVE(id->idVendor);
78928 @@ -501,7 +501,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
78929 for (i = 0; i < count; i++) {
78930 const char *id = (char *)devs[i].id;
78931 char acpi_id[sizeof(devs[0].id)];
78932 - int j;
78933 + unsigned int j;
78934
78935 buf_printf(&mod->dev_table_buf,
78936 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78937 @@ -531,7 +531,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78938
78939 for (j = 0; j < PNP_MAX_DEVICES; j++) {
78940 const char *id = (char *)card->devs[j].id;
78941 - int i2, j2;
78942 + unsigned int i2, j2;
78943 int dup = 0;
78944
78945 if (!id[0])
78946 @@ -557,7 +557,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78947 /* add an individual alias for every device entry */
78948 if (!dup) {
78949 char acpi_id[sizeof(card->devs[0].id)];
78950 - int k;
78951 + unsigned int k;
78952
78953 buf_printf(&mod->dev_table_buf,
78954 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78955 @@ -882,7 +882,7 @@ static void dmi_ascii_filter(char *d, const char *s)
78956 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
78957 char *alias)
78958 {
78959 - int i, j;
78960 + unsigned int i, j;
78961
78962 sprintf(alias, "dmi*");
78963
78964 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
78965 index c4e7d15..4241aef 100644
78966 --- a/scripts/mod/modpost.c
78967 +++ b/scripts/mod/modpost.c
78968 @@ -922,6 +922,7 @@ enum mismatch {
78969 ANY_INIT_TO_ANY_EXIT,
78970 ANY_EXIT_TO_ANY_INIT,
78971 EXPORT_TO_INIT_EXIT,
78972 + DATA_TO_TEXT
78973 };
78974
78975 struct sectioncheck {
78976 @@ -1030,6 +1031,12 @@ const struct sectioncheck sectioncheck[] = {
78977 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
78978 .mismatch = EXPORT_TO_INIT_EXIT,
78979 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
78980 +},
78981 +/* Do not reference code from writable data */
78982 +{
78983 + .fromsec = { DATA_SECTIONS, NULL },
78984 + .tosec = { TEXT_SECTIONS, NULL },
78985 + .mismatch = DATA_TO_TEXT
78986 }
78987 };
78988
78989 @@ -1152,10 +1159,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
78990 continue;
78991 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
78992 continue;
78993 - if (sym->st_value == addr)
78994 - return sym;
78995 /* Find a symbol nearby - addr are maybe negative */
78996 d = sym->st_value - addr;
78997 + if (d == 0)
78998 + return sym;
78999 if (d < 0)
79000 d = addr - sym->st_value;
79001 if (d < distance) {
79002 @@ -1434,6 +1441,14 @@ static void report_sec_mismatch(const char *modname,
79003 tosym, prl_to, prl_to, tosym);
79004 free(prl_to);
79005 break;
79006 + case DATA_TO_TEXT:
79007 +/*
79008 + fprintf(stderr,
79009 + "The variable %s references\n"
79010 + "the %s %s%s%s\n",
79011 + fromsym, to, sec2annotation(tosec), tosym, to_p);
79012 +*/
79013 + break;
79014 }
79015 fprintf(stderr, "\n");
79016 }
79017 @@ -1668,7 +1683,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
79018 static void check_sec_ref(struct module *mod, const char *modname,
79019 struct elf_info *elf)
79020 {
79021 - int i;
79022 + unsigned int i;
79023 Elf_Shdr *sechdrs = elf->sechdrs;
79024
79025 /* Walk through all sections */
79026 @@ -1766,7 +1781,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
79027 va_end(ap);
79028 }
79029
79030 -void buf_write(struct buffer *buf, const char *s, int len)
79031 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
79032 {
79033 if (buf->size - buf->pos < len) {
79034 buf->size += len + SZ;
79035 @@ -1984,7 +1999,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
79036 if (fstat(fileno(file), &st) < 0)
79037 goto close_write;
79038
79039 - if (st.st_size != b->pos)
79040 + if (st.st_size != (off_t)b->pos)
79041 goto close_write;
79042
79043 tmp = NOFAIL(malloc(b->pos));
79044 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
79045 index 51207e4..f7d603d 100644
79046 --- a/scripts/mod/modpost.h
79047 +++ b/scripts/mod/modpost.h
79048 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
79049
79050 struct buffer {
79051 char *p;
79052 - int pos;
79053 - int size;
79054 + unsigned int pos;
79055 + unsigned int size;
79056 };
79057
79058 void __attribute__((format(printf, 2, 3)))
79059 buf_printf(struct buffer *buf, const char *fmt, ...);
79060
79061 void
79062 -buf_write(struct buffer *buf, const char *s, int len);
79063 +buf_write(struct buffer *buf, const char *s, unsigned int len);
79064
79065 struct module {
79066 struct module *next;
79067 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
79068 index 9dfcd6d..099068e 100644
79069 --- a/scripts/mod/sumversion.c
79070 +++ b/scripts/mod/sumversion.c
79071 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
79072 goto out;
79073 }
79074
79075 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
79076 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
79077 warn("writing sum in %s failed: %s\n",
79078 filename, strerror(errno));
79079 goto out;
79080 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
79081 index 5c11312..72742b5 100644
79082 --- a/scripts/pnmtologo.c
79083 +++ b/scripts/pnmtologo.c
79084 @@ -237,14 +237,14 @@ static void write_header(void)
79085 fprintf(out, " * Linux logo %s\n", logoname);
79086 fputs(" */\n\n", out);
79087 fputs("#include <linux/linux_logo.h>\n\n", out);
79088 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
79089 + fprintf(out, "static unsigned char %s_data[] = {\n",
79090 logoname);
79091 }
79092
79093 static void write_footer(void)
79094 {
79095 fputs("\n};\n\n", out);
79096 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79097 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79098 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79099 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79100 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79101 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79102 fputs("\n};\n\n", out);
79103
79104 /* write logo clut */
79105 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79106 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79107 logoname);
79108 write_hex_cnt = 0;
79109 for (i = 0; i < logo_clutsize; i++) {
79110 diff --git a/scripts/tags.sh b/scripts/tags.sh
79111 index 833813a..0bc8588 100755
79112 --- a/scripts/tags.sh
79113 +++ b/scripts/tags.sh
79114 @@ -116,7 +116,7 @@ docscope()
79115
79116 dogtags()
79117 {
79118 - all_sources | gtags -f -
79119 + all_sources | gtags -i -f -
79120 }
79121
79122 exuberant()
79123 diff --git a/security/Kconfig b/security/Kconfig
79124 index 51bd5a0..c37f5e6 100644
79125 --- a/security/Kconfig
79126 +++ b/security/Kconfig
79127 @@ -4,6 +4,640 @@
79128
79129 menu "Security options"
79130
79131 +source grsecurity/Kconfig
79132 +
79133 +menu "PaX"
79134 +
79135 + config ARCH_TRACK_EXEC_LIMIT
79136 + bool
79137 +
79138 + config PAX_KERNEXEC_PLUGIN
79139 + bool
79140 +
79141 + config PAX_PER_CPU_PGD
79142 + bool
79143 +
79144 + config TASK_SIZE_MAX_SHIFT
79145 + int
79146 + depends on X86_64
79147 + default 47 if !PAX_PER_CPU_PGD
79148 + default 42 if PAX_PER_CPU_PGD
79149 +
79150 + config PAX_ENABLE_PAE
79151 + bool
79152 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79153 +
79154 +config PAX
79155 + bool "Enable various PaX features"
79156 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79157 + help
79158 + This allows you to enable various PaX features. PaX adds
79159 + intrusion prevention mechanisms to the kernel that reduce
79160 + the risks posed by exploitable memory corruption bugs.
79161 +
79162 +menu "PaX Control"
79163 + depends on PAX
79164 +
79165 +config PAX_SOFTMODE
79166 + bool 'Support soft mode'
79167 + help
79168 + Enabling this option will allow you to run PaX in soft mode, that
79169 + is, PaX features will not be enforced by default, only on executables
79170 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
79171 + support as they are the only way to mark executables for soft mode use.
79172 +
79173 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79174 + line option on boot. Furthermore you can control various PaX features
79175 + at runtime via the entries in /proc/sys/kernel/pax.
79176 +
79177 +config PAX_EI_PAX
79178 + bool 'Use legacy ELF header marking'
79179 + help
79180 + Enabling this option will allow you to control PaX features on
79181 + a per executable basis via the 'chpax' utility available at
79182 + http://pax.grsecurity.net/. The control flags will be read from
79183 + an otherwise reserved part of the ELF header. This marking has
79184 + numerous drawbacks (no support for soft-mode, toolchain does not
79185 + know about the non-standard use of the ELF header) therefore it
79186 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
79187 + support.
79188 +
79189 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79190 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
79191 + option otherwise they will not get any protection.
79192 +
79193 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
79194 + support as well, they will override the legacy EI_PAX marks.
79195 +
79196 +config PAX_PT_PAX_FLAGS
79197 + bool 'Use ELF program header marking'
79198 + help
79199 + Enabling this option will allow you to control PaX features on
79200 + a per executable basis via the 'paxctl' utility available at
79201 + http://pax.grsecurity.net/. The control flags will be read from
79202 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79203 + has the benefits of supporting both soft mode and being fully
79204 + integrated into the toolchain (the binutils patch is available
79205 + from http://pax.grsecurity.net).
79206 +
79207 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79208 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
79209 + support otherwise they will not get any protection.
79210 +
79211 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79212 + must make sure that the marks are the same if a binary has both marks.
79213 +
79214 + Note that if you enable the legacy EI_PAX marking support as well,
79215 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79216 +
79217 +config PAX_XATTR_PAX_FLAGS
79218 + bool 'Use filesystem extended attributes marking'
79219 + select CIFS_XATTR if CIFS
79220 + select EXT2_FS_XATTR if EXT2_FS
79221 + select EXT3_FS_XATTR if EXT3_FS
79222 + select EXT4_FS_XATTR if EXT4_FS
79223 + select JFFS2_FS_XATTR if JFFS2_FS
79224 + select REISERFS_FS_XATTR if REISERFS_FS
79225 + select SQUASHFS_XATTR if SQUASHFS
79226 + select TMPFS_XATTR if TMPFS
79227 + select UBIFS_FS_XATTR if UBIFS_FS
79228 + help
79229 + Enabling this option will allow you to control PaX features on
79230 + a per executable basis via the 'setfattr' utility. The control
79231 + flags will be read from the user.pax.flags extended attribute of
79232 + the file. This marking has the benefit of supporting binary-only
79233 + applications that self-check themselves (e.g., skype) and would
79234 + not tolerate chpax/paxctl changes. The main drawback is that
79235 + extended attributes are not supported by some filesystems (e.g.,
79236 + isofs, udf, vfat) so copying files through such filesystems will
79237 + lose the extended attributes and these PaX markings.
79238 +
79239 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79240 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
79241 + support otherwise they will not get any protection.
79242 +
79243 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79244 + must make sure that the marks are the same if a binary has both marks.
79245 +
79246 + Note that if you enable the legacy EI_PAX marking support as well,
79247 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
79248 +
79249 +choice
79250 + prompt 'MAC system integration'
79251 + default PAX_HAVE_ACL_FLAGS
79252 + help
79253 + Mandatory Access Control systems have the option of controlling
79254 + PaX flags on a per executable basis, choose the method supported
79255 + by your particular system.
79256 +
79257 + - "none": if your MAC system does not interact with PaX,
79258 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
79259 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
79260 +
79261 + NOTE: this option is for developers/integrators only.
79262 +
79263 + config PAX_NO_ACL_FLAGS
79264 + bool 'none'
79265 +
79266 + config PAX_HAVE_ACL_FLAGS
79267 + bool 'direct'
79268 +
79269 + config PAX_HOOK_ACL_FLAGS
79270 + bool 'hook'
79271 +endchoice
79272 +
79273 +endmenu
79274 +
79275 +menu "Non-executable pages"
79276 + depends on PAX
79277 +
79278 +config PAX_NOEXEC
79279 + bool "Enforce non-executable pages"
79280 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
79281 + help
79282 + By design some architectures do not allow for protecting memory
79283 + pages against execution or even if they do, Linux does not make
79284 + use of this feature. In practice this means that if a page is
79285 + readable (such as the stack or heap) it is also executable.
79286 +
79287 + There is a well known exploit technique that makes use of this
79288 + fact and a common programming mistake where an attacker can
79289 + introduce code of his choice somewhere in the attacked program's
79290 + memory (typically the stack or the heap) and then execute it.
79291 +
79292 + If the attacked program was running with different (typically
79293 + higher) privileges than that of the attacker, then he can elevate
79294 + his own privilege level (e.g. get a root shell, write to files for
79295 + which he does not have write access to, etc).
79296 +
79297 + Enabling this option will let you choose from various features
79298 + that prevent the injection and execution of 'foreign' code in
79299 + a program.
79300 +
79301 + This will also break programs that rely on the old behaviour and
79302 + expect that dynamically allocated memory via the malloc() family
79303 + of functions is executable (which it is not). Notable examples
79304 + are the XFree86 4.x server, the java runtime and wine.
79305 +
79306 +config PAX_PAGEEXEC
79307 + bool "Paging based non-executable pages"
79308 + 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)
79309 + select S390_SWITCH_AMODE if S390
79310 + select S390_EXEC_PROTECT if S390
79311 + select ARCH_TRACK_EXEC_LIMIT if X86_32
79312 + help
79313 + This implementation is based on the paging feature of the CPU.
79314 + On i386 without hardware non-executable bit support there is a
79315 + variable but usually low performance impact, however on Intel's
79316 + P4 core based CPUs it is very high so you should not enable this
79317 + for kernels meant to be used on such CPUs.
79318 +
79319 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
79320 + with hardware non-executable bit support there is no performance
79321 + impact, on ppc the impact is negligible.
79322 +
79323 + Note that several architectures require various emulations due to
79324 + badly designed userland ABIs, this will cause a performance impact
79325 + but will disappear as soon as userland is fixed. For example, ppc
79326 + userland MUST have been built with secure-plt by a recent toolchain.
79327 +
79328 +config PAX_SEGMEXEC
79329 + bool "Segmentation based non-executable pages"
79330 + depends on PAX_NOEXEC && X86_32
79331 + help
79332 + This implementation is based on the segmentation feature of the
79333 + CPU and has a very small performance impact, however applications
79334 + will be limited to a 1.5 GB address space instead of the normal
79335 + 3 GB.
79336 +
79337 +config PAX_EMUTRAMP
79338 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
79339 + default y if PARISC
79340 + help
79341 + There are some programs and libraries that for one reason or
79342 + another attempt to execute special small code snippets from
79343 + non-executable memory pages. Most notable examples are the
79344 + signal handler return code generated by the kernel itself and
79345 + the GCC trampolines.
79346 +
79347 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
79348 + such programs will no longer work under your kernel.
79349 +
79350 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
79351 + utilities to enable trampoline emulation for the affected programs
79352 + yet still have the protection provided by the non-executable pages.
79353 +
79354 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
79355 + your system will not even boot.
79356 +
79357 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
79358 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
79359 + for the affected files.
79360 +
79361 + NOTE: enabling this feature *may* open up a loophole in the
79362 + protection provided by non-executable pages that an attacker
79363 + could abuse. Therefore the best solution is to not have any
79364 + files on your system that would require this option. This can
79365 + be achieved by not using libc5 (which relies on the kernel
79366 + signal handler return code) and not using or rewriting programs
79367 + that make use of the nested function implementation of GCC.
79368 + Skilled users can just fix GCC itself so that it implements
79369 + nested function calls in a way that does not interfere with PaX.
79370 +
79371 +config PAX_EMUSIGRT
79372 + bool "Automatically emulate sigreturn trampolines"
79373 + depends on PAX_EMUTRAMP && PARISC
79374 + default y
79375 + help
79376 + Enabling this option will have the kernel automatically detect
79377 + and emulate signal return trampolines executing on the stack
79378 + that would otherwise lead to task termination.
79379 +
79380 + This solution is intended as a temporary one for users with
79381 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
79382 + Modula-3 runtime, etc) or executables linked to such, basically
79383 + everything that does not specify its own SA_RESTORER function in
79384 + normal executable memory like glibc 2.1+ does.
79385 +
79386 + On parisc you MUST enable this option, otherwise your system will
79387 + not even boot.
79388 +
79389 + NOTE: this feature cannot be disabled on a per executable basis
79390 + and since it *does* open up a loophole in the protection provided
79391 + by non-executable pages, the best solution is to not have any
79392 + files on your system that would require this option.
79393 +
79394 +config PAX_MPROTECT
79395 + bool "Restrict mprotect()"
79396 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
79397 + help
79398 + Enabling this option will prevent programs from
79399 + - changing the executable status of memory pages that were
79400 + not originally created as executable,
79401 + - making read-only executable pages writable again,
79402 + - creating executable pages from anonymous memory,
79403 + - making read-only-after-relocations (RELRO) data pages writable again.
79404 +
79405 + You should say Y here to complete the protection provided by
79406 + the enforcement of non-executable pages.
79407 +
79408 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79409 + this feature on a per file basis.
79410 +
79411 +config PAX_MPROTECT_COMPAT
79412 + bool "Use legacy/compat protection demoting (read help)"
79413 + depends on PAX_MPROTECT
79414 + default n
79415 + help
79416 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
79417 + by sending the proper error code to the application. For some broken
79418 + userland, this can cause problems with Python or other applications. The
79419 + current implementation however allows for applications like clamav to
79420 + detect if JIT compilation/execution is allowed and to fall back gracefully
79421 + to an interpreter-based mode if it does not. While we encourage everyone
79422 + to use the current implementation as-is and push upstream to fix broken
79423 + userland (note that the RWX logging option can assist with this), in some
79424 + environments this may not be possible. Having to disable MPROTECT
79425 + completely on certain binaries reduces the security benefit of PaX,
79426 + so this option is provided for those environments to revert to the old
79427 + behavior.
79428 +
79429 +config PAX_ELFRELOCS
79430 + bool "Allow ELF text relocations (read help)"
79431 + depends on PAX_MPROTECT
79432 + default n
79433 + help
79434 + Non-executable pages and mprotect() restrictions are effective
79435 + in preventing the introduction of new executable code into an
79436 + attacked task's address space. There remain only two venues
79437 + for this kind of attack: if the attacker can execute already
79438 + existing code in the attacked task then he can either have it
79439 + create and mmap() a file containing his code or have it mmap()
79440 + an already existing ELF library that does not have position
79441 + independent code in it and use mprotect() on it to make it
79442 + writable and copy his code there. While protecting against
79443 + the former approach is beyond PaX, the latter can be prevented
79444 + by having only PIC ELF libraries on one's system (which do not
79445 + need to relocate their code). If you are sure this is your case,
79446 + as is the case with all modern Linux distributions, then leave
79447 + this option disabled. You should say 'n' here.
79448 +
79449 +config PAX_ETEXECRELOCS
79450 + bool "Allow ELF ET_EXEC text relocations"
79451 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
79452 + select PAX_ELFRELOCS
79453 + default y
79454 + help
79455 + On some architectures there are incorrectly created applications
79456 + that require text relocations and would not work without enabling
79457 + this option. If you are an alpha, ia64 or parisc user, you should
79458 + enable this option and disable it once you have made sure that
79459 + none of your applications need it.
79460 +
79461 +config PAX_EMUPLT
79462 + bool "Automatically emulate ELF PLT"
79463 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
79464 + default y
79465 + help
79466 + Enabling this option will have the kernel automatically detect
79467 + and emulate the Procedure Linkage Table entries in ELF files.
79468 + On some architectures such entries are in writable memory, and
79469 + become non-executable leading to task termination. Therefore
79470 + it is mandatory that you enable this option on alpha, parisc,
79471 + sparc and sparc64, otherwise your system would not even boot.
79472 +
79473 + NOTE: this feature *does* open up a loophole in the protection
79474 + provided by the non-executable pages, therefore the proper
79475 + solution is to modify the toolchain to produce a PLT that does
79476 + not need to be writable.
79477 +
79478 +config PAX_DLRESOLVE
79479 + bool 'Emulate old glibc resolver stub'
79480 + depends on PAX_EMUPLT && SPARC
79481 + default n
79482 + help
79483 + This option is needed if userland has an old glibc (before 2.4)
79484 + that puts a 'save' instruction into the runtime generated resolver
79485 + stub that needs special emulation.
79486 +
79487 +config PAX_KERNEXEC
79488 + bool "Enforce non-executable kernel pages"
79489 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79490 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79491 + select PAX_KERNEXEC_PLUGIN if X86_64
79492 + help
79493 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79494 + that is, enabling this option will make it harder to inject
79495 + and execute 'foreign' code in kernel memory itself.
79496 +
79497 + Note that on x86_64 kernels there is a known regression when
79498 + this feature and KVM/VMX are both enabled in the host kernel.
79499 +
79500 +choice
79501 + prompt "Return Address Instrumentation Method"
79502 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
79503 + depends on PAX_KERNEXEC_PLUGIN
79504 + help
79505 + Select the method used to instrument function pointer dereferences.
79506 + Note that binary modules cannot be instrumented by this approach.
79507 +
79508 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
79509 + bool "bts"
79510 + help
79511 + This method is compatible with binary only modules but has
79512 + a higher runtime overhead.
79513 +
79514 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
79515 + bool "or"
79516 + depends on !PARAVIRT
79517 + help
79518 + This method is incompatible with binary only modules but has
79519 + a lower runtime overhead.
79520 +endchoice
79521 +
79522 +config PAX_KERNEXEC_PLUGIN_METHOD
79523 + string
79524 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
79525 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
79526 + default ""
79527 +
79528 +config PAX_KERNEXEC_MODULE_TEXT
79529 + int "Minimum amount of memory reserved for module code"
79530 + default "4"
79531 + depends on PAX_KERNEXEC && X86_32 && MODULES
79532 + help
79533 + Due to implementation details the kernel must reserve a fixed
79534 + amount of memory for module code at compile time that cannot be
79535 + changed at runtime. Here you can specify the minimum amount
79536 + in MB that will be reserved. Due to the same implementation
79537 + details this size will always be rounded up to the next 2/4 MB
79538 + boundary (depends on PAE) so the actually available memory for
79539 + module code will usually be more than this minimum.
79540 +
79541 + The default 4 MB should be enough for most users but if you have
79542 + an excessive number of modules (e.g., most distribution configs
79543 + compile many drivers as modules) or use huge modules such as
79544 + nvidia's kernel driver, you will need to adjust this amount.
79545 + A good rule of thumb is to look at your currently loaded kernel
79546 + modules and add up their sizes.
79547 +
79548 +endmenu
79549 +
79550 +menu "Address Space Layout Randomization"
79551 + depends on PAX
79552 +
79553 +config PAX_ASLR
79554 + bool "Address Space Layout Randomization"
79555 + help
79556 + Many if not most exploit techniques rely on the knowledge of
79557 + certain addresses in the attacked program. The following options
79558 + will allow the kernel to apply a certain amount of randomization
79559 + to specific parts of the program thereby forcing an attacker to
79560 + guess them in most cases. Any failed guess will most likely crash
79561 + the attacked program which allows the kernel to detect such attempts
79562 + and react on them. PaX itself provides no reaction mechanisms,
79563 + instead it is strongly encouraged that you make use of Nergal's
79564 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79565 + (http://www.grsecurity.net/) built-in crash detection features or
79566 + develop one yourself.
79567 +
79568 + By saying Y here you can choose to randomize the following areas:
79569 + - top of the task's kernel stack
79570 + - top of the task's userland stack
79571 + - base address for mmap() requests that do not specify one
79572 + (this includes all libraries)
79573 + - base address of the main executable
79574 +
79575 + It is strongly recommended to say Y here as address space layout
79576 + randomization has negligible impact on performance yet it provides
79577 + a very effective protection.
79578 +
79579 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79580 + this feature on a per file basis.
79581 +
79582 +config PAX_RANDKSTACK
79583 + bool "Randomize kernel stack base"
79584 + depends on X86_TSC && X86
79585 + help
79586 + By saying Y here the kernel will randomize every task's kernel
79587 + stack on every system call. This will not only force an attacker
79588 + to guess it but also prevent him from making use of possible
79589 + leaked information about it.
79590 +
79591 + Since the kernel stack is a rather scarce resource, randomization
79592 + may cause unexpected stack overflows, therefore you should very
79593 + carefully test your system. Note that once enabled in the kernel
79594 + configuration, this feature cannot be disabled on a per file basis.
79595 +
79596 +config PAX_RANDUSTACK
79597 + bool "Randomize user stack base"
79598 + depends on PAX_ASLR
79599 + help
79600 + By saying Y here the kernel will randomize every task's userland
79601 + stack. The randomization is done in two steps where the second
79602 + one may apply a big amount of shift to the top of the stack and
79603 + cause problems for programs that want to use lots of memory (more
79604 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79605 + For this reason the second step can be controlled by 'chpax' or
79606 + 'paxctl' on a per file basis.
79607 +
79608 +config PAX_RANDMMAP
79609 + bool "Randomize mmap() base"
79610 + depends on PAX_ASLR
79611 + help
79612 + By saying Y here the kernel will use a randomized base address for
79613 + mmap() requests that do not specify one themselves. As a result
79614 + all dynamically loaded libraries will appear at random addresses
79615 + and therefore be harder to exploit by a technique where an attacker
79616 + attempts to execute library code for his purposes (e.g. spawn a
79617 + shell from an exploited program that is running at an elevated
79618 + privilege level).
79619 +
79620 + Furthermore, if a program is relinked as a dynamic ELF file, its
79621 + base address will be randomized as well, completing the full
79622 + randomization of the address space layout. Attacking such programs
79623 + becomes a guess game. You can find an example of doing this at
79624 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79625 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79626 +
79627 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79628 + feature on a per file basis.
79629 +
79630 +endmenu
79631 +
79632 +menu "Miscellaneous hardening features"
79633 +
79634 +config PAX_MEMORY_SANITIZE
79635 + bool "Sanitize all freed memory"
79636 + depends on !HIBERNATION
79637 + help
79638 + By saying Y here the kernel will erase memory pages as soon as they
79639 + are freed. This in turn reduces the lifetime of data stored in the
79640 + pages, making it less likely that sensitive information such as
79641 + passwords, cryptographic secrets, etc stay in memory for too long.
79642 +
79643 + This is especially useful for programs whose runtime is short, long
79644 + lived processes and the kernel itself benefit from this as long as
79645 + they operate on whole memory pages and ensure timely freeing of pages
79646 + that may hold sensitive information.
79647 +
79648 + The tradeoff is performance impact, on a single CPU system kernel
79649 + compilation sees a 3% slowdown, other systems and workloads may vary
79650 + and you are advised to test this feature on your expected workload
79651 + before deploying it.
79652 +
79653 + Note that this feature does not protect data stored in live pages,
79654 + e.g., process memory swapped to disk may stay there for a long time.
79655 +
79656 +config PAX_MEMORY_STACKLEAK
79657 + bool "Sanitize kernel stack"
79658 + depends on X86
79659 + help
79660 + By saying Y here the kernel will erase the kernel stack before it
79661 + returns from a system call. This in turn reduces the information
79662 + that a kernel stack leak bug can reveal.
79663 +
79664 + Note that such a bug can still leak information that was put on
79665 + the stack by the current system call (the one eventually triggering
79666 + the bug) but traces of earlier system calls on the kernel stack
79667 + cannot leak anymore.
79668 +
79669 + The tradeoff is performance impact: on a single CPU system kernel
79670 + compilation sees a 1% slowdown, other systems and workloads may vary
79671 + and you are advised to test this feature on your expected workload
79672 + before deploying it.
79673 +
79674 + Note: full support for this feature requires gcc with plugin support
79675 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
79676 + versions means that functions with large enough stack frames may
79677 + leave uninitialized memory behind that may be exposed to a later
79678 + syscall leaking the stack.
79679 +
79680 +config PAX_MEMORY_UDEREF
79681 + bool "Prevent invalid userland pointer dereference"
79682 + depends on X86 && !UML_X86 && !XEN
79683 + select PAX_PER_CPU_PGD if X86_64
79684 + help
79685 + By saying Y here the kernel will be prevented from dereferencing
79686 + userland pointers in contexts where the kernel expects only kernel
79687 + pointers. This is both a useful runtime debugging feature and a
79688 + security measure that prevents exploiting a class of kernel bugs.
79689 +
79690 + The tradeoff is that some virtualization solutions may experience
79691 + a huge slowdown and therefore you should not enable this feature
79692 + for kernels meant to run in such environments. Whether a given VM
79693 + solution is affected or not is best determined by simply trying it
79694 + out, the performance impact will be obvious right on boot as this
79695 + mechanism engages from very early on. A good rule of thumb is that
79696 + VMs running on CPUs without hardware virtualization support (i.e.,
79697 + the majority of IA-32 CPUs) will likely experience the slowdown.
79698 +
79699 +config PAX_REFCOUNT
79700 + bool "Prevent various kernel object reference counter overflows"
79701 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
79702 + help
79703 + By saying Y here the kernel will detect and prevent overflowing
79704 + various (but not all) kinds of object reference counters. Such
79705 + overflows can normally occur due to bugs only and are often, if
79706 + not always, exploitable.
79707 +
79708 + The tradeoff is that data structures protected by an overflowed
79709 + refcount will never be freed and therefore will leak memory. Note
79710 + that this leak also happens even without this protection but in
79711 + that case the overflow can eventually trigger the freeing of the
79712 + data structure while it is still being used elsewhere, resulting
79713 + in the exploitable situation that this feature prevents.
79714 +
79715 + Since this has a negligible performance impact, you should enable
79716 + this feature.
79717 +
79718 +config PAX_USERCOPY
79719 + bool "Harden heap object copies between kernel and userland"
79720 + depends on X86 || PPC || SPARC || ARM
79721 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
79722 + help
79723 + By saying Y here the kernel will enforce the size of heap objects
79724 + when they are copied in either direction between the kernel and
79725 + userland, even if only a part of the heap object is copied.
79726 +
79727 + Specifically, this checking prevents information leaking from the
79728 + kernel heap during kernel to userland copies (if the kernel heap
79729 + object is otherwise fully initialized) and prevents kernel heap
79730 + overflows during userland to kernel copies.
79731 +
79732 + Note that the current implementation provides the strictest bounds
79733 + checks for the SLUB allocator.
79734 +
79735 + Enabling this option also enables per-slab cache protection against
79736 + data in a given cache being copied into/out of via userland
79737 + accessors. Though the whitelist of regions will be reduced over
79738 + time, it notably protects important data structures like task structs.
79739 +
79740 + If frame pointers are enabled on x86, this option will also restrict
79741 + copies into and out of the kernel stack to local variables within a
79742 + single frame.
79743 +
79744 + Since this has a negligible performance impact, you should enable
79745 + this feature.
79746 +
79747 +config PAX_SIZE_OVERFLOW
79748 + bool "Prevent various integer overflows in function size parameters"
79749 + depends on X86
79750 + help
79751 + By saying Y here the kernel recomputes expressions of function
79752 + arguments marked by a size_overflow attribute with double integer
79753 + precision (DImode/TImode for 32/64 bit integer types).
79754 +
79755 + The recomputed argument is checked against INT_MAX and an event
79756 + is logged on overflow and the triggering process is killed.
79757 +
79758 + Homepage:
79759 + http://www.grsecurity.net/~ephox/overflow_plugin/
79760 +
79761 +endmenu
79762 +
79763 +endmenu
79764 +
79765 config KEYS
79766 bool "Enable access key retention support"
79767 help
79768 @@ -169,7 +803,7 @@ config INTEL_TXT
79769 config LSM_MMAP_MIN_ADDR
79770 int "Low address space for LSM to protect from user allocation"
79771 depends on SECURITY && SECURITY_SELINUX
79772 - default 32768 if ARM
79773 + default 32768 if ALPHA || ARM || PARISC || SPARC32
79774 default 65536
79775 help
79776 This is the portion of low virtual memory which should be protected
79777 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
79778 index 97ce8fa..23dad96 100644
79779 --- a/security/apparmor/lsm.c
79780 +++ b/security/apparmor/lsm.c
79781 @@ -620,7 +620,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
79782 return error;
79783 }
79784
79785 -static struct security_operations apparmor_ops = {
79786 +static struct security_operations apparmor_ops __read_only = {
79787 .name = "apparmor",
79788
79789 .ptrace_access_check = apparmor_ptrace_access_check,
79790 diff --git a/security/commoncap.c b/security/commoncap.c
79791 index b8d2bb9..980069e 100644
79792 --- a/security/commoncap.c
79793 +++ b/security/commoncap.c
79794 @@ -29,6 +29,7 @@
79795 #include <linux/securebits.h>
79796 #include <linux/user_namespace.h>
79797 #include <linux/personality.h>
79798 +#include <net/sock.h>
79799
79800 /*
79801 * If a non-root user executes a setuid-root binary in
79802 @@ -575,6 +576,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
79803 {
79804 const struct cred *cred = current_cred();
79805
79806 + if (gr_acl_enable_at_secure())
79807 + return 1;
79808 +
79809 if (cred->uid != 0) {
79810 if (bprm->cap_effective)
79811 return 1;
79812 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
79813 index 3ccf7ac..d73ad64 100644
79814 --- a/security/integrity/ima/ima.h
79815 +++ b/security/integrity/ima/ima.h
79816 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79817 extern spinlock_t ima_queue_lock;
79818
79819 struct ima_h_table {
79820 - atomic_long_t len; /* number of stored measurements in the list */
79821 - atomic_long_t violations;
79822 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
79823 + atomic_long_unchecked_t violations;
79824 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
79825 };
79826 extern struct ima_h_table ima_htable;
79827 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
79828 index 88a2788..581ab92 100644
79829 --- a/security/integrity/ima/ima_api.c
79830 +++ b/security/integrity/ima/ima_api.c
79831 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79832 int result;
79833
79834 /* can overflow, only indicator */
79835 - atomic_long_inc(&ima_htable.violations);
79836 + atomic_long_inc_unchecked(&ima_htable.violations);
79837
79838 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
79839 if (!entry) {
79840 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
79841 index e1aa2b4..52027bf 100644
79842 --- a/security/integrity/ima/ima_fs.c
79843 +++ b/security/integrity/ima/ima_fs.c
79844 @@ -28,12 +28,12 @@
79845 static int valid_policy = 1;
79846 #define TMPBUFLEN 12
79847 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
79848 - loff_t *ppos, atomic_long_t *val)
79849 + loff_t *ppos, atomic_long_unchecked_t *val)
79850 {
79851 char tmpbuf[TMPBUFLEN];
79852 ssize_t len;
79853
79854 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
79855 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
79856 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
79857 }
79858
79859 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
79860 index 55a6271..ad829c3 100644
79861 --- a/security/integrity/ima/ima_queue.c
79862 +++ b/security/integrity/ima/ima_queue.c
79863 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
79864 INIT_LIST_HEAD(&qe->later);
79865 list_add_tail_rcu(&qe->later, &ima_measurements);
79866
79867 - atomic_long_inc(&ima_htable.len);
79868 + atomic_long_inc_unchecked(&ima_htable.len);
79869 key = ima_hash_key(entry->digest);
79870 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
79871 return 0;
79872 diff --git a/security/keys/compat.c b/security/keys/compat.c
79873 index 4c48e13..7abdac9 100644
79874 --- a/security/keys/compat.c
79875 +++ b/security/keys/compat.c
79876 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
79877 if (ret == 0)
79878 goto no_payload_free;
79879
79880 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79881 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79882
79883 if (iov != iovstack)
79884 kfree(iov);
79885 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
79886 index 0b3f5d7..892c8a6 100644
79887 --- a/security/keys/keyctl.c
79888 +++ b/security/keys/keyctl.c
79889 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
79890 /*
79891 * Copy the iovec data from userspace
79892 */
79893 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79894 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
79895 unsigned ioc)
79896 {
79897 for (; ioc > 0; ioc--) {
79898 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79899 * If successful, 0 will be returned.
79900 */
79901 long keyctl_instantiate_key_common(key_serial_t id,
79902 - const struct iovec *payload_iov,
79903 + const struct iovec __user *payload_iov,
79904 unsigned ioc,
79905 size_t plen,
79906 key_serial_t ringid)
79907 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
79908 [0].iov_len = plen
79909 };
79910
79911 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
79912 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
79913 }
79914
79915 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
79916 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
79917 if (ret == 0)
79918 goto no_payload_free;
79919
79920 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79921 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79922
79923 if (iov != iovstack)
79924 kfree(iov);
79925 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
79926 index d605f75..2bc6be9 100644
79927 --- a/security/keys/keyring.c
79928 +++ b/security/keys/keyring.c
79929 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
79930 ret = -EFAULT;
79931
79932 for (loop = 0; loop < klist->nkeys; loop++) {
79933 + key_serial_t serial;
79934 key = klist->keys[loop];
79935 + serial = key->serial;
79936
79937 tmp = sizeof(key_serial_t);
79938 if (tmp > buflen)
79939 tmp = buflen;
79940
79941 - if (copy_to_user(buffer,
79942 - &key->serial,
79943 - tmp) != 0)
79944 + if (copy_to_user(buffer, &serial, tmp))
79945 goto error;
79946
79947 buflen -= tmp;
79948 diff --git a/security/min_addr.c b/security/min_addr.c
79949 index f728728..6457a0c 100644
79950 --- a/security/min_addr.c
79951 +++ b/security/min_addr.c
79952 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
79953 */
79954 static void update_mmap_min_addr(void)
79955 {
79956 +#ifndef SPARC
79957 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
79958 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
79959 mmap_min_addr = dac_mmap_min_addr;
79960 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
79961 #else
79962 mmap_min_addr = dac_mmap_min_addr;
79963 #endif
79964 +#endif
79965 }
79966
79967 /*
79968 diff --git a/security/security.c b/security/security.c
79969 index d754249..8bf426e 100644
79970 --- a/security/security.c
79971 +++ b/security/security.c
79972 @@ -26,8 +26,8 @@
79973 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
79974 CONFIG_DEFAULT_SECURITY;
79975
79976 -static struct security_operations *security_ops;
79977 -static struct security_operations default_security_ops = {
79978 +static struct security_operations *security_ops __read_only;
79979 +static struct security_operations default_security_ops __read_only = {
79980 .name = "default",
79981 };
79982
79983 @@ -68,7 +68,9 @@ int __init security_init(void)
79984
79985 void reset_security_ops(void)
79986 {
79987 + pax_open_kernel();
79988 security_ops = &default_security_ops;
79989 + pax_close_kernel();
79990 }
79991
79992 /* Save user chosen LSM */
79993 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
79994 index 6a3683e..f52f4c0 100644
79995 --- a/security/selinux/hooks.c
79996 +++ b/security/selinux/hooks.c
79997 @@ -94,8 +94,6 @@
79998
79999 #define NUM_SEL_MNT_OPTS 5
80000
80001 -extern struct security_operations *security_ops;
80002 -
80003 /* SECMARK reference count */
80004 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
80005
80006 @@ -5429,7 +5427,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
80007
80008 #endif
80009
80010 -static struct security_operations selinux_ops = {
80011 +static struct security_operations selinux_ops __read_only = {
80012 .name = "selinux",
80013
80014 .ptrace_access_check = selinux_ptrace_access_check,
80015 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
80016 index b43813c..74be837 100644
80017 --- a/security/selinux/include/xfrm.h
80018 +++ b/security/selinux/include/xfrm.h
80019 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
80020
80021 static inline void selinux_xfrm_notify_policyload(void)
80022 {
80023 - atomic_inc(&flow_cache_genid);
80024 + atomic_inc_unchecked(&flow_cache_genid);
80025 }
80026 #else
80027 static inline int selinux_xfrm_enabled(void)
80028 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
80029 index e8af5b0b..78527ef 100644
80030 --- a/security/smack/smack_lsm.c
80031 +++ b/security/smack/smack_lsm.c
80032 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
80033 return 0;
80034 }
80035
80036 -struct security_operations smack_ops = {
80037 +struct security_operations smack_ops __read_only = {
80038 .name = "smack",
80039
80040 .ptrace_access_check = smack_ptrace_access_check,
80041 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
80042 index 620d37c..e2ad89b 100644
80043 --- a/security/tomoyo/tomoyo.c
80044 +++ b/security/tomoyo/tomoyo.c
80045 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
80046 * tomoyo_security_ops is a "struct security_operations" which is used for
80047 * registering TOMOYO.
80048 */
80049 -static struct security_operations tomoyo_security_ops = {
80050 +static struct security_operations tomoyo_security_ops __read_only = {
80051 .name = "tomoyo",
80052 .cred_alloc_blank = tomoyo_cred_alloc_blank,
80053 .cred_prepare = tomoyo_cred_prepare,
80054 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
80055 index 762af68..7103453 100644
80056 --- a/sound/aoa/codecs/onyx.c
80057 +++ b/sound/aoa/codecs/onyx.c
80058 @@ -54,7 +54,7 @@ struct onyx {
80059 spdif_locked:1,
80060 analog_locked:1,
80061 original_mute:2;
80062 - int open_count;
80063 + local_t open_count;
80064 struct codec_info *codec_info;
80065
80066 /* mutex serializes concurrent access to the device
80067 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
80068 struct onyx *onyx = cii->codec_data;
80069
80070 mutex_lock(&onyx->mutex);
80071 - onyx->open_count++;
80072 + local_inc(&onyx->open_count);
80073 mutex_unlock(&onyx->mutex);
80074
80075 return 0;
80076 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
80077 struct onyx *onyx = cii->codec_data;
80078
80079 mutex_lock(&onyx->mutex);
80080 - onyx->open_count--;
80081 - if (!onyx->open_count)
80082 + if (local_dec_and_test(&onyx->open_count))
80083 onyx->spdif_locked = onyx->analog_locked = 0;
80084 mutex_unlock(&onyx->mutex);
80085
80086 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
80087 index ffd2025..df062c9 100644
80088 --- a/sound/aoa/codecs/onyx.h
80089 +++ b/sound/aoa/codecs/onyx.h
80090 @@ -11,6 +11,7 @@
80091 #include <linux/i2c.h>
80092 #include <asm/pmac_low_i2c.h>
80093 #include <asm/prom.h>
80094 +#include <asm/local.h>
80095
80096 /* PCM3052 register definitions */
80097
80098 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
80099 index 08fde00..0bf641a 100644
80100 --- a/sound/core/oss/pcm_oss.c
80101 +++ b/sound/core/oss/pcm_oss.c
80102 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
80103 if (in_kernel) {
80104 mm_segment_t fs;
80105 fs = snd_enter_user();
80106 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80107 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80108 snd_leave_user(fs);
80109 } else {
80110 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80111 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80112 }
80113 if (ret != -EPIPE && ret != -ESTRPIPE)
80114 break;
80115 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
80116 if (in_kernel) {
80117 mm_segment_t fs;
80118 fs = snd_enter_user();
80119 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80120 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80121 snd_leave_user(fs);
80122 } else {
80123 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80124 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80125 }
80126 if (ret == -EPIPE) {
80127 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
80128 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
80129 struct snd_pcm_plugin_channel *channels;
80130 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
80131 if (!in_kernel) {
80132 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
80133 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
80134 return -EFAULT;
80135 buf = runtime->oss.buffer;
80136 }
80137 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
80138 }
80139 } else {
80140 tmp = snd_pcm_oss_write2(substream,
80141 - (const char __force *)buf,
80142 + (const char __force_kernel *)buf,
80143 runtime->oss.period_bytes, 0);
80144 if (tmp <= 0)
80145 goto err;
80146 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
80147 struct snd_pcm_runtime *runtime = substream->runtime;
80148 snd_pcm_sframes_t frames, frames1;
80149 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
80150 - char __user *final_dst = (char __force __user *)buf;
80151 + char __user *final_dst = (char __force_user *)buf;
80152 if (runtime->oss.plugin_first) {
80153 struct snd_pcm_plugin_channel *channels;
80154 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
80155 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
80156 xfer += tmp;
80157 runtime->oss.buffer_used -= tmp;
80158 } else {
80159 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
80160 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
80161 runtime->oss.period_bytes, 0);
80162 if (tmp <= 0)
80163 goto err;
80164 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
80165 size1);
80166 size1 /= runtime->channels; /* frames */
80167 fs = snd_enter_user();
80168 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
80169 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
80170 snd_leave_user(fs);
80171 }
80172 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
80173 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
80174 index 91cdf94..4085161 100644
80175 --- a/sound/core/pcm_compat.c
80176 +++ b/sound/core/pcm_compat.c
80177 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
80178 int err;
80179
80180 fs = snd_enter_user();
80181 - err = snd_pcm_delay(substream, &delay);
80182 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
80183 snd_leave_user(fs);
80184 if (err < 0)
80185 return err;
80186 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
80187 index 25ed9fe..24c46e9 100644
80188 --- a/sound/core/pcm_native.c
80189 +++ b/sound/core/pcm_native.c
80190 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
80191 switch (substream->stream) {
80192 case SNDRV_PCM_STREAM_PLAYBACK:
80193 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
80194 - (void __user *)arg);
80195 + (void __force_user *)arg);
80196 break;
80197 case SNDRV_PCM_STREAM_CAPTURE:
80198 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
80199 - (void __user *)arg);
80200 + (void __force_user *)arg);
80201 break;
80202 default:
80203 result = -EINVAL;
80204 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
80205 index 5cf8d65..912a79c 100644
80206 --- a/sound/core/seq/seq_device.c
80207 +++ b/sound/core/seq/seq_device.c
80208 @@ -64,7 +64,7 @@ struct ops_list {
80209 int argsize; /* argument size */
80210
80211 /* operators */
80212 - struct snd_seq_dev_ops ops;
80213 + struct snd_seq_dev_ops *ops;
80214
80215 /* registred devices */
80216 struct list_head dev_list; /* list of devices */
80217 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
80218
80219 mutex_lock(&ops->reg_mutex);
80220 /* copy driver operators */
80221 - ops->ops = *entry;
80222 + ops->ops = entry;
80223 ops->driver |= DRIVER_LOADED;
80224 ops->argsize = argsize;
80225
80226 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
80227 dev->name, ops->id, ops->argsize, dev->argsize);
80228 return -EINVAL;
80229 }
80230 - if (ops->ops.init_device(dev) >= 0) {
80231 + if (ops->ops->init_device(dev) >= 0) {
80232 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
80233 ops->num_init_devices++;
80234 } else {
80235 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
80236 dev->name, ops->id, ops->argsize, dev->argsize);
80237 return -EINVAL;
80238 }
80239 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
80240 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
80241 dev->status = SNDRV_SEQ_DEVICE_FREE;
80242 dev->driver_data = NULL;
80243 ops->num_init_devices--;
80244 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
80245 index 621e60e..f4543f5 100644
80246 --- a/sound/drivers/mts64.c
80247 +++ b/sound/drivers/mts64.c
80248 @@ -29,6 +29,7 @@
80249 #include <sound/initval.h>
80250 #include <sound/rawmidi.h>
80251 #include <sound/control.h>
80252 +#include <asm/local.h>
80253
80254 #define CARD_NAME "Miditerminal 4140"
80255 #define DRIVER_NAME "MTS64"
80256 @@ -67,7 +68,7 @@ struct mts64 {
80257 struct pardevice *pardev;
80258 int pardev_claimed;
80259
80260 - int open_count;
80261 + local_t open_count;
80262 int current_midi_output_port;
80263 int current_midi_input_port;
80264 u8 mode[MTS64_NUM_INPUT_PORTS];
80265 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80266 {
80267 struct mts64 *mts = substream->rmidi->private_data;
80268
80269 - if (mts->open_count == 0) {
80270 + if (local_read(&mts->open_count) == 0) {
80271 /* We don't need a spinlock here, because this is just called
80272 if the device has not been opened before.
80273 So there aren't any IRQs from the device */
80274 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80275
80276 msleep(50);
80277 }
80278 - ++(mts->open_count);
80279 + local_inc(&mts->open_count);
80280
80281 return 0;
80282 }
80283 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80284 struct mts64 *mts = substream->rmidi->private_data;
80285 unsigned long flags;
80286
80287 - --(mts->open_count);
80288 - if (mts->open_count == 0) {
80289 + if (local_dec_return(&mts->open_count) == 0) {
80290 /* We need the spinlock_irqsave here because we can still
80291 have IRQs at this point */
80292 spin_lock_irqsave(&mts->lock, flags);
80293 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80294
80295 msleep(500);
80296
80297 - } else if (mts->open_count < 0)
80298 - mts->open_count = 0;
80299 + } else if (local_read(&mts->open_count) < 0)
80300 + local_set(&mts->open_count, 0);
80301
80302 return 0;
80303 }
80304 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
80305 index b953fb4..1999c01 100644
80306 --- a/sound/drivers/opl4/opl4_lib.c
80307 +++ b/sound/drivers/opl4/opl4_lib.c
80308 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
80309 MODULE_DESCRIPTION("OPL4 driver");
80310 MODULE_LICENSE("GPL");
80311
80312 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
80313 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
80314 {
80315 int timeout = 10;
80316 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
80317 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
80318 index 3e32bd3..46fc152 100644
80319 --- a/sound/drivers/portman2x4.c
80320 +++ b/sound/drivers/portman2x4.c
80321 @@ -48,6 +48,7 @@
80322 #include <sound/initval.h>
80323 #include <sound/rawmidi.h>
80324 #include <sound/control.h>
80325 +#include <asm/local.h>
80326
80327 #define CARD_NAME "Portman 2x4"
80328 #define DRIVER_NAME "portman"
80329 @@ -85,7 +86,7 @@ struct portman {
80330 struct pardevice *pardev;
80331 int pardev_claimed;
80332
80333 - int open_count;
80334 + local_t open_count;
80335 int mode[PORTMAN_NUM_INPUT_PORTS];
80336 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
80337 };
80338 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
80339 index 87657dd..a8268d4 100644
80340 --- a/sound/firewire/amdtp.c
80341 +++ b/sound/firewire/amdtp.c
80342 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
80343 ptr = s->pcm_buffer_pointer + data_blocks;
80344 if (ptr >= pcm->runtime->buffer_size)
80345 ptr -= pcm->runtime->buffer_size;
80346 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
80347 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
80348
80349 s->pcm_period_pointer += data_blocks;
80350 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
80351 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
80352 */
80353 void amdtp_out_stream_update(struct amdtp_out_stream *s)
80354 {
80355 - ACCESS_ONCE(s->source_node_id_field) =
80356 + ACCESS_ONCE_RW(s->source_node_id_field) =
80357 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
80358 }
80359 EXPORT_SYMBOL(amdtp_out_stream_update);
80360 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
80361 index 537a9cb..8e8c8e9 100644
80362 --- a/sound/firewire/amdtp.h
80363 +++ b/sound/firewire/amdtp.h
80364 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
80365 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
80366 struct snd_pcm_substream *pcm)
80367 {
80368 - ACCESS_ONCE(s->pcm) = pcm;
80369 + ACCESS_ONCE_RW(s->pcm) = pcm;
80370 }
80371
80372 /**
80373 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
80374 index cd094ec..eca1277 100644
80375 --- a/sound/firewire/isight.c
80376 +++ b/sound/firewire/isight.c
80377 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
80378 ptr += count;
80379 if (ptr >= runtime->buffer_size)
80380 ptr -= runtime->buffer_size;
80381 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
80382 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
80383
80384 isight->period_counter += count;
80385 if (isight->period_counter >= runtime->period_size) {
80386 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
80387 if (err < 0)
80388 return err;
80389
80390 - ACCESS_ONCE(isight->pcm_active) = true;
80391 + ACCESS_ONCE_RW(isight->pcm_active) = true;
80392
80393 return 0;
80394 }
80395 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
80396 {
80397 struct isight *isight = substream->private_data;
80398
80399 - ACCESS_ONCE(isight->pcm_active) = false;
80400 + ACCESS_ONCE_RW(isight->pcm_active) = false;
80401
80402 mutex_lock(&isight->mutex);
80403 isight_stop_streaming(isight);
80404 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
80405
80406 switch (cmd) {
80407 case SNDRV_PCM_TRIGGER_START:
80408 - ACCESS_ONCE(isight->pcm_running) = true;
80409 + ACCESS_ONCE_RW(isight->pcm_running) = true;
80410 break;
80411 case SNDRV_PCM_TRIGGER_STOP:
80412 - ACCESS_ONCE(isight->pcm_running) = false;
80413 + ACCESS_ONCE_RW(isight->pcm_running) = false;
80414 break;
80415 default:
80416 return -EINVAL;
80417 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
80418 index 7bd5e33..1fcab12 100644
80419 --- a/sound/isa/cmi8330.c
80420 +++ b/sound/isa/cmi8330.c
80421 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
80422
80423 struct snd_pcm *pcm;
80424 struct snd_cmi8330_stream {
80425 - struct snd_pcm_ops ops;
80426 + snd_pcm_ops_no_const ops;
80427 snd_pcm_open_callback_t open;
80428 void *private_data; /* sb or wss */
80429 } streams[2];
80430 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
80431 index 733b014..56ce96f 100644
80432 --- a/sound/oss/sb_audio.c
80433 +++ b/sound/oss/sb_audio.c
80434 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
80435 buf16 = (signed short *)(localbuf + localoffs);
80436 while (c)
80437 {
80438 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80439 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80440 if (copy_from_user(lbuf8,
80441 userbuf+useroffs + p,
80442 locallen))
80443 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
80444 index 09d4648..cf234c7 100644
80445 --- a/sound/oss/swarm_cs4297a.c
80446 +++ b/sound/oss/swarm_cs4297a.c
80447 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
80448 {
80449 struct cs4297a_state *s;
80450 u32 pwr, id;
80451 - mm_segment_t fs;
80452 int rval;
80453 #ifndef CONFIG_BCM_CS4297A_CSWARM
80454 u64 cfg;
80455 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
80456 if (!rval) {
80457 char *sb1250_duart_present;
80458
80459 +#if 0
80460 + mm_segment_t fs;
80461 fs = get_fs();
80462 set_fs(KERNEL_DS);
80463 -#if 0
80464 val = SOUND_MASK_LINE;
80465 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
80466 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
80467 val = initvol[i].vol;
80468 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
80469 }
80470 + set_fs(fs);
80471 // cs4297a_write_ac97(s, 0x18, 0x0808);
80472 #else
80473 // cs4297a_write_ac97(s, 0x5e, 0x180);
80474 cs4297a_write_ac97(s, 0x02, 0x0808);
80475 cs4297a_write_ac97(s, 0x18, 0x0808);
80476 #endif
80477 - set_fs(fs);
80478
80479 list_add(&s->list, &cs4297a_devs);
80480
80481 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
80482 index f0f1943..8e1f96c 100644
80483 --- a/sound/pci/hda/hda_codec.h
80484 +++ b/sound/pci/hda/hda_codec.h
80485 @@ -611,7 +611,7 @@ struct hda_bus_ops {
80486 /* notify power-up/down from codec to controller */
80487 void (*pm_notify)(struct hda_bus *bus);
80488 #endif
80489 -};
80490 +} __no_const;
80491
80492 /* template to pass to the bus constructor */
80493 struct hda_bus_template {
80494 @@ -713,6 +713,7 @@ struct hda_codec_ops {
80495 #endif
80496 void (*reboot_notify)(struct hda_codec *codec);
80497 };
80498 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
80499
80500 /* record for amp information cache */
80501 struct hda_cache_head {
80502 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
80503 struct snd_pcm_substream *substream);
80504 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
80505 struct snd_pcm_substream *substream);
80506 -};
80507 +} __no_const;
80508
80509 /* PCM information for each substream */
80510 struct hda_pcm_stream {
80511 @@ -801,7 +802,7 @@ struct hda_codec {
80512 const char *modelname; /* model name for preset */
80513
80514 /* set by patch */
80515 - struct hda_codec_ops patch_ops;
80516 + hda_codec_ops_no_const patch_ops;
80517
80518 /* PCM to create, set by patch_ops.build_pcms callback */
80519 unsigned int num_pcms;
80520 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
80521 index 0da778a..bc38b84 100644
80522 --- a/sound/pci/ice1712/ice1712.h
80523 +++ b/sound/pci/ice1712/ice1712.h
80524 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
80525 unsigned int mask_flags; /* total mask bits */
80526 struct snd_akm4xxx_ops {
80527 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
80528 - } ops;
80529 + } __no_const ops;
80530 };
80531
80532 struct snd_ice1712_spdif {
80533 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
80534 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80535 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80536 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80537 - } ops;
80538 + } __no_const ops;
80539 };
80540
80541
80542 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
80543 index 12a9a2b..2b6138f 100644
80544 --- a/sound/pci/ymfpci/ymfpci_main.c
80545 +++ b/sound/pci/ymfpci/ymfpci_main.c
80546 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
80547 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
80548 break;
80549 }
80550 - if (atomic_read(&chip->interrupt_sleep_count)) {
80551 - atomic_set(&chip->interrupt_sleep_count, 0);
80552 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80553 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80554 wake_up(&chip->interrupt_sleep);
80555 }
80556 __end:
80557 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
80558 continue;
80559 init_waitqueue_entry(&wait, current);
80560 add_wait_queue(&chip->interrupt_sleep, &wait);
80561 - atomic_inc(&chip->interrupt_sleep_count);
80562 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
80563 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
80564 remove_wait_queue(&chip->interrupt_sleep, &wait);
80565 }
80566 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
80567 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
80568 spin_unlock(&chip->reg_lock);
80569
80570 - if (atomic_read(&chip->interrupt_sleep_count)) {
80571 - atomic_set(&chip->interrupt_sleep_count, 0);
80572 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80573 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80574 wake_up(&chip->interrupt_sleep);
80575 }
80576 }
80577 @@ -2389,7 +2389,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
80578 spin_lock_init(&chip->reg_lock);
80579 spin_lock_init(&chip->voice_lock);
80580 init_waitqueue_head(&chip->interrupt_sleep);
80581 - atomic_set(&chip->interrupt_sleep_count, 0);
80582 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80583 chip->card = card;
80584 chip->pci = pci;
80585 chip->irq = -1;
80586 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
80587 index cdc860a..db34a93 100644
80588 --- a/sound/soc/soc-pcm.c
80589 +++ b/sound/soc/soc-pcm.c
80590 @@ -605,7 +605,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
80591 struct snd_soc_platform *platform = rtd->platform;
80592 struct snd_soc_dai *codec_dai = rtd->codec_dai;
80593 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
80594 - struct snd_pcm_ops *soc_pcm_ops = &rtd->ops;
80595 + snd_pcm_ops_no_const *soc_pcm_ops = &rtd->ops;
80596 struct snd_pcm *pcm;
80597 char new_name[64];
80598 int ret = 0, playback = 0, capture = 0;
80599 diff --git a/sound/usb/card.h b/sound/usb/card.h
80600 index da5fa1a..113cd02 100644
80601 --- a/sound/usb/card.h
80602 +++ b/sound/usb/card.h
80603 @@ -45,6 +45,7 @@ struct snd_urb_ops {
80604 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80605 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80606 };
80607 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
80608
80609 struct snd_usb_substream {
80610 struct snd_usb_stream *stream;
80611 @@ -94,7 +95,7 @@ struct snd_usb_substream {
80612 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
80613 spinlock_t lock;
80614
80615 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
80616 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
80617 int last_frame_number; /* stored frame number */
80618 int last_delay; /* stored delay */
80619 };
80620 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
80621 new file mode 100644
80622 index 0000000..ca64170
80623 --- /dev/null
80624 +++ b/tools/gcc/Makefile
80625 @@ -0,0 +1,26 @@
80626 +#CC := gcc
80627 +#PLUGIN_SOURCE_FILES := pax_plugin.c
80628 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
80629 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
80630 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
80631 +
80632 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
80633 +CFLAGS_size_overflow_plugin.o := -Wno-missing-initializer
80634 +
80635 +hostlibs-y := constify_plugin.so
80636 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
80637 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
80638 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
80639 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
80640 +hostlibs-y += colorize_plugin.so
80641 +hostlibs-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
80642 +
80643 +always := $(hostlibs-y)
80644 +
80645 +constify_plugin-objs := constify_plugin.o
80646 +stackleak_plugin-objs := stackleak_plugin.o
80647 +kallocstat_plugin-objs := kallocstat_plugin.o
80648 +kernexec_plugin-objs := kernexec_plugin.o
80649 +checker_plugin-objs := checker_plugin.o
80650 +colorize_plugin-objs := colorize_plugin.o
80651 +size_overflow_plugin-objs := size_overflow_plugin.o
80652 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
80653 new file mode 100644
80654 index 0000000..d41b5af
80655 --- /dev/null
80656 +++ b/tools/gcc/checker_plugin.c
80657 @@ -0,0 +1,171 @@
80658 +/*
80659 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80660 + * Licensed under the GPL v2
80661 + *
80662 + * Note: the choice of the license means that the compilation process is
80663 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80664 + * but for the kernel it doesn't matter since it doesn't link against
80665 + * any of the gcc libraries
80666 + *
80667 + * gcc plugin to implement various sparse (source code checker) features
80668 + *
80669 + * TODO:
80670 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
80671 + *
80672 + * BUGS:
80673 + * - none known
80674 + */
80675 +#include "gcc-plugin.h"
80676 +#include "config.h"
80677 +#include "system.h"
80678 +#include "coretypes.h"
80679 +#include "tree.h"
80680 +#include "tree-pass.h"
80681 +#include "flags.h"
80682 +#include "intl.h"
80683 +#include "toplev.h"
80684 +#include "plugin.h"
80685 +//#include "expr.h" where are you...
80686 +#include "diagnostic.h"
80687 +#include "plugin-version.h"
80688 +#include "tm.h"
80689 +#include "function.h"
80690 +#include "basic-block.h"
80691 +#include "gimple.h"
80692 +#include "rtl.h"
80693 +#include "emit-rtl.h"
80694 +#include "tree-flow.h"
80695 +#include "target.h"
80696 +
80697 +extern void c_register_addr_space (const char *str, addr_space_t as);
80698 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
80699 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
80700 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
80701 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
80702 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
80703 +
80704 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80705 +extern rtx emit_move_insn(rtx x, rtx y);
80706 +
80707 +int plugin_is_GPL_compatible;
80708 +
80709 +static struct plugin_info checker_plugin_info = {
80710 + .version = "201111150100",
80711 +};
80712 +
80713 +#define ADDR_SPACE_KERNEL 0
80714 +#define ADDR_SPACE_FORCE_KERNEL 1
80715 +#define ADDR_SPACE_USER 2
80716 +#define ADDR_SPACE_FORCE_USER 3
80717 +#define ADDR_SPACE_IOMEM 0
80718 +#define ADDR_SPACE_FORCE_IOMEM 0
80719 +#define ADDR_SPACE_PERCPU 0
80720 +#define ADDR_SPACE_FORCE_PERCPU 0
80721 +#define ADDR_SPACE_RCU 0
80722 +#define ADDR_SPACE_FORCE_RCU 0
80723 +
80724 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
80725 +{
80726 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
80727 +}
80728 +
80729 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
80730 +{
80731 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
80732 +}
80733 +
80734 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
80735 +{
80736 + return default_addr_space_valid_pointer_mode(mode, as);
80737 +}
80738 +
80739 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
80740 +{
80741 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
80742 +}
80743 +
80744 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
80745 +{
80746 + return default_addr_space_legitimize_address(x, oldx, mode, as);
80747 +}
80748 +
80749 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
80750 +{
80751 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
80752 + return true;
80753 +
80754 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
80755 + return true;
80756 +
80757 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
80758 + return true;
80759 +
80760 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
80761 + return true;
80762 +
80763 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
80764 + return true;
80765 +
80766 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
80767 + return true;
80768 +
80769 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
80770 + return true;
80771 +
80772 + return subset == superset;
80773 +}
80774 +
80775 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
80776 +{
80777 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
80778 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
80779 +
80780 + return op;
80781 +}
80782 +
80783 +static void register_checker_address_spaces(void *event_data, void *data)
80784 +{
80785 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
80786 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
80787 + c_register_addr_space("__user", ADDR_SPACE_USER);
80788 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
80789 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
80790 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
80791 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
80792 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
80793 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
80794 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
80795 +
80796 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
80797 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
80798 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
80799 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
80800 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
80801 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
80802 + targetm.addr_space.convert = checker_addr_space_convert;
80803 +}
80804 +
80805 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80806 +{
80807 + const char * const plugin_name = plugin_info->base_name;
80808 + const int argc = plugin_info->argc;
80809 + const struct plugin_argument * const argv = plugin_info->argv;
80810 + int i;
80811 +
80812 + if (!plugin_default_version_check(version, &gcc_version)) {
80813 + error(G_("incompatible gcc/plugin versions"));
80814 + return 1;
80815 + }
80816 +
80817 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
80818 +
80819 + for (i = 0; i < argc; ++i)
80820 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80821 +
80822 + if (TARGET_64BIT == 0)
80823 + return 0;
80824 +
80825 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
80826 +
80827 + return 0;
80828 +}
80829 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
80830 new file mode 100644
80831 index 0000000..ee950d0
80832 --- /dev/null
80833 +++ b/tools/gcc/colorize_plugin.c
80834 @@ -0,0 +1,147 @@
80835 +/*
80836 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
80837 + * Licensed under the GPL v2
80838 + *
80839 + * Note: the choice of the license means that the compilation process is
80840 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80841 + * but for the kernel it doesn't matter since it doesn't link against
80842 + * any of the gcc libraries
80843 + *
80844 + * gcc plugin to colorize diagnostic output
80845 + *
80846 + */
80847 +
80848 +#include "gcc-plugin.h"
80849 +#include "config.h"
80850 +#include "system.h"
80851 +#include "coretypes.h"
80852 +#include "tree.h"
80853 +#include "tree-pass.h"
80854 +#include "flags.h"
80855 +#include "intl.h"
80856 +#include "toplev.h"
80857 +#include "plugin.h"
80858 +#include "diagnostic.h"
80859 +#include "plugin-version.h"
80860 +#include "tm.h"
80861 +
80862 +int plugin_is_GPL_compatible;
80863 +
80864 +static struct plugin_info colorize_plugin_info = {
80865 + .version = "201203092200",
80866 +};
80867 +
80868 +#define GREEN "\033[32m\033[2m"
80869 +#define LIGHTGREEN "\033[32m\033[1m"
80870 +#define YELLOW "\033[33m\033[2m"
80871 +#define LIGHTYELLOW "\033[33m\033[1m"
80872 +#define RED "\033[31m\033[2m"
80873 +#define LIGHTRED "\033[31m\033[1m"
80874 +#define BLUE "\033[34m\033[2m"
80875 +#define LIGHTBLUE "\033[34m\033[1m"
80876 +#define BRIGHT "\033[m\033[1m"
80877 +#define NORMAL "\033[m"
80878 +
80879 +static diagnostic_starter_fn old_starter;
80880 +static diagnostic_finalizer_fn old_finalizer;
80881 +
80882 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80883 +{
80884 + const char *color;
80885 + char *newprefix;
80886 +
80887 + switch (diagnostic->kind) {
80888 + case DK_NOTE:
80889 + color = LIGHTBLUE;
80890 + break;
80891 +
80892 + case DK_PEDWARN:
80893 + case DK_WARNING:
80894 + color = LIGHTYELLOW;
80895 + break;
80896 +
80897 + case DK_ERROR:
80898 + case DK_FATAL:
80899 + case DK_ICE:
80900 + case DK_PERMERROR:
80901 + case DK_SORRY:
80902 + color = LIGHTRED;
80903 + break;
80904 +
80905 + default:
80906 + color = NORMAL;
80907 + }
80908 +
80909 + old_starter(context, diagnostic);
80910 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
80911 + return;
80912 + pp_destroy_prefix(context->printer);
80913 + pp_set_prefix(context->printer, newprefix);
80914 +}
80915 +
80916 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80917 +{
80918 + old_finalizer(context, diagnostic);
80919 +}
80920 +
80921 +static void colorize_arm(void)
80922 +{
80923 + old_starter = diagnostic_starter(global_dc);
80924 + old_finalizer = diagnostic_finalizer(global_dc);
80925 +
80926 + diagnostic_starter(global_dc) = start_colorize;
80927 + diagnostic_finalizer(global_dc) = finalize_colorize;
80928 +}
80929 +
80930 +static unsigned int execute_colorize_rearm(void)
80931 +{
80932 + if (diagnostic_starter(global_dc) == start_colorize)
80933 + return 0;
80934 +
80935 + colorize_arm();
80936 + return 0;
80937 +}
80938 +
80939 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
80940 + .pass = {
80941 + .type = SIMPLE_IPA_PASS,
80942 + .name = "colorize_rearm",
80943 + .gate = NULL,
80944 + .execute = execute_colorize_rearm,
80945 + .sub = NULL,
80946 + .next = NULL,
80947 + .static_pass_number = 0,
80948 + .tv_id = TV_NONE,
80949 + .properties_required = 0,
80950 + .properties_provided = 0,
80951 + .properties_destroyed = 0,
80952 + .todo_flags_start = 0,
80953 + .todo_flags_finish = 0
80954 + }
80955 +};
80956 +
80957 +static void colorize_start_unit(void *gcc_data, void *user_data)
80958 +{
80959 + colorize_arm();
80960 +}
80961 +
80962 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80963 +{
80964 + const char * const plugin_name = plugin_info->base_name;
80965 + struct register_pass_info colorize_rearm_pass_info = {
80966 + .pass = &pass_ipa_colorize_rearm.pass,
80967 + .reference_pass_name = "*free_lang_data",
80968 + .ref_pass_instance_number = 0,
80969 + .pos_op = PASS_POS_INSERT_AFTER
80970 + };
80971 +
80972 + if (!plugin_default_version_check(version, &gcc_version)) {
80973 + error(G_("incompatible gcc/plugin versions"));
80974 + return 1;
80975 + }
80976 +
80977 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
80978 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
80979 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
80980 + return 0;
80981 +}
80982 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
80983 new file mode 100644
80984 index 0000000..88a7438
80985 --- /dev/null
80986 +++ b/tools/gcc/constify_plugin.c
80987 @@ -0,0 +1,303 @@
80988 +/*
80989 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
80990 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
80991 + * Licensed under the GPL v2, or (at your option) v3
80992 + *
80993 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
80994 + *
80995 + * Homepage:
80996 + * http://www.grsecurity.net/~ephox/const_plugin/
80997 + *
80998 + * Usage:
80999 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
81000 + * $ gcc -fplugin=constify_plugin.so test.c -O2
81001 + */
81002 +
81003 +#include "gcc-plugin.h"
81004 +#include "config.h"
81005 +#include "system.h"
81006 +#include "coretypes.h"
81007 +#include "tree.h"
81008 +#include "tree-pass.h"
81009 +#include "flags.h"
81010 +#include "intl.h"
81011 +#include "toplev.h"
81012 +#include "plugin.h"
81013 +#include "diagnostic.h"
81014 +#include "plugin-version.h"
81015 +#include "tm.h"
81016 +#include "function.h"
81017 +#include "basic-block.h"
81018 +#include "gimple.h"
81019 +#include "rtl.h"
81020 +#include "emit-rtl.h"
81021 +#include "tree-flow.h"
81022 +
81023 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
81024 +
81025 +int plugin_is_GPL_compatible;
81026 +
81027 +static struct plugin_info const_plugin_info = {
81028 + .version = "201111150100",
81029 + .help = "no-constify\tturn off constification\n",
81030 +};
81031 +
81032 +static void constify_type(tree type);
81033 +static bool walk_struct(tree node);
81034 +
81035 +static tree deconstify_type(tree old_type)
81036 +{
81037 + tree new_type, field;
81038 +
81039 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
81040 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
81041 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
81042 + DECL_FIELD_CONTEXT(field) = new_type;
81043 + TYPE_READONLY(new_type) = 0;
81044 + C_TYPE_FIELDS_READONLY(new_type) = 0;
81045 + return new_type;
81046 +}
81047 +
81048 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81049 +{
81050 + tree type;
81051 +
81052 + *no_add_attrs = true;
81053 + if (TREE_CODE(*node) == FUNCTION_DECL) {
81054 + error("%qE attribute does not apply to functions", name);
81055 + return NULL_TREE;
81056 + }
81057 +
81058 + if (TREE_CODE(*node) == VAR_DECL) {
81059 + error("%qE attribute does not apply to variables", name);
81060 + return NULL_TREE;
81061 + }
81062 +
81063 + if (TYPE_P(*node)) {
81064 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
81065 + *no_add_attrs = false;
81066 + else
81067 + error("%qE attribute applies to struct and union types only", name);
81068 + return NULL_TREE;
81069 + }
81070 +
81071 + type = TREE_TYPE(*node);
81072 +
81073 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
81074 + error("%qE attribute applies to struct and union types only", name);
81075 + return NULL_TREE;
81076 + }
81077 +
81078 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
81079 + error("%qE attribute is already applied to the type", name);
81080 + return NULL_TREE;
81081 + }
81082 +
81083 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
81084 + error("%qE attribute used on type that is not constified", name);
81085 + return NULL_TREE;
81086 + }
81087 +
81088 + if (TREE_CODE(*node) == TYPE_DECL) {
81089 + TREE_TYPE(*node) = deconstify_type(type);
81090 + TREE_READONLY(*node) = 0;
81091 + return NULL_TREE;
81092 + }
81093 +
81094 + return NULL_TREE;
81095 +}
81096 +
81097 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81098 +{
81099 + *no_add_attrs = true;
81100 + if (!TYPE_P(*node)) {
81101 + error("%qE attribute applies to types only", name);
81102 + return NULL_TREE;
81103 + }
81104 +
81105 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
81106 + error("%qE attribute applies to struct and union types only", name);
81107 + return NULL_TREE;
81108 + }
81109 +
81110 + *no_add_attrs = false;
81111 + constify_type(*node);
81112 + return NULL_TREE;
81113 +}
81114 +
81115 +static struct attribute_spec no_const_attr = {
81116 + .name = "no_const",
81117 + .min_length = 0,
81118 + .max_length = 0,
81119 + .decl_required = false,
81120 + .type_required = false,
81121 + .function_type_required = false,
81122 + .handler = handle_no_const_attribute,
81123 +#if BUILDING_GCC_VERSION >= 4007
81124 + .affects_type_identity = true
81125 +#endif
81126 +};
81127 +
81128 +static struct attribute_spec do_const_attr = {
81129 + .name = "do_const",
81130 + .min_length = 0,
81131 + .max_length = 0,
81132 + .decl_required = false,
81133 + .type_required = false,
81134 + .function_type_required = false,
81135 + .handler = handle_do_const_attribute,
81136 +#if BUILDING_GCC_VERSION >= 4007
81137 + .affects_type_identity = true
81138 +#endif
81139 +};
81140 +
81141 +static void register_attributes(void *event_data, void *data)
81142 +{
81143 + register_attribute(&no_const_attr);
81144 + register_attribute(&do_const_attr);
81145 +}
81146 +
81147 +static void constify_type(tree type)
81148 +{
81149 + TYPE_READONLY(type) = 1;
81150 + C_TYPE_FIELDS_READONLY(type) = 1;
81151 +}
81152 +
81153 +static bool is_fptr(tree field)
81154 +{
81155 + tree ptr = TREE_TYPE(field);
81156 +
81157 + if (TREE_CODE(ptr) != POINTER_TYPE)
81158 + return false;
81159 +
81160 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
81161 +}
81162 +
81163 +static bool walk_struct(tree node)
81164 +{
81165 + tree field;
81166 +
81167 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
81168 + return false;
81169 +
81170 + if (TYPE_FIELDS(node) == NULL_TREE)
81171 + return false;
81172 +
81173 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
81174 + tree type = TREE_TYPE(field);
81175 + enum tree_code code = TREE_CODE(type);
81176 + if (code == RECORD_TYPE || code == UNION_TYPE) {
81177 + if (!(walk_struct(type)))
81178 + return false;
81179 + } else if (!is_fptr(field) && !TREE_READONLY(field))
81180 + return false;
81181 + }
81182 + return true;
81183 +}
81184 +
81185 +static void finish_type(void *event_data, void *data)
81186 +{
81187 + tree type = (tree)event_data;
81188 +
81189 + if (type == NULL_TREE)
81190 + return;
81191 +
81192 + if (TYPE_READONLY(type))
81193 + return;
81194 +
81195 + if (walk_struct(type))
81196 + constify_type(type);
81197 +}
81198 +
81199 +static unsigned int check_local_variables(void);
81200 +
81201 +struct gimple_opt_pass pass_local_variable = {
81202 + {
81203 + .type = GIMPLE_PASS,
81204 + .name = "check_local_variables",
81205 + .gate = NULL,
81206 + .execute = check_local_variables,
81207 + .sub = NULL,
81208 + .next = NULL,
81209 + .static_pass_number = 0,
81210 + .tv_id = TV_NONE,
81211 + .properties_required = 0,
81212 + .properties_provided = 0,
81213 + .properties_destroyed = 0,
81214 + .todo_flags_start = 0,
81215 + .todo_flags_finish = 0
81216 + }
81217 +};
81218 +
81219 +static unsigned int check_local_variables(void)
81220 +{
81221 + tree var;
81222 + referenced_var_iterator rvi;
81223 +
81224 +#if BUILDING_GCC_VERSION == 4005
81225 + FOR_EACH_REFERENCED_VAR(var, rvi) {
81226 +#else
81227 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
81228 +#endif
81229 + tree type = TREE_TYPE(var);
81230 +
81231 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
81232 + continue;
81233 +
81234 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81235 + continue;
81236 +
81237 + if (!TYPE_READONLY(type))
81238 + continue;
81239 +
81240 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
81241 +// continue;
81242 +
81243 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
81244 +// continue;
81245 +
81246 + if (walk_struct(type)) {
81247 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
81248 + return 1;
81249 + }
81250 + }
81251 + return 0;
81252 +}
81253 +
81254 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81255 +{
81256 + const char * const plugin_name = plugin_info->base_name;
81257 + const int argc = plugin_info->argc;
81258 + const struct plugin_argument * const argv = plugin_info->argv;
81259 + int i;
81260 + bool constify = true;
81261 +
81262 + struct register_pass_info local_variable_pass_info = {
81263 + .pass = &pass_local_variable.pass,
81264 + .reference_pass_name = "*referenced_vars",
81265 + .ref_pass_instance_number = 0,
81266 + .pos_op = PASS_POS_INSERT_AFTER
81267 + };
81268 +
81269 + if (!plugin_default_version_check(version, &gcc_version)) {
81270 + error(G_("incompatible gcc/plugin versions"));
81271 + return 1;
81272 + }
81273 +
81274 + for (i = 0; i < argc; ++i) {
81275 + if (!(strcmp(argv[i].key, "no-constify"))) {
81276 + constify = false;
81277 + continue;
81278 + }
81279 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81280 + }
81281 +
81282 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
81283 + if (constify) {
81284 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
81285 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
81286 + }
81287 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
81288 +
81289 + return 0;
81290 +}
81291 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
81292 new file mode 100644
81293 index 0000000..a5eabce
81294 --- /dev/null
81295 +++ b/tools/gcc/kallocstat_plugin.c
81296 @@ -0,0 +1,167 @@
81297 +/*
81298 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81299 + * Licensed under the GPL v2
81300 + *
81301 + * Note: the choice of the license means that the compilation process is
81302 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81303 + * but for the kernel it doesn't matter since it doesn't link against
81304 + * any of the gcc libraries
81305 + *
81306 + * gcc plugin to find the distribution of k*alloc sizes
81307 + *
81308 + * TODO:
81309 + *
81310 + * BUGS:
81311 + * - none known
81312 + */
81313 +#include "gcc-plugin.h"
81314 +#include "config.h"
81315 +#include "system.h"
81316 +#include "coretypes.h"
81317 +#include "tree.h"
81318 +#include "tree-pass.h"
81319 +#include "flags.h"
81320 +#include "intl.h"
81321 +#include "toplev.h"
81322 +#include "plugin.h"
81323 +//#include "expr.h" where are you...
81324 +#include "diagnostic.h"
81325 +#include "plugin-version.h"
81326 +#include "tm.h"
81327 +#include "function.h"
81328 +#include "basic-block.h"
81329 +#include "gimple.h"
81330 +#include "rtl.h"
81331 +#include "emit-rtl.h"
81332 +
81333 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81334 +
81335 +int plugin_is_GPL_compatible;
81336 +
81337 +static const char * const kalloc_functions[] = {
81338 + "__kmalloc",
81339 + "kmalloc",
81340 + "kmalloc_large",
81341 + "kmalloc_node",
81342 + "kmalloc_order",
81343 + "kmalloc_order_trace",
81344 + "kmalloc_slab",
81345 + "kzalloc",
81346 + "kzalloc_node",
81347 +};
81348 +
81349 +static struct plugin_info kallocstat_plugin_info = {
81350 + .version = "201111150100",
81351 +};
81352 +
81353 +static unsigned int execute_kallocstat(void);
81354 +
81355 +static struct gimple_opt_pass kallocstat_pass = {
81356 + .pass = {
81357 + .type = GIMPLE_PASS,
81358 + .name = "kallocstat",
81359 + .gate = NULL,
81360 + .execute = execute_kallocstat,
81361 + .sub = NULL,
81362 + .next = NULL,
81363 + .static_pass_number = 0,
81364 + .tv_id = TV_NONE,
81365 + .properties_required = 0,
81366 + .properties_provided = 0,
81367 + .properties_destroyed = 0,
81368 + .todo_flags_start = 0,
81369 + .todo_flags_finish = 0
81370 + }
81371 +};
81372 +
81373 +static bool is_kalloc(const char *fnname)
81374 +{
81375 + size_t i;
81376 +
81377 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
81378 + if (!strcmp(fnname, kalloc_functions[i]))
81379 + return true;
81380 + return false;
81381 +}
81382 +
81383 +static unsigned int execute_kallocstat(void)
81384 +{
81385 + basic_block bb;
81386 +
81387 + // 1. loop through BBs and GIMPLE statements
81388 + FOR_EACH_BB(bb) {
81389 + gimple_stmt_iterator gsi;
81390 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81391 + // gimple match:
81392 + tree fndecl, size;
81393 + gimple call_stmt;
81394 + const char *fnname;
81395 +
81396 + // is it a call
81397 + call_stmt = gsi_stmt(gsi);
81398 + if (!is_gimple_call(call_stmt))
81399 + continue;
81400 + fndecl = gimple_call_fndecl(call_stmt);
81401 + if (fndecl == NULL_TREE)
81402 + continue;
81403 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
81404 + continue;
81405 +
81406 + // is it a call to k*alloc
81407 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
81408 + if (!is_kalloc(fnname))
81409 + continue;
81410 +
81411 + // is the size arg the result of a simple const assignment
81412 + size = gimple_call_arg(call_stmt, 0);
81413 + while (true) {
81414 + gimple def_stmt;
81415 + expanded_location xloc;
81416 + size_t size_val;
81417 +
81418 + if (TREE_CODE(size) != SSA_NAME)
81419 + break;
81420 + def_stmt = SSA_NAME_DEF_STMT(size);
81421 + if (!def_stmt || !is_gimple_assign(def_stmt))
81422 + break;
81423 + if (gimple_num_ops(def_stmt) != 2)
81424 + break;
81425 + size = gimple_assign_rhs1(def_stmt);
81426 + if (!TREE_CONSTANT(size))
81427 + continue;
81428 + xloc = expand_location(gimple_location(def_stmt));
81429 + if (!xloc.file)
81430 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
81431 + size_val = TREE_INT_CST_LOW(size);
81432 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
81433 + break;
81434 + }
81435 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81436 +//debug_tree(gimple_call_fn(call_stmt));
81437 +//print_node(stderr, "pax", fndecl, 4);
81438 + }
81439 + }
81440 +
81441 + return 0;
81442 +}
81443 +
81444 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81445 +{
81446 + const char * const plugin_name = plugin_info->base_name;
81447 + struct register_pass_info kallocstat_pass_info = {
81448 + .pass = &kallocstat_pass.pass,
81449 + .reference_pass_name = "ssa",
81450 + .ref_pass_instance_number = 0,
81451 + .pos_op = PASS_POS_INSERT_AFTER
81452 + };
81453 +
81454 + if (!plugin_default_version_check(version, &gcc_version)) {
81455 + error(G_("incompatible gcc/plugin versions"));
81456 + return 1;
81457 + }
81458 +
81459 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
81460 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
81461 +
81462 + return 0;
81463 +}
81464 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
81465 new file mode 100644
81466 index 0000000..d8a8da2
81467 --- /dev/null
81468 +++ b/tools/gcc/kernexec_plugin.c
81469 @@ -0,0 +1,427 @@
81470 +/*
81471 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81472 + * Licensed under the GPL v2
81473 + *
81474 + * Note: the choice of the license means that the compilation process is
81475 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81476 + * but for the kernel it doesn't matter since it doesn't link against
81477 + * any of the gcc libraries
81478 + *
81479 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
81480 + *
81481 + * TODO:
81482 + *
81483 + * BUGS:
81484 + * - none known
81485 + */
81486 +#include "gcc-plugin.h"
81487 +#include "config.h"
81488 +#include "system.h"
81489 +#include "coretypes.h"
81490 +#include "tree.h"
81491 +#include "tree-pass.h"
81492 +#include "flags.h"
81493 +#include "intl.h"
81494 +#include "toplev.h"
81495 +#include "plugin.h"
81496 +//#include "expr.h" where are you...
81497 +#include "diagnostic.h"
81498 +#include "plugin-version.h"
81499 +#include "tm.h"
81500 +#include "function.h"
81501 +#include "basic-block.h"
81502 +#include "gimple.h"
81503 +#include "rtl.h"
81504 +#include "emit-rtl.h"
81505 +#include "tree-flow.h"
81506 +
81507 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81508 +extern rtx emit_move_insn(rtx x, rtx y);
81509 +
81510 +int plugin_is_GPL_compatible;
81511 +
81512 +static struct plugin_info kernexec_plugin_info = {
81513 + .version = "201111291120",
81514 + .help = "method=[bts|or]\tinstrumentation method\n"
81515 +};
81516 +
81517 +static unsigned int execute_kernexec_reload(void);
81518 +static unsigned int execute_kernexec_fptr(void);
81519 +static unsigned int execute_kernexec_retaddr(void);
81520 +static bool kernexec_cmodel_check(void);
81521 +
81522 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
81523 +static void (*kernexec_instrument_retaddr)(rtx);
81524 +
81525 +static struct gimple_opt_pass kernexec_reload_pass = {
81526 + .pass = {
81527 + .type = GIMPLE_PASS,
81528 + .name = "kernexec_reload",
81529 + .gate = kernexec_cmodel_check,
81530 + .execute = execute_kernexec_reload,
81531 + .sub = NULL,
81532 + .next = NULL,
81533 + .static_pass_number = 0,
81534 + .tv_id = TV_NONE,
81535 + .properties_required = 0,
81536 + .properties_provided = 0,
81537 + .properties_destroyed = 0,
81538 + .todo_flags_start = 0,
81539 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81540 + }
81541 +};
81542 +
81543 +static struct gimple_opt_pass kernexec_fptr_pass = {
81544 + .pass = {
81545 + .type = GIMPLE_PASS,
81546 + .name = "kernexec_fptr",
81547 + .gate = kernexec_cmodel_check,
81548 + .execute = execute_kernexec_fptr,
81549 + .sub = NULL,
81550 + .next = NULL,
81551 + .static_pass_number = 0,
81552 + .tv_id = TV_NONE,
81553 + .properties_required = 0,
81554 + .properties_provided = 0,
81555 + .properties_destroyed = 0,
81556 + .todo_flags_start = 0,
81557 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81558 + }
81559 +};
81560 +
81561 +static struct rtl_opt_pass kernexec_retaddr_pass = {
81562 + .pass = {
81563 + .type = RTL_PASS,
81564 + .name = "kernexec_retaddr",
81565 + .gate = kernexec_cmodel_check,
81566 + .execute = execute_kernexec_retaddr,
81567 + .sub = NULL,
81568 + .next = NULL,
81569 + .static_pass_number = 0,
81570 + .tv_id = TV_NONE,
81571 + .properties_required = 0,
81572 + .properties_provided = 0,
81573 + .properties_destroyed = 0,
81574 + .todo_flags_start = 0,
81575 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
81576 + }
81577 +};
81578 +
81579 +static bool kernexec_cmodel_check(void)
81580 +{
81581 + tree section;
81582 +
81583 + if (ix86_cmodel != CM_KERNEL)
81584 + return false;
81585 +
81586 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
81587 + if (!section || !TREE_VALUE(section))
81588 + return true;
81589 +
81590 + section = TREE_VALUE(TREE_VALUE(section));
81591 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
81592 + return true;
81593 +
81594 + return false;
81595 +}
81596 +
81597 +/*
81598 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
81599 + */
81600 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
81601 +{
81602 + gimple asm_movabs_stmt;
81603 +
81604 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
81605 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
81606 + gimple_asm_set_volatile(asm_movabs_stmt, true);
81607 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
81608 + update_stmt(asm_movabs_stmt);
81609 +}
81610 +
81611 +/*
81612 + * find all asm() stmts that clobber r10 and add a reload of r10
81613 + */
81614 +static unsigned int execute_kernexec_reload(void)
81615 +{
81616 + basic_block bb;
81617 +
81618 + // 1. loop through BBs and GIMPLE statements
81619 + FOR_EACH_BB(bb) {
81620 + gimple_stmt_iterator gsi;
81621 +
81622 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81623 + // gimple match: __asm__ ("" : : : "r10");
81624 + gimple asm_stmt;
81625 + size_t nclobbers;
81626 +
81627 + // is it an asm ...
81628 + asm_stmt = gsi_stmt(gsi);
81629 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
81630 + continue;
81631 +
81632 + // ... clobbering r10
81633 + nclobbers = gimple_asm_nclobbers(asm_stmt);
81634 + while (nclobbers--) {
81635 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
81636 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
81637 + continue;
81638 + kernexec_reload_fptr_mask(&gsi);
81639 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
81640 + break;
81641 + }
81642 + }
81643 + }
81644 +
81645 + return 0;
81646 +}
81647 +
81648 +/*
81649 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
81650 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
81651 + */
81652 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
81653 +{
81654 + gimple assign_intptr, assign_new_fptr, call_stmt;
81655 + tree intptr, old_fptr, new_fptr, kernexec_mask;
81656 +
81657 + call_stmt = gsi_stmt(*gsi);
81658 + old_fptr = gimple_call_fn(call_stmt);
81659 +
81660 + // create temporary unsigned long variable used for bitops and cast fptr to it
81661 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
81662 + add_referenced_var(intptr);
81663 + mark_sym_for_renaming(intptr);
81664 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
81665 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81666 + update_stmt(assign_intptr);
81667 +
81668 + // apply logical or to temporary unsigned long and bitmask
81669 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
81670 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
81671 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
81672 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81673 + update_stmt(assign_intptr);
81674 +
81675 + // cast temporary unsigned long back to a temporary fptr variable
81676 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
81677 + add_referenced_var(new_fptr);
81678 + mark_sym_for_renaming(new_fptr);
81679 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
81680 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
81681 + update_stmt(assign_new_fptr);
81682 +
81683 + // replace call stmt fn with the new fptr
81684 + gimple_call_set_fn(call_stmt, new_fptr);
81685 + update_stmt(call_stmt);
81686 +}
81687 +
81688 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
81689 +{
81690 + gimple asm_or_stmt, call_stmt;
81691 + tree old_fptr, new_fptr, input, output;
81692 + VEC(tree, gc) *inputs = NULL;
81693 + VEC(tree, gc) *outputs = NULL;
81694 +
81695 + call_stmt = gsi_stmt(*gsi);
81696 + old_fptr = gimple_call_fn(call_stmt);
81697 +
81698 + // create temporary fptr variable
81699 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
81700 + add_referenced_var(new_fptr);
81701 + mark_sym_for_renaming(new_fptr);
81702 +
81703 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
81704 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
81705 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
81706 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
81707 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
81708 + VEC_safe_push(tree, gc, inputs, input);
81709 + VEC_safe_push(tree, gc, outputs, output);
81710 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
81711 + gimple_asm_set_volatile(asm_or_stmt, true);
81712 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
81713 + update_stmt(asm_or_stmt);
81714 +
81715 + // replace call stmt fn with the new fptr
81716 + gimple_call_set_fn(call_stmt, new_fptr);
81717 + update_stmt(call_stmt);
81718 +}
81719 +
81720 +/*
81721 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
81722 + */
81723 +static unsigned int execute_kernexec_fptr(void)
81724 +{
81725 + basic_block bb;
81726 +
81727 + // 1. loop through BBs and GIMPLE statements
81728 + FOR_EACH_BB(bb) {
81729 + gimple_stmt_iterator gsi;
81730 +
81731 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81732 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
81733 + tree fn;
81734 + gimple call_stmt;
81735 +
81736 + // is it a call ...
81737 + call_stmt = gsi_stmt(gsi);
81738 + if (!is_gimple_call(call_stmt))
81739 + continue;
81740 + fn = gimple_call_fn(call_stmt);
81741 + if (TREE_CODE(fn) == ADDR_EXPR)
81742 + continue;
81743 + if (TREE_CODE(fn) != SSA_NAME)
81744 + gcc_unreachable();
81745 +
81746 + // ... through a function pointer
81747 + fn = SSA_NAME_VAR(fn);
81748 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
81749 + continue;
81750 + fn = TREE_TYPE(fn);
81751 + if (TREE_CODE(fn) != POINTER_TYPE)
81752 + continue;
81753 + fn = TREE_TYPE(fn);
81754 + if (TREE_CODE(fn) != FUNCTION_TYPE)
81755 + continue;
81756 +
81757 + kernexec_instrument_fptr(&gsi);
81758 +
81759 +//debug_tree(gimple_call_fn(call_stmt));
81760 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81761 + }
81762 + }
81763 +
81764 + return 0;
81765 +}
81766 +
81767 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
81768 +static void kernexec_instrument_retaddr_bts(rtx insn)
81769 +{
81770 + rtx btsq;
81771 + rtvec argvec, constraintvec, labelvec;
81772 + int line;
81773 +
81774 + // create asm volatile("btsq $63,(%%rsp)":::)
81775 + argvec = rtvec_alloc(0);
81776 + constraintvec = rtvec_alloc(0);
81777 + labelvec = rtvec_alloc(0);
81778 + line = expand_location(RTL_LOCATION(insn)).line;
81779 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81780 + MEM_VOLATILE_P(btsq) = 1;
81781 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
81782 + emit_insn_before(btsq, insn);
81783 +}
81784 +
81785 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
81786 +static void kernexec_instrument_retaddr_or(rtx insn)
81787 +{
81788 + rtx orq;
81789 + rtvec argvec, constraintvec, labelvec;
81790 + int line;
81791 +
81792 + // create asm volatile("orq %%r10,(%%rsp)":::)
81793 + argvec = rtvec_alloc(0);
81794 + constraintvec = rtvec_alloc(0);
81795 + labelvec = rtvec_alloc(0);
81796 + line = expand_location(RTL_LOCATION(insn)).line;
81797 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81798 + MEM_VOLATILE_P(orq) = 1;
81799 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
81800 + emit_insn_before(orq, insn);
81801 +}
81802 +
81803 +/*
81804 + * find all asm level function returns and forcibly set the highest bit of the return address
81805 + */
81806 +static unsigned int execute_kernexec_retaddr(void)
81807 +{
81808 + rtx insn;
81809 +
81810 + // 1. find function returns
81811 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
81812 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
81813 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
81814 + rtx body;
81815 +
81816 + // is it a retn
81817 + if (!JUMP_P(insn))
81818 + continue;
81819 + body = PATTERN(insn);
81820 + if (GET_CODE(body) == PARALLEL)
81821 + body = XVECEXP(body, 0, 0);
81822 + if (GET_CODE(body) != RETURN)
81823 + continue;
81824 + kernexec_instrument_retaddr(insn);
81825 + }
81826 +
81827 +// print_simple_rtl(stderr, get_insns());
81828 +// print_rtl(stderr, get_insns());
81829 +
81830 + return 0;
81831 +}
81832 +
81833 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81834 +{
81835 + const char * const plugin_name = plugin_info->base_name;
81836 + const int argc = plugin_info->argc;
81837 + const struct plugin_argument * const argv = plugin_info->argv;
81838 + int i;
81839 + struct register_pass_info kernexec_reload_pass_info = {
81840 + .pass = &kernexec_reload_pass.pass,
81841 + .reference_pass_name = "ssa",
81842 + .ref_pass_instance_number = 0,
81843 + .pos_op = PASS_POS_INSERT_AFTER
81844 + };
81845 + struct register_pass_info kernexec_fptr_pass_info = {
81846 + .pass = &kernexec_fptr_pass.pass,
81847 + .reference_pass_name = "ssa",
81848 + .ref_pass_instance_number = 0,
81849 + .pos_op = PASS_POS_INSERT_AFTER
81850 + };
81851 + struct register_pass_info kernexec_retaddr_pass_info = {
81852 + .pass = &kernexec_retaddr_pass.pass,
81853 + .reference_pass_name = "pro_and_epilogue",
81854 + .ref_pass_instance_number = 0,
81855 + .pos_op = PASS_POS_INSERT_AFTER
81856 + };
81857 +
81858 + if (!plugin_default_version_check(version, &gcc_version)) {
81859 + error(G_("incompatible gcc/plugin versions"));
81860 + return 1;
81861 + }
81862 +
81863 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
81864 +
81865 + if (TARGET_64BIT == 0)
81866 + return 0;
81867 +
81868 + for (i = 0; i < argc; ++i) {
81869 + if (!strcmp(argv[i].key, "method")) {
81870 + if (!argv[i].value) {
81871 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81872 + continue;
81873 + }
81874 + if (!strcmp(argv[i].value, "bts")) {
81875 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
81876 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
81877 + } else if (!strcmp(argv[i].value, "or")) {
81878 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
81879 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
81880 + fix_register("r10", 1, 1);
81881 + } else
81882 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
81883 + continue;
81884 + }
81885 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81886 + }
81887 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
81888 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
81889 +
81890 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
81891 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
81892 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
81893 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
81894 +
81895 + return 0;
81896 +}
81897 diff --git a/tools/gcc/size_overflow_hash1.h b/tools/gcc/size_overflow_hash1.h
81898 new file mode 100644
81899 index 0000000..16ccac1
81900 --- /dev/null
81901 +++ b/tools/gcc/size_overflow_hash1.h
81902 @@ -0,0 +1,3047 @@
81903 +struct size_overflow_hash size_overflow_hash1[65536] = {
81904 + [10013].file = "security/smack/smackfs.c",
81905 + [10013].name = "smk_write_direct",
81906 + [10013].param3 = 1,
81907 + [10167].file = "sound/core/oss/pcm_plugin.c",
81908 + [10167].name = "snd_pcm_plugin_build",
81909 + [10167].param5 = 1,
81910 + [1020].file = "drivers/usb/misc/usbtest.c",
81911 + [1020].name = "test_unaligned_bulk",
81912 + [1020].param3 = 1,
81913 + [1022].file = "sound/pci/rme9652/rme9652.c",
81914 + [1022].name = "snd_rme9652_playback_copy",
81915 + [1022].param5 = 1,
81916 + [10321].file = "drivers/platform/x86/thinkpad_acpi.c",
81917 + [10321].name = "create_attr_set",
81918 + [10321].param1 = 1,
81919 + [10341].file = "fs/nfsd/nfs4xdr.c",
81920 + [10341].name = "read_buf",
81921 + [10341].param2 = 1,
81922 + [10357].file = "net/sunrpc/cache.c",
81923 + [10357].name = "cache_read",
81924 + [10357].param3 = 1,
81925 + [10397].file = "drivers/gpu/drm/i915/i915_debugfs.c",
81926 + [10397].name = "i915_wedged_write",
81927 + [10397].param3 = 1,
81928 + [10399].file = "kernel/trace/trace.c",
81929 + [10399].name = "trace_seq_to_user",
81930 + [10399].param3 = 1,
81931 + [10414].file = "drivers/tty/vt/vt.c",
81932 + [10414].name = "vc_do_resize",
81933 + [10414].param3 = 1,
81934 + [10414].param4 = 1,
81935 + [10565].file = "drivers/input/touchscreen/ad7879-spi.c",
81936 + [10565].name = "ad7879_spi_multi_read",
81937 + [10565].param3 = 1,
81938 + [10623].file = "drivers/infiniband/core/user_mad.c",
81939 + [10623].name = "ib_umad_write",
81940 + [10623].param3 = 1,
81941 + [10707].file = "fs/nfs/idmap.c",
81942 + [10707].name = "nfs_idmap_request_key",
81943 + [10707].param2 = 1,
81944 + [1073].file = "drivers/block/aoe/aoecmd.c",
81945 + [1073].name = "addtgt",
81946 + [1073].param3 = 1,
81947 + [10745].file = "fs/cifs/connect.c",
81948 + [10745].name = "get_server_iovec",
81949 + [10745].param2 = 1,
81950 + [10750].file = "drivers/net/wireless/iwmc3200wifi/rx.c",
81951 + [10750].name = "iwm_ntf_calib_res",
81952 + [10750].param3 = 1,
81953 + [10773].file = "drivers/input/mousedev.c",
81954 + [10773].name = "mousedev_read",
81955 + [10773].param3 = 1,
81956 + [10777].file = "fs/ntfs/file.c",
81957 + [10777].name = "ntfs_file_buffered_write",
81958 + [10777].param6 = 1,
81959 + [10893].file = "drivers/misc/sgi-gru/gruprocfs.c",
81960 + [10893].name = "options_write",
81961 + [10893].param3 = 1,
81962 + [10919].file = "net/ipv4/netfilter/arp_tables.c",
81963 + [10919].name = "do_arpt_set_ctl",
81964 + [10919].param4 = 1,
81965 + [1107].file = "mm/process_vm_access.c",
81966 + [1107].name = "process_vm_rw_single_vec",
81967 + [1107].param1 = 1,
81968 + [1107].param2 = 1,
81969 + [11230].file = "net/core/neighbour.c",
81970 + [11230].name = "neigh_hash_grow",
81971 + [11230].param2 = 1,
81972 + [11364].file = "fs/ext4/super.c",
81973 + [11364].name = "ext4_kvzalloc",
81974 + [11364].param1 = 1,
81975 + [114].file = "security/selinux/selinuxfs.c",
81976 + [114].name = "sel_write_relabel",
81977 + [114].param3 = 1,
81978 + [11549].file = "drivers/media/rc/redrat3.c",
81979 + [11549].name = "redrat3_transmit_ir",
81980 + [11549].param3 = 1,
81981 + [11568].file = "drivers/gpu/drm/drm_scatter.c",
81982 + [11568].name = "drm_vmalloc_dma",
81983 + [11568].param1 = 1,
81984 + [11582].file = "drivers/scsi/lpfc/lpfc_sli.c",
81985 + [11582].name = "lpfc_sli4_queue_alloc",
81986 + [11582].param3 = 1,
81987 + [11616].file = "security/selinux/selinuxfs.c",
81988 + [11616].name = "sel_write_enforce",
81989 + [11616].param3 = 1,
81990 + [11699].file = "drivers/net/ethernet/neterion/vxge/vxge-config.h",
81991 + [11699].name = "vxge_os_dma_malloc",
81992 + [11699].param2 = 1,
81993 + [11766].file = "drivers/block/paride/pt.c",
81994 + [11766].name = "pt_read",
81995 + [11766].param3 = 1,
81996 + [11784].file = "fs/bio.c",
81997 + [11784].name = "bio_kmalloc",
81998 + [11784].param2 = 1,
81999 + [11919].file = "drivers/lguest/core.c",
82000 + [11919].name = "__lgread",
82001 + [11919].param4 = 1,
82002 + [11925].file = "drivers/media/video/cx18/cx18-fileops.c",
82003 + [11925].name = "cx18_copy_mdl_to_user",
82004 + [11925].param4 = 1,
82005 + [11985].file = "drivers/block/floppy.c",
82006 + [11985].name = "fd_copyin",
82007 + [11985].param3 = 1,
82008 + [11986].file = "drivers/net/usb/asix.c",
82009 + [11986].name = "asix_read_cmd",
82010 + [11986].param5 = 1,
82011 + [12018].file = "sound/core/oss/pcm_oss.c",
82012 + [12018].name = "snd_pcm_oss_read1",
82013 + [12018].param3 = 1,
82014 + [12059].file = "drivers/net/wireless/libertas/debugfs.c",
82015 + [12059].name = "lbs_debugfs_write",
82016 + [12059].param3 = 1,
82017 + [12151].file = "fs/compat.c",
82018 + [12151].name = "compat_rw_copy_check_uvector",
82019 + [12151].param3 = 1,
82020 + [12205].file = "fs/reiserfs/journal.c",
82021 + [12205].name = "reiserfs_allocate_list_bitmaps",
82022 + [12205].param3 = 1,
82023 + [12234].file = "include/acpi/platform/aclinux.h",
82024 + [12234].name = "acpi_os_allocate",
82025 + [12234].param1 = 1,
82026 + [1227].file = "lib/cpu_rmap.c",
82027 + [1227].name = "alloc_cpu_rmap",
82028 + [1227].param1 = 1,
82029 + [12395].file = "drivers/char/hw_random/core.c",
82030 + [12395].name = "rng_dev_read",
82031 + [12395].param3 = 1,
82032 + [12602].file = "net/sunrpc/cache.c",
82033 + [12602].name = "cache_downcall",
82034 + [12602].param3 = 1,
82035 + [12712].file = "drivers/net/wimax/i2400m/fw.c",
82036 + [12712].name = "i2400m_zrealloc_2x",
82037 + [12712].param3 = 1,
82038 + [12755].file = "sound/drivers/opl4/opl4_proc.c",
82039 + [12755].name = "snd_opl4_mem_proc_read",
82040 + [12755].param5 = 1,
82041 + [12833].file = "net/sctp/auth.c",
82042 + [12833].name = "sctp_auth_create_key",
82043 + [12833].param1 = 1,
82044 + [12840].file = "net/sctp/tsnmap.c",
82045 + [12840].name = "sctp_tsnmap_mark",
82046 + [12840].param2 = 1,
82047 + [12931].file = "drivers/hid/hid-roccat.c",
82048 + [12931].name = "roccat_read",
82049 + [12931].param3 = 1,
82050 + [12954].file = "fs/proc/base.c",
82051 + [12954].name = "oom_adjust_write",
82052 + [12954].param3 = 1,
82053 + [13103].file = "drivers/acpi/acpica/utobject.c",
82054 + [13103].name = "acpi_ut_create_string_object",
82055 + [13103].param1 = 1,
82056 + [13121].file = "net/ipv4/ip_sockglue.c",
82057 + [13121].name = "do_ip_setsockopt",
82058 + [13121].param5 = 1,
82059 + [1327].file = "net/netfilter/nfnetlink_log.c",
82060 + [1327].name = "nfulnl_alloc_skb",
82061 + [1327].param2 = 1,
82062 + [13337].file = "net/core/iovec.c",
82063 + [13337].name = "csum_partial_copy_fromiovecend",
82064 + [13337].param4 = 1,
82065 + [13339].file = "security/smack/smackfs.c",
82066 + [13339].name = "smk_write_netlbladdr",
82067 + [13339].param3 = 1,
82068 + [13342].file = "fs/jbd2/journal.c",
82069 + [13342].name = "jbd2_alloc",
82070 + [13342].param1 = 1,
82071 + [13384].file = "drivers/char/virtio_console.c",
82072 + [13384].name = "alloc_buf",
82073 + [13384].param1 = 1,
82074 + [13412].file = "fs/proc/base.c",
82075 + [13412].name = "oom_score_adj_write",
82076 + [13412].param3 = 1,
82077 + [13559].file = "drivers/media/video/ivtv/ivtv-fileops.c",
82078 + [13559].name = "ivtv_read",
82079 + [13559].param3 = 1,
82080 + [13618].file = "drivers/net/team/team.c",
82081 + [13618].name = "team_options_register",
82082 + [13618].param3 = 1,
82083 + [13659].file = "drivers/net/wan/hdlc.c",
82084 + [13659].name = "attach_hdlc_protocol",
82085 + [13659].param3 = 1,
82086 + [13708].file = "drivers/usb/misc/usbtest.c",
82087 + [13708].name = "simple_alloc_urb",
82088 + [13708].param3 = 1,
82089 + [13805].file = "drivers/misc/altera-stapl/altera-jtag.c",
82090 + [13805].name = "altera_swap_dr",
82091 + [13805].param2 = 1,
82092 + [13868].file = "fs/lockd/mon.c",
82093 + [13868].name = "nsm_create_handle",
82094 + [13868].param4 = 1,
82095 + [13924].file = "net/ipv4/netfilter/ip_tables.c",
82096 + [13924].name = "do_ipt_set_ctl",
82097 + [13924].param4 = 1,
82098 + [14019].file = "net/dns_resolver/dns_key.c",
82099 + [14019].name = "dns_resolver_instantiate",
82100 + [14019].param2 = 1,
82101 + [14019].param3 = 1,
82102 + [14025].file = "net/ax25/af_ax25.c",
82103 + [14025].name = "ax25_setsockopt",
82104 + [14025].param5 = 1,
82105 + [14029].file = "drivers/spi/spidev.c",
82106 + [14029].name = "spidev_compat_ioctl",
82107 + [14029].param2 = 1,
82108 + [14090].file = "drivers/bluetooth/btmrvl_debugfs.c",
82109 + [14090].name = "btmrvl_hsmode_write",
82110 + [14090].param3 = 1,
82111 + [14149].file = "drivers/hid/hidraw.c",
82112 + [14149].name = "hidraw_ioctl",
82113 + [14149].param2 = 1,
82114 + [14153].file = "drivers/staging/bcm/led_control.c",
82115 + [14153].name = "ValidateDSDParamsChecksum",
82116 + [14153].param3 = 1,
82117 + [14174].file = "sound/pci/es1938.c",
82118 + [14174].name = "snd_es1938_capture_copy",
82119 + [14174].param5 = 1,
82120 + [14207].file = "drivers/media/video/v4l2-event.c",
82121 + [14207].name = "v4l2_event_subscribe",
82122 + [14207].param3 = 1,
82123 + [14241].file = "drivers/platform/x86/asus_acpi.c",
82124 + [14241].name = "brn_proc_write",
82125 + [14241].param3 = 1,
82126 + [14345].file = "fs/cachefiles/daemon.c",
82127 + [14345].name = "cachefiles_daemon_write",
82128 + [14345].param3 = 1,
82129 + [14347].file = "drivers/media/dvb/dvb-core/dvb_ca_en50221.c",
82130 + [14347].name = "dvb_ca_en50221_io_write",
82131 + [14347].param3 = 1,
82132 + [14566].file = "drivers/pci/hotplug/ibmphp_ebda.c",
82133 + [14566].name = "alloc_ebda_hpc",
82134 + [14566].param1 = 1,
82135 + [14566].param2 = 1,
82136 + [1458].file = "drivers/misc/lkdtm.c",
82137 + [1458].name = "direct_entry",
82138 + [1458].param3 = 1,
82139 + [14646].file = "fs/compat.c",
82140 + [14646].name = "compat_writev",
82141 + [14646].param3 = 1,
82142 + [14684].file = "drivers/media/video/stk-webcam.c",
82143 + [14684].name = "stk_allocate_buffers",
82144 + [14684].param2 = 1,
82145 + [14736].file = "drivers/usb/misc/usbtest.c",
82146 + [14736].name = "unlink_queued",
82147 + [14736].param3 = 1,
82148 + [1482].file = "drivers/scsi/scsi_netlink.c",
82149 + [1482].name = "scsi_nl_send_vendor_msg",
82150 + [1482].param5 = 1,
82151 + [15017].file = "drivers/edac/edac_device.c",
82152 + [15017].name = "edac_device_alloc_ctl_info",
82153 + [15017].param1 = 1,
82154 + [15044].file = "drivers/uio/uio.c",
82155 + [15044].name = "uio_write",
82156 + [15044].param3 = 1,
82157 + [15087].file = "fs/bio.c",
82158 + [15087].name = "bio_map_kern",
82159 + [15087].param2 = 1,
82160 + [15087].param3 = 1,
82161 + [15112].file = "drivers/xen/evtchn.c",
82162 + [15112].name = "evtchn_write",
82163 + [15112].param3 = 1,
82164 + [15130].file = "net/bluetooth/hci_core.c",
82165 + [15130].name = "hci_send_cmd",
82166 + [15130].param3 = 1,
82167 + [15202].file = "net/bluetooth/rfcomm/tty.c",
82168 + [15202].name = "rfcomm_wmalloc",
82169 + [15202].param2 = 1,
82170 + [15274].file = "crypto/shash.c",
82171 + [15274].name = "crypto_shash_setkey",
82172 + [15274].param3 = 1,
82173 + [15354].file = "drivers/isdn/mISDN/socket.c",
82174 + [15354].name = "mISDN_sock_sendmsg",
82175 + [15354].param4 = 1,
82176 + [15361].file = "drivers/char/agp/generic.c",
82177 + [15361].name = "agp_allocate_memory",
82178 + [15361].param2 = 1,
82179 + [15497].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
82180 + [15497].name = "ts_read",
82181 + [15497].param3 = 1,
82182 + [15551].file = "net/ipv4/netfilter/ipt_CLUSTERIP.c",
82183 + [15551].name = "clusterip_proc_write",
82184 + [15551].param3 = 1,
82185 + [15701].file = "drivers/hid/hid-roccat-common.c",
82186 + [15701].name = "roccat_common_receive",
82187 + [15701].param4 = 1,
82188 + [1572].file = "net/ceph/pagevec.c",
82189 + [1572].name = "ceph_copy_page_vector_to_user",
82190 + [1572].param4 = 1,
82191 + [15814].file = "net/mac80211/debugfs_netdev.c",
82192 + [15814].name = "ieee80211_if_write",
82193 + [15814].param3 = 1,
82194 + [15883].file = "security/keys/keyctl.c",
82195 + [15883].name = "sys_add_key",
82196 + [15883].param4 = 1,
82197 + [15884].file = "fs/exofs/super.c",
82198 + [15884].name = "exofs_read_lookup_dev_table",
82199 + [15884].param3 = 1,
82200 + [16037].file = "drivers/staging/media/easycap/easycap_sound.c",
82201 + [16037].name = "easycap_alsa_vmalloc",
82202 + [16037].param2 = 1,
82203 + [16073].file = "net/sctp/socket.c",
82204 + [16073].name = "sctp_setsockopt",
82205 + [16073].param5 = 1,
82206 + [16132].file = "drivers/staging/vme/devices/vme_user.c",
82207 + [16132].name = "buffer_from_user",
82208 + [16132].param3 = 1,
82209 + [16138].file = "security/selinux/ss/services.c",
82210 + [16138].name = "security_context_to_sid_force",
82211 + [16138].param2 = 1,
82212 + [16166].file = "drivers/platform/x86/thinkpad_acpi.c",
82213 + [16166].name = "dispatch_proc_write",
82214 + [16166].param3 = 1,
82215 + [16229].file = "drivers/scsi/scsi_transport_iscsi.c",
82216 + [16229].name = "iscsi_offload_mesg",
82217 + [16229].param5 = 1,
82218 + [16353].file = "drivers/base/regmap/regmap.c",
82219 + [16353].name = "regmap_raw_write",
82220 + [16353].param4 = 1,
82221 + [16383].file = "fs/proc/base.c",
82222 + [16383].name = "comm_write",
82223 + [16383].param3 = 1,
82224 + [16396].file = "drivers/misc/altera-stapl/altera-jtag.c",
82225 + [16396].name = "altera_irscan",
82226 + [16396].param2 = 1,
82227 + [16447].file = "drivers/hid/usbhid/hiddev.c",
82228 + [16447].name = "hiddev_ioctl",
82229 + [16447].param2 = 1,
82230 + [16453].file = "include/linux/slab.h",
82231 + [16453].name = "kzalloc",
82232 + [16453].param1 = 1,
82233 + [16605].file = "fs/ecryptfs/miscdev.c",
82234 + [16605].name = "ecryptfs_send_miscdev",
82235 + [16605].param2 = 1,
82236 + [16606].file = "drivers/ide/ide-tape.c",
82237 + [16606].name = "idetape_chrdev_write",
82238 + [16606].param3 = 1,
82239 + [16637].file = "security/keys/encrypted-keys/encrypted.c",
82240 + [16637].name = "datablob_hmac_verify",
82241 + [16637].param4 = 1,
82242 + [16828].file = "net/batman-adv/hash.c",
82243 + [16828].name = "hash_new",
82244 + [16828].param1 = 1,
82245 + [16853].file = "drivers/net/ethernet/chelsio/cxgb4vf/sge.c",
82246 + [16853].name = "t4vf_pktgl_to_skb",
82247 + [16853].param2 = 1,
82248 + [16911].file = "drivers/media/dvb/ttpci/av7110_hw.c",
82249 + [16911].name = "LoadBitmap",
82250 + [16911].param2 = 1,
82251 + [169].file = "drivers/net/ethernet/amd/pcnet32.c",
82252 + [169].name = "pcnet32_realloc_rx_ring",
82253 + [169].param3 = 1,
82254 + [17075].file = "sound/isa/gus/gus_dram.c",
82255 + [17075].name = "snd_gus_dram_write",
82256 + [17075].param4 = 1,
82257 + [17133].file = "drivers/usb/misc/iowarrior.c",
82258 + [17133].name = "iowarrior_read",
82259 + [17133].param3 = 1,
82260 + [17185].file = "net/wireless/scan.c",
82261 + [17185].name = "cfg80211_inform_bss",
82262 + [17185].param8 = 1,
82263 + [17349].file = "net/tipc/link.c",
82264 + [17349].name = "tipc_link_send_sections_fast",
82265 + [17349].param4 = 1,
82266 + [17377].file = "drivers/usb/class/cdc-wdm.c",
82267 + [17377].name = "wdm_write",
82268 + [17377].param3 = 1,
82269 + [17459].file = "drivers/usb/misc/rio500.c",
82270 + [17459].name = "write_rio",
82271 + [17459].param3 = 1,
82272 + [17460].file = "fs/nfsd/nfscache.c",
82273 + [17460].name = "nfsd_cache_update",
82274 + [17460].param3 = 1,
82275 + [17492].file = "net/dccp/proto.c",
82276 + [17492].name = "do_dccp_setsockopt",
82277 + [17492].param5 = 1,
82278 + [1754].file = "sound/core/oss/pcm_oss.c",
82279 + [1754].name = "snd_pcm_oss_write",
82280 + [1754].param3 = 1,
82281 + [17604].file = "fs/proc/generic.c",
82282 + [17604].name = "__proc_file_read",
82283 + [17604].param3 = 1,
82284 + [17718].file = "net/caif/caif_socket.c",
82285 + [17718].name = "setsockopt",
82286 + [17718].param5 = 1,
82287 + [17828].file = "kernel/sched/core.c",
82288 + [17828].name = "sched_feat_write",
82289 + [17828].param3 = 1,
82290 + [17841].file = "drivers/misc/tifm_core.c",
82291 + [17841].name = "tifm_alloc_adapter",
82292 + [17841].param1 = 1,
82293 + [17946].file = "drivers/net/wireless/libertas/if_spi.c",
82294 + [17946].name = "if_spi_host_to_card",
82295 + [17946].param4 = 1,
82296 + [1800].file = "drivers/media/dvb/dvb-core/dmxdev.c",
82297 + [1800].name = "dvb_dvr_do_ioctl",
82298 + [1800].param3 = 1,
82299 + [18119].file = "drivers/misc/iwmc3200top/fw-download.c",
82300 + [18119].name = "iwmct_fw_parser_init",
82301 + [18119].param4 = 1,
82302 + [18140].file = "drivers/scsi/pm8001/pm8001_ctl.c",
82303 + [18140].name = "pm8001_store_update_fw",
82304 + [18140].param4 = 1,
82305 + [18191].file = "sound/pci/hda/patch_realtek.c",
82306 + [18191].name = "new_bind_ctl",
82307 + [18191].param2 = 1,
82308 + [18224].file = "drivers/xen/grant-table.c",
82309 + [18224].name = "gnttab_map",
82310 + [18224].param2 = 1,
82311 + [18232].file = "fs/nfs/write.c",
82312 + [18232].name = "nfs_writedata_alloc",
82313 + [18232].param1 = 1,
82314 + [18247].file = "drivers/char/agp/generic.c",
82315 + [18247].name = "agp_create_user_memory",
82316 + [18247].param1 = 1,
82317 + [18303].file = "fs/xattr.c",
82318 + [18303].name = "getxattr",
82319 + [18303].param4 = 1,
82320 + [18353].file = "net/rfkill/core.c",
82321 + [18353].name = "rfkill_fop_read",
82322 + [18353].param3 = 1,
82323 + [18386].file = "fs/read_write.c",
82324 + [18386].name = "vfs_readv",
82325 + [18386].param3 = 1,
82326 + [18391].file = "fs/ocfs2/stack_user.c",
82327 + [18391].name = "ocfs2_control_write",
82328 + [18391].param3 = 1,
82329 + [183].file = "crypto/ahash.c",
82330 + [183].name = "crypto_ahash_setkey",
82331 + [183].param3 = 1,
82332 + [18406].file = "drivers/media/video/tm6000/tm6000-core.c",
82333 + [18406].name = "tm6000_read_write_usb",
82334 + [18406].param7 = 1,
82335 + [1845].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
82336 + [1845].name = "rt2x00debug_write_rf",
82337 + [1845].param3 = 1,
82338 + [18465].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
82339 + [18465].name = "cxgb_alloc_mem",
82340 + [18465].param1 = 1,
82341 + [184].file = "drivers/firewire/nosy.c",
82342 + [184].name = "packet_buffer_init",
82343 + [184].param2 = 1,
82344 + [1858].file = "net/ipv6/netfilter/ip6_tables.c",
82345 + [1858].name = "do_ip6t_set_ctl",
82346 + [1858].param4 = 1,
82347 + [18659].file = "drivers/media/dvb/dvb-core/dvbdev.c",
82348 + [18659].name = "dvb_usercopy",
82349 + [18659].param2 = 1,
82350 + [18722].file = "security/tomoyo/condition.c",
82351 + [18722].name = "tomoyo_scan_bprm",
82352 + [18722].param2 = 1,
82353 + [18722].param4 = 1,
82354 + [18775].file = "include/linux/textsearch.h",
82355 + [18775].name = "alloc_ts_config",
82356 + [18775].param1 = 1,
82357 + [18940].file = "drivers/usb/host/hwa-hc.c",
82358 + [18940].name = "__hwahc_op_set_gtk",
82359 + [18940].param4 = 1,
82360 + [19012].file = "drivers/acpi/event.c",
82361 + [19012].name = "acpi_system_read_event",
82362 + [19012].param3 = 1,
82363 + [19028].file = "mm/filemap.c",
82364 + [19028].name = "iov_iter_copy_from_user_atomic",
82365 + [19028].param4 = 1,
82366 + [19107].file = "security/smack/smackfs.c",
82367 + [19107].name = "smk_write_load_list",
82368 + [19107].param3 = 1,
82369 + [19240].file = "net/sctp/socket.c",
82370 + [19240].name = "sctp_setsockopt_delayed_ack",
82371 + [19240].param3 = 1,
82372 + [19274].file = "net/core/pktgen.c",
82373 + [19274].name = "pktgen_if_write",
82374 + [19274].param3 = 1,
82375 + [19286].file = "drivers/base/regmap/regmap.c",
82376 + [19286].name = "_regmap_raw_write",
82377 + [19286].param4 = 1,
82378 + [19308].file = "drivers/char/mem.c",
82379 + [19308].name = "read_oldmem",
82380 + [19308].param3 = 1,
82381 + [19343].file = "security/keys/encrypted-keys/encrypted.c",
82382 + [19343].name = "datablob_hmac_append",
82383 + [19343].param3 = 1,
82384 + [19349].file = "drivers/acpi/acpica/utobject.c",
82385 + [19349].name = "acpi_ut_create_package_object",
82386 + [19349].param1 = 1,
82387 + [19453].file = "drivers/net/ethernet/chelsio/cxgb/sge.c",
82388 + [19453].name = "sge_rx",
82389 + [19453].param3 = 1,
82390 + [19504].file = "drivers/usb/serial/garmin_gps.c",
82391 + [19504].name = "pkt_add",
82392 + [19504].param3 = 1,
82393 + [19522].file = "mm/percpu.c",
82394 + [19522].name = "pcpu_mem_zalloc",
82395 + [19522].param1 = 1,
82396 + [19548].file = "drivers/scsi/qla2xxx/qla_init.c",
82397 + [19548].name = "qla2x00_get_ctx_sp",
82398 + [19548].param3 = 1,
82399 + [19592].file = "net/dccp/proto.c",
82400 + [19592].name = "dccp_setsockopt_service",
82401 + [19592].param4 = 1,
82402 + [19726].file = "kernel/trace/trace.c",
82403 + [19726].name = "tracing_set_trace_write",
82404 + [19726].param3 = 1,
82405 + [19738].file = "fs/sysfs/file.c",
82406 + [19738].name = "sysfs_write_file",
82407 + [19738].param3 = 1,
82408 + [19833].file = "drivers/xen/privcmd.c",
82409 + [19833].name = "gather_array",
82410 + [19833].param3 = 1,
82411 + [19910].file = "drivers/media/video/saa7164/saa7164-buffer.c",
82412 + [19910].name = "saa7164_buffer_alloc_user",
82413 + [19910].param2 = 1,
82414 + [19920].file = "drivers/input/joydev.c",
82415 + [19920].name = "joydev_ioctl",
82416 + [19920].param2 = 1,
82417 + [19931].file = "drivers/usb/misc/ftdi-elan.c",
82418 + [19931].name = "ftdi_elan_write",
82419 + [19931].param3 = 1,
82420 + [19960].file = "drivers/usb/class/usblp.c",
82421 + [19960].name = "usblp_read",
82422 + [19960].param3 = 1,
82423 + [1996].file = "drivers/scsi/libsrp.c",
82424 + [1996].name = "srp_target_alloc",
82425 + [1996].param3 = 1,
82426 + [20023].file = "drivers/media/video/gspca/gspca.c",
82427 + [20023].name = "dev_read",
82428 + [20023].param3 = 1,
82429 + [20207].file = "net/core/sock.c",
82430 + [20207].name = "sock_alloc_send_pskb",
82431 + [20207].param2 = 1,
82432 + [20263].file = "kernel/trace/trace_events.c",
82433 + [20263].name = "event_filter_write",
82434 + [20263].param3 = 1,
82435 + [20314].file = "drivers/gpu/drm/drm_hashtab.c",
82436 + [20314].name = "drm_ht_create",
82437 + [20314].param2 = 1,
82438 + [20320].file = "drivers/mfd/sm501.c",
82439 + [20320].name = "sm501_create_subdev",
82440 + [20320].param3 = 1,
82441 + [20320].param4 = 1,
82442 + [20376].file = "mm/nobootmem.c",
82443 + [20376].name = "__alloc_bootmem_nopanic",
82444 + [20376].param1 = 1,
82445 + [20409].file = "drivers/media/dvb/dvb-usb/opera1.c",
82446 + [20409].name = "opera1_usb_i2c_msgxfer",
82447 + [20409].param4 = 1,
82448 + [20473].file = "drivers/mtd/mtdchar.c",
82449 + [20473].name = "mtdchar_write",
82450 + [20473].param3 = 1,
82451 + [20611].file = "net/netfilter/x_tables.c",
82452 + [20611].name = "xt_alloc_table_info",
82453 + [20611].param1 = 1,
82454 + [20618].file = "drivers/staging/crystalhd/crystalhd_lnx.c",
82455 + [20618].name = "chd_dec_fetch_cdata",
82456 + [20618].param3 = 1,
82457 + [20713].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
82458 + [20713].name = "ttm_bo_io",
82459 + [20713].param5 = 1,
82460 + [20801].file = "drivers/vhost/vhost.c",
82461 + [20801].name = "vhost_add_used_n",
82462 + [20801].param3 = 1,
82463 + [20835].file = "drivers/isdn/i4l/isdn_common.c",
82464 + [20835].name = "isdn_read",
82465 + [20835].param3 = 1,
82466 + [20951].file = "crypto/rng.c",
82467 + [20951].name = "rngapi_reset",
82468 + [20951].param3 = 1,
82469 + [21125].file = "fs/gfs2/dir.c",
82470 + [21125].name = "gfs2_alloc_sort_buffer",
82471 + [21125].param1 = 1,
82472 + [21132].file = "kernel/cgroup.c",
82473 + [21132].name = "cgroup_write_X64",
82474 + [21132].param5 = 1,
82475 + [21138].file = "drivers/uio/uio.c",
82476 + [21138].name = "uio_read",
82477 + [21138].param3 = 1,
82478 + [21193].file = "net/wireless/sme.c",
82479 + [21193].name = "cfg80211_disconnected",
82480 + [21193].param4 = 1,
82481 + [21312].file = "lib/ts_kmp.c",
82482 + [21312].name = "kmp_init",
82483 + [21312].param2 = 1,
82484 + [21335].file = "net/econet/af_econet.c",
82485 + [21335].name = "econet_sendmsg",
82486 + [21335].param4 = 1,
82487 + [21406].file = "fs/libfs.c",
82488 + [21406].name = "simple_write_to_buffer",
82489 + [21406].param2 = 1,
82490 + [21406].param5 = 1,
82491 + [21451].file = "net/netfilter/ipvs/ip_vs_ctl.c",
82492 + [21451].name = "do_ip_vs_set_ctl",
82493 + [21451].param4 = 1,
82494 + [21459].file = "security/smack/smackfs.c",
82495 + [21459].name = "smk_write_doi",
82496 + [21459].param3 = 1,
82497 + [21508].file = "include/linux/usb/wusb.h",
82498 + [21508].name = "wusb_prf_64",
82499 + [21508].param7 = 1,
82500 + [21511].file = "drivers/input/ff-core.c",
82501 + [21511].name = "input_ff_create",
82502 + [21511].param2 = 1,
82503 + [21538].file = "net/bluetooth/l2cap_sock.c",
82504 + [21538].name = "l2cap_sock_setsockopt",
82505 + [21538].param5 = 1,
82506 + [21543].file = "drivers/media/video/gspca/gspca.c",
82507 + [21543].name = "frame_alloc",
82508 + [21543].param4 = 1,
82509 + [21608].file = "drivers/char/tpm/tpm.c",
82510 + [21608].name = "tpm_write",
82511 + [21608].param3 = 1,
82512 + [2160].file = "drivers/net/wireless/ray_cs.c",
82513 + [2160].name = "int_proc_write",
82514 + [2160].param3 = 1,
82515 + [21632].file = "fs/afs/cell.c",
82516 + [21632].name = "afs_cell_create",
82517 + [21632].param2 = 1,
82518 + [21679].file = "drivers/net/wireless/ath/carl9170/debug.c",
82519 + [21679].name = "carl9170_debugfs_write",
82520 + [21679].param3 = 1,
82521 + [21784].file = "crypto/ahash.c",
82522 + [21784].name = "ahash_setkey_unaligned",
82523 + [21784].param3 = 1,
82524 + [2180].file = "drivers/char/ppdev.c",
82525 + [2180].name = "pp_write",
82526 + [2180].param3 = 1,
82527 + [21810].file = "net/core/netprio_cgroup.c",
82528 + [21810].name = "extend_netdev_table",
82529 + [21810].param2 = 1,
82530 + [21906].file = "net/atm/mpc.c",
82531 + [21906].name = "copy_macs",
82532 + [21906].param4 = 1,
82533 + [21946].file = "fs/nfs/idmap.c",
82534 + [21946].name = "nfs_map_name_to_uid",
82535 + [21946].param3 = 1,
82536 + [22052].file = "drivers/net/ethernet/chelsio/cxgb3/sge.c",
82537 + [22052].name = "get_packet_pg",
82538 + [22052].param4 = 1,
82539 + [22085].file = "drivers/staging/sep/sep_driver.c",
82540 + [22085].name = "sep_lock_user_pages",
82541 + [22085].param2 = 1,
82542 + [22085].param3 = 1,
82543 + [22190].file = "drivers/char/tpm/tpm.c",
82544 + [22190].name = "tpm_read",
82545 + [22190].param3 = 1,
82546 + [22291].file = "net/core/pktgen.c",
82547 + [22291].name = "pgctrl_write",
82548 + [22291].param3 = 1,
82549 + [22439].file = "fs/afs/rxrpc.c",
82550 + [22439].name = "afs_alloc_flat_call",
82551 + [22439].param2 = 1,
82552 + [22439].param3 = 1,
82553 + [2243].file = "drivers/scsi/scsi_tgt_lib.c",
82554 + [2243].name = "scsi_tgt_kspace_exec",
82555 + [2243].param8 = 1,
82556 + [22440].file = "drivers/uwb/neh.c",
82557 + [22440].name = "uwb_rc_neh_grok_event",
82558 + [22440].param3 = 1,
82559 + [22611].file = "drivers/staging/android/logger.c",
82560 + [22611].name = "do_write_log_from_user",
82561 + [22611].param3 = 1,
82562 + [22614].file = "drivers/media/video/cx18/cx18-fileops.c",
82563 + [22614].name = "cx18_copy_buf_to_user",
82564 + [22614].param4 = 1,
82565 + [22667].file = "drivers/misc/altera-stapl/altera-jtag.c",
82566 + [22667].name = "altera_set_ir_post",
82567 + [22667].param2 = 1,
82568 + [22772].file = "drivers/target/iscsi/iscsi_target_erl1.c",
82569 + [22772].name = "iscsit_dump_data_payload",
82570 + [22772].param2 = 1,
82571 + [22777].file = "drivers/infiniband/ulp/srp/ib_srp.c",
82572 + [22777].name = "srp_alloc_iu",
82573 + [22777].param2 = 1,
82574 + [22811].file = "drivers/usb/dwc3/debugfs.c",
82575 + [22811].name = "dwc3_mode_write",
82576 + [22811].param3 = 1,
82577 + [22817].file = "drivers/media/video/usbvision/usbvision-core.c",
82578 + [22817].name = "usbvision_rvmalloc",
82579 + [22817].param1 = 1,
82580 + [22864].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82581 + [22864].name = "ath6kl_add_bss_if_needed",
82582 + [22864].param6 = 1,
82583 + [2286].file = "drivers/scsi/mvumi.c",
82584 + [2286].name = "mvumi_alloc_mem_resource",
82585 + [2286].param3 = 1,
82586 + [22904].file = "security/selinux/ss/services.c",
82587 + [22904].name = "security_context_to_sid_default",
82588 + [22904].param2 = 1,
82589 + [22932].file = "fs/compat.c",
82590 + [22932].name = "compat_sys_writev",
82591 + [22932].param3 = 1,
82592 + [2302].file = "drivers/media/video/stk-webcam.c",
82593 + [2302].name = "v4l_stk_read",
82594 + [2302].param3 = 1,
82595 + [2307].file = "drivers/pcmcia/cistpl.c",
82596 + [2307].name = "pcmcia_replace_cis",
82597 + [2307].param3 = 1,
82598 + [23117].file = "drivers/media/dvb/ttpci/av7110_av.c",
82599 + [23117].name = "dvb_audio_write",
82600 + [23117].param3 = 1,
82601 + [23220].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
82602 + [23220].name = "do_dmabuf_dirty_sou",
82603 + [23220].param7 = 1,
82604 + [23232].file = "drivers/md/persistent-data/dm-space-map-checker.c",
82605 + [23232].name = "sm_checker_extend",
82606 + [23232].param2 = 1,
82607 + [2324].file = "net/ieee802154/wpan-class.c",
82608 + [2324].name = "wpan_phy_alloc",
82609 + [2324].param1 = 1,
82610 + [2328].file = "kernel/trace/ftrace.c",
82611 + [2328].name = "ftrace_pid_write",
82612 + [2328].param3 = 1,
82613 + [23290].file = "fs/proc/base.c",
82614 + [23290].name = "mem_rw",
82615 + [23290].param3 = 1,
82616 + [23449].file = "crypto/blkcipher.c",
82617 + [23449].name = "blkcipher_next_slow",
82618 + [23449].param3 = 1,
82619 + [23449].param4 = 1,
82620 + [23535].file = "ipc/sem.c",
82621 + [23535].name = "sys_semtimedop",
82622 + [23535].param3 = 1,
82623 + [2357].file = "drivers/usb/serial/garmin_gps.c",
82624 + [2357].name = "garmin_read_process",
82625 + [2357].param3 = 1,
82626 + [23589].file = "kernel/relay.c",
82627 + [23589].name = "subbuf_read_actor",
82628 + [23589].param3 = 1,
82629 + [23848].file = "crypto/blkcipher.c",
82630 + [23848].name = "async_setkey",
82631 + [23848].param3 = 1,
82632 + [2386].file = "drivers/acpi/acpica/exnames.c",
82633 + [2386].name = "acpi_ex_allocate_name_string",
82634 + [2386].param2 = 1,
82635 + [2389].file = "net/core/sock.c",
82636 + [2389].name = "sock_rmalloc",
82637 + [2389].param2 = 1,
82638 + [23994].file = "net/bluetooth/mgmt.c",
82639 + [23994].name = "set_powered",
82640 + [23994].param4 = 1,
82641 + [23999].file = "sound/pci/rme9652/hdsp.c",
82642 + [23999].name = "snd_hdsp_capture_copy",
82643 + [23999].param5 = 1,
82644 + [24233].file = "drivers/pci/pcie/aer/aer_inject.c",
82645 + [24233].name = "aer_inject_write",
82646 + [24233].param3 = 1,
82647 + [24359].file = "kernel/power/qos.c",
82648 + [24359].name = "pm_qos_power_write",
82649 + [24359].param3 = 1,
82650 + [24457].file = "fs/btrfs/backref.c",
82651 + [24457].name = "init_data_container",
82652 + [24457].param1 = 1,
82653 + [24719].file = "drivers/input/evdev.c",
82654 + [24719].name = "bits_to_user",
82655 + [24719].param3 = 1,
82656 + [2472].file = "net/ipv4/netfilter/ip_tables.c",
82657 + [2472].name = "compat_do_ipt_set_ctl",
82658 + [2472].param4 = 1,
82659 + [24755].file = "drivers/infiniband/hw/qib/qib_diag.c",
82660 + [24755].name = "qib_diag_write",
82661 + [24755].param3 = 1,
82662 + [24805].file = "security/keys/user_defined.c",
82663 + [24805].name = "user_update",
82664 + [24805].param3 = 1,
82665 + [25036].file = "fs/pipe.c",
82666 + [25036].name = "pipe_iov_copy_from_user",
82667 + [25036].param3 = 1,
82668 + [25078].file = "drivers/net/wireless/p54/fwio.c",
82669 + [25078].name = "p54_download_eeprom",
82670 + [25078].param4 = 1,
82671 + [25127].file = "drivers/scsi/device_handler/scsi_dh_alua.c",
82672 + [25127].name = "realloc_buffer",
82673 + [25127].param2 = 1,
82674 + [25145].file = "net/tipc/link.c",
82675 + [25145].name = "link_send_sections_long",
82676 + [25145].param4 = 1,
82677 + [25157].file = "security/keys/request_key_auth.c",
82678 + [25157].name = "request_key_auth_new",
82679 + [25157].param3 = 1,
82680 + [25158].file = "drivers/net/ethernet/mellanox/mlx4/en_rx.c",
82681 + [25158].name = "mlx4_en_create_rx_ring",
82682 + [25158].param3 = 1,
82683 + [25267].file = "fs/configfs/file.c",
82684 + [25267].name = "configfs_write_file",
82685 + [25267].param3 = 1,
82686 + [25495].file = "drivers/scsi/bfa/bfad_debugfs.c",
82687 + [25495].name = "bfad_debugfs_write_regwr",
82688 + [25495].param3 = 1,
82689 + [25558].file = "fs/proc/task_mmu.c",
82690 + [25558].name = "clear_refs_write",
82691 + [25558].param3 = 1,
82692 + [25692].file = "drivers/net/wireless/ath/ath6kl/wmi.c",
82693 + [25692].name = "ath6kl_wmi_send_action_cmd",
82694 + [25692].param7 = 1,
82695 + [25765].file = "drivers/media/dvb/b2c2/flexcop.c",
82696 + [25765].name = "flexcop_device_kmalloc",
82697 + [25765].param1 = 1,
82698 + [26100].file = "sound/core/info.c",
82699 + [26100].name = "snd_info_entry_write",
82700 + [26100].param3 = 1,
82701 + [26256].file = "fs/hpfs/name.c",
82702 + [26256].name = "hpfs_translate_name",
82703 + [26256].param3 = 1,
82704 + [26394].file = "drivers/hid/hidraw.c",
82705 + [26394].name = "hidraw_get_report",
82706 + [26394].param3 = 1,
82707 + [26494].file = "kernel/signal.c",
82708 + [26494].name = "sys_rt_sigpending",
82709 + [26494].param2 = 1,
82710 + [26497].file = "security/keys/keyctl.c",
82711 + [26497].name = "sys_keyctl",
82712 + [26497].param4 = 1,
82713 + [26533].file = "drivers/block/aoe/aoechr.c",
82714 + [26533].name = "aoechr_write",
82715 + [26533].param3 = 1,
82716 + [26560].file = "crypto/algapi.c",
82717 + [26560].name = "crypto_alloc_instance2",
82718 + [26560].param3 = 1,
82719 + [26605].file = "security/selinux/selinuxfs.c",
82720 + [26605].name = "sel_write_user",
82721 + [26605].param3 = 1,
82722 + [26620].file = "net/bluetooth/mgmt.c",
82723 + [26620].name = "mgmt_control",
82724 + [26620].param3 = 1,
82725 + [26701].file = "drivers/mtd/chips/cfi_util.c",
82726 + [26701].name = "cfi_read_pri",
82727 + [26701].param3 = 1,
82728 + [26757].file = "fs/xattr.c",
82729 + [26757].name = "sys_fgetxattr",
82730 + [26757].param4 = 1,
82731 + [2678].file = "drivers/platform/x86/asus_acpi.c",
82732 + [2678].name = "disp_proc_write",
82733 + [2678].param3 = 1,
82734 + [26834].file = "drivers/gpu/drm/drm_drv.c",
82735 + [26834].name = "drm_ioctl",
82736 + [26834].param2 = 1,
82737 + [26843].file = "drivers/firewire/core-cdev.c",
82738 + [26843].name = "fw_device_op_compat_ioctl",
82739 + [26843].param2 = 1,
82740 + [26845].file = "drivers/scsi/qla2xxx/qla_bsg.c",
82741 + [26845].name = "qla2x00_get_ctx_bsg_sp",
82742 + [26845].param3 = 1,
82743 + [26888].file = "net/bridge/br_ioctl.c",
82744 + [26888].name = "get_fdb_entries",
82745 + [26888].param3 = 1,
82746 + [26962].file = "drivers/usb/class/usbtmc.c",
82747 + [26962].name = "usbtmc_write",
82748 + [26962].param3 = 1,
82749 + [26966].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
82750 + [26966].name = "ts_write",
82751 + [26966].param3 = 1,
82752 + [27004].file = "drivers/misc/hpilo.c",
82753 + [27004].name = "ilo_write",
82754 + [27004].param3 = 1,
82755 + [27025].file = "fs/ntfs/file.c",
82756 + [27025].name = "__ntfs_copy_from_user_iovec_inatomic",
82757 + [27025].param3 = 1,
82758 + [27025].param4 = 1,
82759 + [27061].file = "drivers/firewire/core-cdev.c",
82760 + [27061].name = "iso_callback",
82761 + [27061].param3 = 1,
82762 + [2711].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
82763 + [2711].name = "dvb_ringbuffer_read_user",
82764 + [2711].param3 = 1,
82765 + [27129].file = "fs/lockd/mon.c",
82766 + [27129].name = "nsm_get_handle",
82767 + [27129].param4 = 1,
82768 + [27142].file = "fs/proc/kcore.c",
82769 + [27142].name = "read_kcore",
82770 + [27142].param3 = 1,
82771 + [27164].file = "include/drm/drm_mem_util.h",
82772 + [27164].name = "drm_calloc_large",
82773 + [27164].param1 = 1,
82774 + [27164].param2 = 1,
82775 + [27176].file = "drivers/mtd/devices/mtd_dataflash.c",
82776 + [27176].name = "otp_read",
82777 + [27176].param2 = 1,
82778 + [27176].param5 = 1,
82779 + [27232].file = "security/apparmor/lib.c",
82780 + [27232].name = "kvmalloc",
82781 + [27232].param1 = 1,
82782 + [27275].file = "drivers/scsi/cxgbi/libcxgbi.c",
82783 + [27275].name = "cxgbi_ddp_reserve",
82784 + [27275].param4 = 1,
82785 + [27280].file = "drivers/net/ethernet/mellanox/mlx4/en_tx.c",
82786 + [27280].name = "mlx4_en_create_tx_ring",
82787 + [27280].param4 = 1,
82788 + [27290].file = "security/selinux/ss/services.c",
82789 + [27290].name = "security_context_to_sid_core",
82790 + [27290].param2 = 1,
82791 + [27302].file = "fs/proc/base.c",
82792 + [27302].name = "proc_loginuid_write",
82793 + [27302].param3 = 1,
82794 + [2730].file = "drivers/target/iscsi/iscsi_target_parameters.c",
82795 + [2730].name = "iscsi_decode_text_input",
82796 + [2730].param4 = 1,
82797 + [27314].file = "net/bluetooth/mgmt.c",
82798 + [27314].name = "cmd_complete",
82799 + [27314].param5 = 1,
82800 + [27472].file = "security/selinux/selinuxfs.c",
82801 + [27472].name = "sel_write_load",
82802 + [27472].param3 = 1,
82803 + [27491].file = "fs/proc/base.c",
82804 + [27491].name = "proc_pid_attr_write",
82805 + [27491].param3 = 1,
82806 + [27568].file = "drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c",
82807 + [27568].name = "t4_alloc_mem",
82808 + [27568].param1 = 1,
82809 + [27582].file = "drivers/platform/x86/asus_acpi.c",
82810 + [27582].name = "ledd_proc_write",
82811 + [27582].param3 = 1,
82812 + [27595].file = "net/core/sock.c",
82813 + [27595].name = "sock_alloc_send_skb",
82814 + [27595].param2 = 1,
82815 + [27648].file = "net/bluetooth/l2cap_core.c",
82816 + [27648].name = "l2cap_bredr_sig_cmd",
82817 + [27648].param3 = 1,
82818 + [27697].file = "drivers/staging/mei/iorw.c",
82819 + [27697].name = "amthi_read",
82820 + [27697].param4 = 1,
82821 + [27911].file = "fs/ext4/resize.c",
82822 + [27911].name = "alloc_flex_gd",
82823 + [27911].param1 = 1,
82824 + [27927].file = "drivers/tty/tty_io.c",
82825 + [27927].name = "redirected_tty_write",
82826 + [27927].param3 = 1,
82827 + [28040].file = "kernel/kfifo.c",
82828 + [28040].name = "__kfifo_alloc",
82829 + [28040].param2 = 1,
82830 + [28040].param3 = 1,
82831 + [28151].file = "mm/filemap_xip.c",
82832 + [28151].name = "do_xip_mapping_read",
82833 + [28151].param5 = 1,
82834 + [28247].file = "net/sctp/tsnmap.c",
82835 + [28247].name = "sctp_tsnmap_init",
82836 + [28247].param2 = 1,
82837 + [28253].file = "include/linux/fb.h",
82838 + [28253].name = "alloc_apertures",
82839 + [28253].param1 = 1,
82840 + [28265].file = "fs/notify/fanotify/fanotify_user.c",
82841 + [28265].name = "fanotify_write",
82842 + [28265].param3 = 1,
82843 + [28316].file = "drivers/input/joydev.c",
82844 + [28316].name = "joydev_ioctl_common",
82845 + [28316].param2 = 1,
82846 + [28359].file = "drivers/spi/spidev.c",
82847 + [28359].name = "spidev_message",
82848 + [28359].param3 = 1,
82849 + [28360].file = "drivers/hid/usbhid/hiddev.c",
82850 + [28360].name = "hiddev_compat_ioctl",
82851 + [28360].param2 = 1,
82852 + [28407].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
82853 + [28407].name = "rt2x00debug_write_csr",
82854 + [28407].param3 = 1,
82855 + [2847].file = "fs/ntfs/file.c",
82856 + [2847].name = "ntfs_copy_from_user",
82857 + [2847].param3 = 1,
82858 + [2847].param5 = 1,
82859 + [28584].file = "drivers/memstick/core/memstick.c",
82860 + [28584].name = "memstick_alloc_host",
82861 + [28584].param1 = 1,
82862 + [28783].file = "drivers/gpu/drm/i915/i915_debugfs.c",
82863 + [28783].name = "i915_cache_sharing_write",
82864 + [28783].param3 = 1,
82865 + [28787].file = "drivers/media/video/videobuf2-core.c",
82866 + [28787].name = "vb2_write",
82867 + [28787].param3 = 1,
82868 + [28879].file = "drivers/base/map.c",
82869 + [28879].name = "kobj_map",
82870 + [28879].param2 = 1,
82871 + [28879].param3 = 1,
82872 + [28889].file = "drivers/char/pcmcia/cm4040_cs.c",
82873 + [28889].name = "cm4040_write",
82874 + [28889].param3 = 1,
82875 + [29073].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
82876 + [29073].name = "vmw_kms_readback",
82877 + [29073].param6 = 1,
82878 + [29085].file = "security/apparmor/apparmorfs.c",
82879 + [29085].name = "profile_load",
82880 + [29085].param3 = 1,
82881 + [29092].file = "lib/lru_cache.c",
82882 + [29092].name = "lc_create",
82883 + [29092].param3 = 1,
82884 + [29257].file = "drivers/vhost/vhost.c",
82885 + [29257].name = "vhost_add_used_and_signal_n",
82886 + [29257].param4 = 1,
82887 + [29267].file = "net/ipv4/fib_trie.c",
82888 + [29267].name = "tnode_alloc",
82889 + [29267].param1 = 1,
82890 + [29338].file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
82891 + [29338].name = "bnad_debugfs_write_regwr",
82892 + [29338].param3 = 1,
82893 + [29353].file = "net/sctp/socket.c",
82894 + [29353].name = "sctp_setsockopt_del_key",
82895 + [29353].param3 = 1,
82896 + [29405].file = "drivers/media/dvb/dvb-usb/dw2102.c",
82897 + [29405].name = "dw210x_op_rw",
82898 + [29405].param6 = 1,
82899 + [29542].file = "net/nfc/nci/core.c",
82900 + [29542].name = "nci_send_cmd",
82901 + [29542].param3 = 1,
82902 + [29714].file = "drivers/scsi/cxgbi/libcxgbi.c",
82903 + [29714].name = "cxgbi_device_register",
82904 + [29714].param1 = 1,
82905 + [29714].param2 = 1,
82906 + [2972].file = "drivers/staging/crystalhd/crystalhd_misc.c",
82907 + [2972].name = "crystalhd_create_dio_pool",
82908 + [2972].param2 = 1,
82909 + [29769].file = "drivers/misc/iwmc3200top/log.c",
82910 + [29769].name = "store_iwmct_log_level",
82911 + [29769].param4 = 1,
82912 + [29792].file = "drivers/staging/bcm/nvm.c",
82913 + [29792].name = "BcmCopySection",
82914 + [29792].param5 = 1,
82915 + [29859].file = "net/rds/page.c",
82916 + [29859].name = "rds_page_copy_user",
82917 + [29859].param4 = 1,
82918 + [29905].file = "mm/nobootmem.c",
82919 + [29905].name = "___alloc_bootmem",
82920 + [29905].param1 = 1,
82921 + [2995].file = "mm/page_alloc.c",
82922 + [2995].name = "alloc_large_system_hash",
82923 + [2995].param2 = 1,
82924 + [30000].file = "drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c",
82925 + [30000].name = "wlc_phy_loadsampletable_nphy",
82926 + [30000].param3 = 1,
82927 + [30242].file = "fs/cifs/cifssmb.c",
82928 + [30242].name = "cifs_readdata_alloc",
82929 + [30242].param1 = 1,
82930 + [30494].file = "net/ceph/buffer.c",
82931 + [30494].name = "ceph_buffer_new",
82932 + [30494].param1 = 1,
82933 + [30590].file = "security/tomoyo/memory.c",
82934 + [30590].name = "tomoyo_commit_ok",
82935 + [30590].param2 = 1,
82936 + [3060].file = "lib/mpi/mpiutil.c",
82937 + [3060].name = "mpi_alloc_limb_space",
82938 + [3060].param1 = 1,
82939 + [30687].file = "drivers/uwb/uwb-debug.c",
82940 + [30687].name = "command_write",
82941 + [30687].param3 = 1,
82942 + [30726].file = "drivers/bluetooth/hci_vhci.c",
82943 + [30726].name = "vhci_get_user",
82944 + [30726].param3 = 1,
82945 + [30873].file = "net/packet/af_packet.c",
82946 + [30873].name = "alloc_one_pg_vec_page",
82947 + [30873].param1 = 1,
82948 + [30970].file = "drivers/staging/hv/storvsc_drv.c",
82949 + [30970].name = "create_bounce_buffer",
82950 + [30970].param3 = 1,
82951 + [310].file = "drivers/block/drbd/drbd_bitmap.c",
82952 + [310].name = "bm_realloc_pages",
82953 + [310].param2 = 1,
82954 + [3119].file = "drivers/misc/ibmasm/command.c",
82955 + [3119].name = "ibmasm_new_command",
82956 + [3119].param2 = 1,
82957 + [31207].file = "drivers/platform/x86/asus_acpi.c",
82958 + [31207].name = "parse_arg",
82959 + [31207].param2 = 1,
82960 + [31287].file = "drivers/scsi/libsrp.c",
82961 + [31287].name = "srp_iu_pool_alloc",
82962 + [31287].param2 = 1,
82963 + [31291].file = "sound/pci/rme9652/rme9652.c",
82964 + [31291].name = "snd_rme9652_capture_copy",
82965 + [31291].param5 = 1,
82966 + [31348].file = "kernel/sched/core.c",
82967 + [31348].name = "sys_sched_getaffinity",
82968 + [31348].param2 = 1,
82969 + [31492].file = "drivers/hid/hidraw.c",
82970 + [31492].name = "hidraw_read",
82971 + [31492].param3 = 1,
82972 + [3170].file = "security/integrity/ima/ima_fs.c",
82973 + [3170].name = "ima_write_policy",
82974 + [3170].param3 = 1,
82975 + [31782].file = "drivers/misc/pti.c",
82976 + [31782].name = "pti_char_write",
82977 + [31782].param3 = 1,
82978 + [31789].file = "fs/file.c",
82979 + [31789].name = "alloc_fdmem",
82980 + [31789].param1 = 1,
82981 + [31957].file = "fs/afs/proc.c",
82982 + [31957].name = "afs_proc_cells_write",
82983 + [31957].param3 = 1,
82984 + [32002].file = "net/sctp/socket.c",
82985 + [32002].name = "sctp_setsockopt_active_key",
82986 + [32002].param3 = 1,
82987 + [32182].file = "net/sunrpc/cache.c",
82988 + [32182].name = "cache_write",
82989 + [32182].param3 = 1,
82990 + [32278].file = "kernel/time/timer_stats.c",
82991 + [32278].name = "tstats_write",
82992 + [32278].param3 = 1,
82993 + [32326].file = "drivers/tty/n_r3964.c",
82994 + [32326].name = "r3964_write",
82995 + [32326].param4 = 1,
82996 + [32399].file = "drivers/net/phy/mdio_bus.c",
82997 + [32399].name = "mdiobus_alloc_size",
82998 + [32399].param1 = 1,
82999 + [32402].file = "net/ceph/pagevec.c",
83000 + [32402].name = "ceph_copy_user_to_page_vector",
83001 + [32402].param4 = 1,
83002 + [3241].file = "drivers/usb/wusbcore/crypto.c",
83003 + [3241].name = "wusb_prf",
83004 + [3241].param7 = 1,
83005 + [32459].file = "drivers/media/radio/radio-wl1273.c",
83006 + [32459].name = "wl1273_fm_fops_write",
83007 + [32459].param3 = 1,
83008 + [32531].file = "fs/bio.c",
83009 + [32531].name = "__bio_map_kern",
83010 + [32531].param2 = 1,
83011 + [32531].param3 = 1,
83012 + [32537].file = "drivers/staging/vme/devices/vme_user.c",
83013 + [32537].name = "buffer_to_user",
83014 + [32537].param3 = 1,
83015 + [32560].file = "drivers/input/input-mt.c",
83016 + [32560].name = "input_mt_init_slots",
83017 + [32560].param2 = 1,
83018 + [32600].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
83019 + [32600].name = "ath6kl_set_assoc_req_ies",
83020 + [32600].param3 = 1,
83021 + [32608].file = "security/selinux/selinuxfs.c",
83022 + [32608].name = "sel_write_checkreqprot",
83023 + [32608].param3 = 1,
83024 + [32812].file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
83025 + [32812].name = "__vxge_hw_channel_allocate",
83026 + [32812].param3 = 1,
83027 + [32950].file = "fs/reiserfs/resize.c",
83028 + [32950].name = "reiserfs_resize",
83029 + [32950].param2 = 1,
83030 + [33010].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
83031 + [33010].name = "dvb_ringbuffer_pkt_read_user",
83032 + [33010].param5 = 1,
83033 + [33130].file = "net/llc/llc_sap.c",
83034 + [33130].name = "llc_alloc_frame",
83035 + [33130].param4 = 1,
83036 + [33221].file = "crypto/ablkcipher.c",
83037 + [33221].name = "ablkcipher_copy_iv",
83038 + [33221].param3 = 1,
83039 + [33268].file = "mm/maccess.c",
83040 + [33268].name = "__probe_kernel_write",
83041 + [33268].param3 = 1,
83042 + [33280].file = "fs/xfs/kmem.c",
83043 + [33280].name = "kmem_realloc",
83044 + [33280].param2 = 1,
83045 + [33375].file = "drivers/staging/rtl8712/osdep_service.h",
83046 + [33375].name = "_malloc",
83047 + [33375].param1 = 1,
83048 + [33420].file = "drivers/net/team/team.c",
83049 + [33420].name = "__team_options_register",
83050 + [33420].param3 = 1,
83051 + [33489].file = "fs/binfmt_misc.c",
83052 + [33489].name = "create_entry",
83053 + [33489].param2 = 1,
83054 + [33637].file = "net/9p/client.c",
83055 + [33637].name = "p9_client_read",
83056 + [33637].param5 = 1,
83057 + [33669].file = "fs/gfs2/glock.c",
83058 + [33669].name = "gfs2_glock_nq_m",
83059 + [33669].param1 = 1,
83060 + [33704].file = "drivers/gpu/drm/ttm/ttm_page_alloc_dma.c",
83061 + [33704].name = "ttm_dma_page_pool_free",
83062 + [33704].param2 = 1,
83063 + [33779].file = "drivers/staging/vme/devices/vme_user.c",
83064 + [33779].name = "resource_from_user",
83065 + [33779].param3 = 1,
83066 + [33810].file = "net/mac80211/util.c",
83067 + [33810].name = "ieee80211_send_probe_req",
83068 + [33810].param6 = 1,
83069 + [3384].file = "drivers/block/paride/pg.c",
83070 + [3384].name = "pg_write",
83071 + [3384].param3 = 1,
83072 + [34105].file = "fs/libfs.c",
83073 + [34105].name = "simple_read_from_buffer",
83074 + [34105].param2 = 1,
83075 + [34105].param5 = 1,
83076 + [34120].file = "drivers/media/video/pvrusb2/pvrusb2-io.c",
83077 + [34120].name = "pvr2_stream_buffer_count",
83078 + [34120].param2 = 1,
83079 + [34226].file = "mm/shmem.c",
83080 + [34226].name = "shmem_xattr_set",
83081 + [34226].param4 = 1,
83082 + [34251].file = "drivers/staging/cxt1e1/sbecom_inline_linux.h",
83083 + [34251].name = "OS_kmalloc",
83084 + [34251].param1 = 1,
83085 + [34276].file = "drivers/media/video/videobuf2-core.c",
83086 + [34276].name = "__vb2_perform_fileio",
83087 + [34276].param3 = 1,
83088 + [34278].file = "fs/ubifs/debug.c",
83089 + [34278].name = "dfs_global_file_write",
83090 + [34278].param3 = 1,
83091 + [34432].file = "drivers/edac/edac_pci.c",
83092 + [34432].name = "edac_pci_alloc_ctl_info",
83093 + [34432].param1 = 1,
83094 + [34532].file = "drivers/virtio/virtio_ring.c",
83095 + [34532].name = "vring_add_indirect",
83096 + [34532].param3 = 1,
83097 + [34532].param4 = 1,
83098 + [34543].file = "net/sctp/tsnmap.c",
83099 + [34543].name = "sctp_tsnmap_grow",
83100 + [34543].param2 = 1,
83101 + [34551].file = "fs/ocfs2/stack_user.c",
83102 + [34551].name = "ocfs2_control_cfu",
83103 + [34551].param2 = 1,
83104 + [34634].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
83105 + [34634].name = "ath6kl_send_go_probe_resp",
83106 + [34634].param3 = 1,
83107 + [34666].file = "fs/cifs/cifs_debug.c",
83108 + [34666].name = "cifs_security_flags_proc_write",
83109 + [34666].param3 = 1,
83110 + [3466].file = "drivers/misc/altera-stapl/altera-jtag.c",
83111 + [3466].name = "altera_drscan",
83112 + [3466].param2 = 1,
83113 + [34672].file = "drivers/tty/tty_io.c",
83114 + [34672].name = "tty_write",
83115 + [34672].param3 = 1,
83116 + [34679].file = "drivers/media/video/ivtv/ivtv-fileops.c",
83117 + [34679].name = "ivtv_copy_buf_to_user",
83118 + [34679].param4 = 1,
83119 + [34721].file = "drivers/usb/host/hwa-hc.c",
83120 + [34721].name = "__hwahc_dev_set_key",
83121 + [34721].param5 = 1,
83122 + [34749].file = "mm/nobootmem.c",
83123 + [34749].name = "__alloc_bootmem_low_node",
83124 + [34749].param2 = 1,
83125 + [34760].file = "include/acpi/platform/aclinux.h",
83126 + [34760].name = "acpi_os_allocate_zeroed",
83127 + [34760].param1 = 1,
83128 + [34802].file = "drivers/scsi/cxgbi/libcxgbi.h",
83129 + [34802].name = "cxgbi_alloc_big_mem",
83130 + [34802].param1 = 1,
83131 + [34863].file = "drivers/video/fbsysfs.c",
83132 + [34863].name = "framebuffer_alloc",
83133 + [34863].param1 = 1,
83134 + [34868].file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
83135 + [34868].name = "bnad_debugfs_write_regrd",
83136 + [34868].param3 = 1,
83137 + [34882].file = "drivers/platform/x86/toshiba_acpi.c",
83138 + [34882].name = "video_proc_write",
83139 + [34882].param3 = 1,
83140 + [35050].file = "fs/ocfs2/dlmfs/dlmfs.c",
83141 + [35050].name = "dlmfs_file_write",
83142 + [35050].param3 = 1,
83143 + [35119].file = "fs/xattr.c",
83144 + [35119].name = "sys_llistxattr",
83145 + [35119].param3 = 1,
83146 + [35129].file = "mm/nobootmem.c",
83147 + [35129].name = "___alloc_bootmem_nopanic",
83148 + [35129].param1 = 1,
83149 + [35159].file = "drivers/net/wimax/i2400m/usb.c",
83150 + [35159].name = "__i2400mu_send_barker",
83151 + [35159].param3 = 1,
83152 + [35232].file = "drivers/media/video/cx18/cx18-fileops.c",
83153 + [35232].name = "cx18_read",
83154 + [35232].param3 = 1,
83155 + [35234].file = "net/irda/irnet/irnet_ppp.c",
83156 + [35234].name = "irnet_ctrl_write",
83157 + [35234].param3 = 1,
83158 + [35256].file = "sound/core/memory.c",
83159 + [35256].name = "copy_from_user_toio",
83160 + [35256].param3 = 1,
83161 + [35268].file = "security/keys/request_key_auth.c",
83162 + [35268].name = "request_key_auth_read",
83163 + [35268].param3 = 1,
83164 + [3538].file = "net/bluetooth/mgmt.c",
83165 + [3538].name = "disconnect",
83166 + [3538].param4 = 1,
83167 + [35443].file = "sound/core/pcm_memory.c",
83168 + [35443].name = "_snd_pcm_lib_alloc_vmalloc_buffer",
83169 + [35443].param2 = 1,
83170 + [35468].file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
83171 + [35468].name = "xenbus_file_write",
83172 + [35468].param3 = 1,
83173 + [35536].file = "kernel/sysctl_binary.c",
83174 + [35536].name = "bin_uuid",
83175 + [35536].param3 = 1,
83176 + [35551].file = "drivers/media/video/ivtv/ivtv-fileops.c",
83177 + [35551].name = "ivtv_read_pos",
83178 + [35551].param3 = 1,
83179 + [35556].file = "fs/read_write.c",
83180 + [35556].name = "sys_readv",
83181 + [35556].param3 = 1,
83182 + [35693].file = "drivers/staging/mei/main.c",
83183 + [35693].name = "mei_read",
83184 + [35693].param3 = 1,
83185 + [35703].file = "crypto/ablkcipher.c",
83186 + [35703].name = "ablkcipher_next_slow",
83187 + [35703].param3 = 1,
83188 + [35703].param4 = 1,
83189 + [35729].file = "include/linux/skbuff.h",
83190 + [35729].name = "__dev_alloc_skb",
83191 + [35729].param1 = 1,
83192 + [35731].file = "drivers/usb/class/cdc-wdm.c",
83193 + [35731].name = "wdm_read",
83194 + [35731].param3 = 1,
83195 + [35796].file = "drivers/mtd/nand/nand_bch.c",
83196 + [35796].name = "nand_bch_init",
83197 + [35796].param2 = 1,
83198 + [35796].param3 = 1,
83199 + [35880].file = "fs/ecryptfs/crypto.c",
83200 + [35880].name = "ecryptfs_encrypt_and_encode_filename",
83201 + [35880].param6 = 1,
83202 + [36076].file = "drivers/net/ethernet/sfc/tx.c",
83203 + [36076].name = "efx_tsoh_heap_alloc",
83204 + [36076].param2 = 1,
83205 + [36080].file = "drivers/media/video/v4l2-ioctl.c",
83206 + [36080].name = "video_usercopy",
83207 + [36080].param2 = 1,
83208 + [36149].file = "fs/udf/inode.c",
83209 + [36149].name = "udf_alloc_i_data",
83210 + [36149].param2 = 1,
83211 + [36183].file = "drivers/tty/vt/vc_screen.c",
83212 + [36183].name = "vcs_read",
83213 + [36183].param3 = 1,
83214 + [36199].file = "net/sunrpc/auth_gss/auth_gss.c",
83215 + [36199].name = "gss_pipe_downcall",
83216 + [36199].param3 = 1,
83217 + [36206].file = "net/ipv4/tcp_input.c",
83218 + [36206].name = "tcp_collapse",
83219 + [36206].param5 = 1,
83220 + [36206].param6 = 1,
83221 + [36230].file = "drivers/net/wan/hdlc_ppp.c",
83222 + [36230].name = "ppp_cp_parse_cr",
83223 + [36230].param4 = 1,
83224 + [36284].file = "drivers/spi/spi.c",
83225 + [36284].name = "spi_register_board_info",
83226 + [36284].param2 = 1,
83227 + [36490].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
83228 + [36490].name = "ath6kl_cfg80211_connect_event",
83229 + [36490].param7 = 1,
83230 + [36522].file = "drivers/hid/hidraw.c",
83231 + [36522].name = "hidraw_send_report",
83232 + [36522].param3 = 1,
83233 + [36560].file = "net/sunrpc/cache.c",
83234 + [36560].name = "write_flush",
83235 + [36560].param3 = 1,
83236 + [36807].file = "drivers/usb/mon/mon_bin.c",
83237 + [36807].name = "mon_bin_get_event",
83238 + [36807].param4 = 1,
83239 + [37034].file = "fs/cifs/cifssmb.c",
83240 + [37034].name = "cifs_writedata_alloc",
83241 + [37034].param1 = 1,
83242 + [37044].file = "sound/firewire/packets-buffer.c",
83243 + [37044].name = "iso_packets_buffer_init",
83244 + [37044].param3 = 1,
83245 + [37108].file = "drivers/media/dvb/ttpci/av7110_av.c",
83246 + [37108].name = "dvb_video_write",
83247 + [37108].param3 = 1,
83248 + [37154].file = "net/nfc/llcp/commands.c",
83249 + [37154].name = "nfc_llcp_build_tlv",
83250 + [37154].param3 = 1,
83251 + [37163].file = "net/core/skbuff.c",
83252 + [37163].name = "__netdev_alloc_skb",
83253 + [37163].param2 = 1,
83254 + [37233].file = "fs/ocfs2/cluster/tcp.c",
83255 + [37233].name = "o2net_send_message_vec",
83256 + [37233].param4 = 1,
83257 + [37241].file = "net/atm/lec.c",
83258 + [37241].name = "lane2_associate_req",
83259 + [37241].param4 = 1,
83260 + [37384].file = "drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c",
83261 + [37384].name = "vmw_fifo_reserve",
83262 + [37384].param2 = 1,
83263 + [37497].file = "net/mac80211/util.c",
83264 + [37497].name = "ieee80211_build_probe_req",
83265 + [37497].param7 = 1,
83266 + [37535].file = "kernel/trace/trace.c",
83267 + [37535].name = "tracing_trace_options_write",
83268 + [37535].param3 = 1,
83269 + [37611].file = "drivers/xen/xenbus/xenbus_xs.c",
83270 + [37611].name = "split",
83271 + [37611].param2 = 1,
83272 + [37661].file = "mm/filemap.c",
83273 + [37661].name = "file_read_actor",
83274 + [37661].param4 = 1,
83275 + [37852].file = "drivers/staging/android/logger.c",
83276 + [37852].name = "do_read_log_to_user",
83277 + [37852].param4 = 1,
83278 + [37921].file = "drivers/net/wireless/wl12xx/rx.c",
83279 + [37921].name = "wl1271_rx_handle_data",
83280 + [37921].param3 = 1,
83281 + [37976].file = "drivers/platform/x86/asus_acpi.c",
83282 + [37976].name = "bluetooth_proc_write",
83283 + [37976].param3 = 1,
83284 + [3797].file = "sound/pci/asihpi/hpicmn.c",
83285 + [3797].name = "hpi_alloc_control_cache",
83286 + [3797].param1 = 1,
83287 + [3801].file = "drivers/block/paride/pt.c",
83288 + [3801].name = "pt_write",
83289 + [3801].param3 = 1,
83290 + [38052].file = "kernel/kexec.c",
83291 + [38052].name = "kimage_normal_alloc",
83292 + [38052].param3 = 1,
83293 + [38057].file = "fs/coda/psdev.c",
83294 + [38057].name = "coda_psdev_write",
83295 + [38057].param3 = 1,
83296 + [38186].file = "kernel/signal.c",
83297 + [38186].name = "do_sigpending",
83298 + [38186].param2 = 1,
83299 + [38314].file = "fs/nfs/read.c",
83300 + [38314].name = "nfs_readdata_alloc",
83301 + [38314].param1 = 1,
83302 + [38401].file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
83303 + [38401].name = "queue_reply",
83304 + [38401].param3 = 1,
83305 + [3841].file = "drivers/platform/x86/asus_acpi.c",
83306 + [3841].name = "write_led",
83307 + [3841].param2 = 1,
83308 + [38532].file = "fs/afs/cell.c",
83309 + [38532].name = "afs_cell_lookup",
83310 + [38532].param2 = 1,
83311 + [38564].file = "fs/nfs/nfs4proc.c",
83312 + [38564].name = "nfs4_realloc_slot_table",
83313 + [38564].param2 = 1,
83314 + [38576].file = "drivers/i2c/i2c-dev.c",
83315 + [38576].name = "i2cdev_read",
83316 + [38576].param3 = 1,
83317 + [38704].file = "drivers/media/video/uvc/uvc_driver.c",
83318 + [38704].name = "uvc_alloc_entity",
83319 + [38704].param3 = 1,
83320 + [38704].param4 = 1,
83321 + [38747].file = "fs/xattr.c",
83322 + [38747].name = "sys_lgetxattr",
83323 + [38747].param4 = 1,
83324 + [38867].file = "drivers/scsi/scsi_transport_fc.c",
83325 + [38867].name = "fc_host_post_vendor_event",
83326 + [38867].param3 = 1,
83327 + [38931].file = "drivers/isdn/hardware/eicon/capimain.c",
83328 + [38931].name = "diva_os_alloc_message_buffer",
83329 + [38931].param1 = 1,
83330 + [38972].file = "security/smack/smackfs.c",
83331 + [38972].name = "smk_write_logging",
83332 + [38972].param3 = 1,
83333 + [39001].file = "net/xfrm/xfrm_hash.c",
83334 + [39001].name = "xfrm_hash_alloc",
83335 + [39001].param1 = 1,
83336 + [39052].file = "drivers/input/evdev.c",
83337 + [39052].name = "evdev_ioctl",
83338 + [39052].param2 = 1,
83339 + [39066].file = "drivers/media/dvb/frontends/tda10048.c",
83340 + [39066].name = "tda10048_writeregbulk",
83341 + [39066].param4 = 1,
83342 + [39118].file = "drivers/misc/iwmc3200top/log.c",
83343 + [39118].name = "store_iwmct_log_level_fw",
83344 + [39118].param4 = 1,
83345 + [39254].file = "drivers/char/pcmcia/cm4000_cs.c",
83346 + [39254].name = "cmm_write",
83347 + [39254].param3 = 1,
83348 + [39392].file = "drivers/atm/solos-pci.c",
83349 + [39392].name = "send_command",
83350 + [39392].param4 = 1,
83351 + [39415].file = "fs/pstore/inode.c",
83352 + [39415].name = "pstore_mkfile",
83353 + [39415].param5 = 1,
83354 + [39417].file = "drivers/block/DAC960.c",
83355 + [39417].name = "dac960_user_command_proc_write",
83356 + [39417].param3 = 1,
83357 + [39460].file = "fs/btrfs/volumes.c",
83358 + [39460].name = "btrfs_map_block",
83359 + [39460].param3 = 1,
83360 + [39479].file = "drivers/ide/ide-tape.c",
83361 + [39479].name = "idetape_chrdev_read",
83362 + [39479].param3 = 1,
83363 + [39586].file = "drivers/hv/channel.c",
83364 + [39586].name = "create_gpadl_header",
83365 + [39586].param2 = 1,
83366 + [39638].file = "security/selinux/selinuxfs.c",
83367 + [39638].name = "sel_write_avc_cache_threshold",
83368 + [39638].param3 = 1,
83369 + [39645].file = "drivers/media/dvb/dvb-core/dvbdev.c",
83370 + [39645].name = "dvb_generic_ioctl",
83371 + [39645].param2 = 1,
83372 + [39770].file = "include/linux/mISDNif.h",
83373 + [39770].name = "mI_alloc_skb",
83374 + [39770].param1 = 1,
83375 + [39813].file = "fs/ocfs2/stack_user.c",
83376 + [39813].name = "ocfs2_control_message",
83377 + [39813].param3 = 1,
83378 + [39888].file = "net/core/skbuff.c",
83379 + [39888].name = "__alloc_skb",
83380 + [39888].param1 = 1,
83381 + [39980].file = "net/bluetooth/mgmt.c",
83382 + [39980].name = "pair_device",
83383 + [39980].param4 = 1,
83384 + [40043].file = "drivers/media/video/v4l2-ioctl.c",
83385 + [40043].name = "video_ioctl2",
83386 + [40043].param2 = 1,
83387 + [40049].file = "drivers/bluetooth/btmrvl_debugfs.c",
83388 + [40049].name = "btmrvl_psmode_write",
83389 + [40049].param3 = 1,
83390 + [40075].file = "drivers/media/video/c-qcam.c",
83391 + [40075].name = "qc_capture",
83392 + [40075].param3 = 1,
83393 + [40163].file = "fs/ncpfs/file.c",
83394 + [40163].name = "ncp_file_write",
83395 + [40163].param3 = 1,
83396 + [40240].file = "drivers/char/nvram.c",
83397 + [40240].name = "nvram_write",
83398 + [40240].param3 = 1,
83399 + [40256].file = "drivers/tty/vt/vc_screen.c",
83400 + [40256].name = "vcs_write",
83401 + [40256].param3 = 1,
83402 + [40302].file = "sound/isa/gus/gus_dram.c",
83403 + [40302].name = "snd_gus_dram_poke",
83404 + [40302].param4 = 1,
83405 + [40339].file = "drivers/acpi/apei/hest.c",
83406 + [40339].name = "hest_ghes_dev_register",
83407 + [40339].param1 = 1,
83408 + [40355].file = "drivers/staging/mei/main.c",
83409 + [40355].name = "mei_write",
83410 + [40355].param3 = 1,
83411 + [40373].file = "fs/cifs/cifs_spnego.c",
83412 + [40373].name = "cifs_spnego_key_instantiate",
83413 + [40373].param3 = 1,
83414 + [40519].file = "net/sctp/socket.c",
83415 + [40519].name = "sctp_setsockopt_events",
83416 + [40519].param3 = 1,
83417 + [40694].file = "mm/page_cgroup.c",
83418 + [40694].name = "alloc_page_cgroup",
83419 + [40694].param1 = 1,
83420 + [40731].file = "drivers/tty/tty_io.c",
83421 + [40731].name = "do_tty_write",
83422 + [40731].param5 = 1,
83423 + [40754].file = "fs/btrfs/delayed-inode.c",
83424 + [40754].name = "btrfs_alloc_delayed_item",
83425 + [40754].param1 = 1,
83426 + [40786].file = "net/ipv4/netfilter/nf_nat_snmp_basic.c",
83427 + [40786].name = "asn1_octets_decode",
83428 + [40786].param2 = 1,
83429 + [40901].file = "drivers/block/drbd/drbd_bitmap.c",
83430 + [40901].name = "drbd_bm_resize",
83431 + [40901].param2 = 1,
83432 + [40951].file = "drivers/xen/evtchn.c",
83433 + [40951].name = "evtchn_read",
83434 + [40951].param3 = 1,
83435 + [40952].file = "drivers/misc/sgi-xp/xpc_partition.c",
83436 + [40952].name = "xpc_kmalloc_cacheline_aligned",
83437 + [40952].param1 = 1,
83438 + [41000].file = "sound/core/pcm_native.c",
83439 + [41000].name = "snd_pcm_aio_read",
83440 + [41000].param3 = 1,
83441 + [41005].file = "net/bridge/netfilter/ebtables.c",
83442 + [41005].name = "copy_counters_to_user",
83443 + [41005].param5 = 1,
83444 + [41041].file = "net/core/sock.c",
83445 + [41041].name = "sock_wmalloc",
83446 + [41041].param2 = 1,
83447 + [41122].file = "fs/binfmt_misc.c",
83448 + [41122].name = "bm_status_write",
83449 + [41122].param3 = 1,
83450 + [41176].file = "kernel/trace/trace_events.c",
83451 + [41176].name = "subsystem_filter_write",
83452 + [41176].param3 = 1,
83453 + [41249].file = "drivers/media/video/zr364xx.c",
83454 + [41249].name = "send_control_msg",
83455 + [41249].param6 = 1,
83456 + [41287].file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
83457 + [41287].name = "vxge_os_dma_malloc_async",
83458 + [41287].param3 = 1,
83459 + [41302].file = "net/dns_resolver/dns_query.c",
83460 + [41302].name = "dns_query",
83461 + [41302].param3 = 1,
83462 + [41408].file = "mm/filemap_xip.c",
83463 + [41408].name = "__xip_file_write",
83464 + [41408].param3 = 1,
83465 + [41547].file = "net/bluetooth/smp.c",
83466 + [41547].name = "smp_build_cmd",
83467 + [41547].param3 = 1,
83468 + [4155].file = "kernel/kexec.c",
83469 + [4155].name = "do_kimage_alloc",
83470 + [4155].param3 = 1,
83471 + [41676].file = "fs/compat.c",
83472 + [41676].name = "compat_sys_preadv",
83473 + [41676].param3 = 1,
83474 + [4167].file = "drivers/media/dvb/frontends/cx24116.c",
83475 + [4167].name = "cx24116_writeregN",
83476 + [4167].param4 = 1,
83477 + [41793].file = "drivers/net/wireless/ath/ath6kl/wmi.c",
83478 + [41793].name = "ath6kl_wmi_send_mgmt_cmd",
83479 + [41793].param7 = 1,
83480 + [41924].file = "security/keys/keyctl.c",
83481 + [41924].name = "keyctl_get_security",
83482 + [41924].param3 = 1,
83483 + [41968].file = "fs/btrfs/volumes.c",
83484 + [41968].name = "__btrfs_map_block",
83485 + [41968].param3 = 1,
83486 + [4202].file = "drivers/edac/edac_mc.c",
83487 + [4202].name = "edac_mc_alloc",
83488 + [4202].param1 = 1,
83489 + [42081].file = "net/econet/af_econet.c",
83490 + [42081].name = "aun_incoming",
83491 + [42081].param3 = 1,
83492 + [42143].file = "drivers/media/video/c-qcam.c",
83493 + [42143].name = "qcam_read",
83494 + [42143].param3 = 1,
83495 + [42206].file = "fs/quota/quota_tree.c",
83496 + [42206].name = "getdqbuf",
83497 + [42206].param1 = 1,
83498 + [42270].file = "net/wireless/scan.c",
83499 + [42270].name = "cfg80211_inform_bss_frame",
83500 + [42270].param4 = 1,
83501 + [42281].file = "include/linux/mISDNif.h",
83502 + [42281].name = "_queue_data",
83503 + [42281].param4 = 1,
83504 + [42420].file = "drivers/net/wireless/hostap/hostap_ioctl.c",
83505 + [42420].name = "prism2_set_genericelement",
83506 + [42420].param3 = 1,
83507 + [42472].file = "fs/compat.c",
83508 + [42472].name = "compat_readv",
83509 + [42472].param3 = 1,
83510 + [42473].file = "net/tipc/name_table.c",
83511 + [42473].name = "tipc_subseq_alloc",
83512 + [42473].param1 = 1,
83513 + [42562].file = "kernel/kfifo.c",
83514 + [42562].name = "__kfifo_to_user_r",
83515 + [42562].param3 = 1,
83516 + [42666].file = "drivers/pcmcia/cistpl.c",
83517 + [42666].name = "read_cis_cache",
83518 + [42666].param4 = 1,
83519 + [42714].file = "drivers/scsi/scsi_tgt_lib.c",
83520 + [42714].name = "scsi_tgt_copy_sense",
83521 + [42714].param3 = 1,
83522 + [42833].file = "kernel/trace/blktrace.c",
83523 + [42833].name = "blk_msg_write",
83524 + [42833].param3 = 1,
83525 + [42857].file = "security/selinux/selinuxfs.c",
83526 + [42857].name = "sel_write_member",
83527 + [42857].param3 = 1,
83528 + [42882].file = "security/keys/user_defined.c",
83529 + [42882].name = "user_instantiate",
83530 + [42882].param3 = 1,
83531 + [42930].file = "net/caif/cfpkt_skbuff.c",
83532 + [42930].name = "cfpkt_create_pfx",
83533 + [42930].param1 = 1,
83534 + [42930].param2 = 1,
83535 + [43023].file = "drivers/usb/misc/usblcd.c",
83536 + [43023].name = "lcd_write",
83537 + [43023].param3 = 1,
83538 + [43104].file = "drivers/mtd/devices/mtd_dataflash.c",
83539 + [43104].name = "dataflash_read_user_otp",
83540 + [43104].param3 = 1,
83541 + [43133].file = "lib/mpi/mpiutil.c",
83542 + [43133].name = "mpi_resize",
83543 + [43133].param2 = 1,
83544 + [4324].file = "drivers/video/fbmem.c",
83545 + [4324].name = "fb_read",
83546 + [4324].param3 = 1,
83547 + [43266].file = "fs/afs/cell.c",
83548 + [43266].name = "afs_cell_alloc",
83549 + [43266].param2 = 1,
83550 + [4328].file = "drivers/usb/musb/musb_debugfs.c",
83551 + [4328].name = "musb_test_mode_write",
83552 + [4328].param3 = 1,
83553 + [43380].file = "drivers/scsi/bfa/bfad_debugfs.c",
83554 + [43380].name = "bfad_debugfs_write_regrd",
83555 + [43380].param3 = 1,
83556 + [43510].file = "kernel/kexec.c",
83557 + [43510].name = "compat_sys_kexec_load",
83558 + [43510].param2 = 1,
83559 + [43540].file = "include/rdma/ib_verbs.h",
83560 + [43540].name = "ib_copy_to_udata",
83561 + [43540].param3 = 1,
83562 + [4357].file = "security/tomoyo/securityfs_if.c",
83563 + [4357].name = "tomoyo_read_self",
83564 + [4357].param3 = 1,
83565 + [43590].file = "security/smack/smackfs.c",
83566 + [43590].name = "smk_write_onlycap",
83567 + [43590].param3 = 1,
83568 + [43596].file = "drivers/usb/core/buffer.c",
83569 + [43596].name = "hcd_buffer_alloc",
83570 + [43596].param2 = 1,
83571 + [43632].file = "drivers/media/video/videobuf2-core.c",
83572 + [43632].name = "vb2_read",
83573 + [43632].param3 = 1,
83574 + [43659].file = "drivers/firmware/efivars.c",
83575 + [43659].name = "efivar_create_sysfs_entry",
83576 + [43659].param2 = 1,
83577 + [43731].file = "drivers/hid/hid-picolcd.c",
83578 + [43731].name = "picolcd_debug_eeprom_read",
83579 + [43731].param3 = 1,
83580 + [43777].file = "drivers/acpi/acpica/utobject.c",
83581 + [43777].name = "acpi_ut_create_buffer_object",
83582 + [43777].param1 = 1,
83583 + [43798].file = "net/bluetooth/mgmt.c",
83584 + [43798].name = "set_local_name",
83585 + [43798].param4 = 1,
83586 + [4380].file = "drivers/mtd/devices/mtd_dataflash.c",
83587 + [4380].name = "dataflash_read_fact_otp",
83588 + [4380].param3 = 1,
83589 + [43834].file = "security/apparmor/apparmorfs.c",
83590 + [43834].name = "profile_replace",
83591 + [43834].param3 = 1,
83592 + [43895].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
83593 + [43895].name = "ddb_output_write",
83594 + [43895].param3 = 1,
83595 + [43899].file = "drivers/media/rc/imon.c",
83596 + [43899].name = "vfd_write",
83597 + [43899].param3 = 1,
83598 + [43900].file = "drivers/scsi/cxgbi/libcxgbi.c",
83599 + [43900].name = "cxgbi_device_portmap_create",
83600 + [43900].param3 = 1,
83601 + [43922].file = "drivers/mmc/card/mmc_test.c",
83602 + [43922].name = "mmc_test_alloc_mem",
83603 + [43922].param3 = 1,
83604 + [43946].file = "drivers/net/wireless/ath/ath6kl/txrx.c",
83605 + [43946].name = "aggr_recv_addba_req_evt",
83606 + [43946].param4 = 1,
83607 + [44006].file = "mm/process_vm_access.c",
83608 + [44006].name = "process_vm_rw_pages",
83609 + [44006].param5 = 1,
83610 + [44006].param6 = 1,
83611 + [44050].file = "fs/nfs/idmap.c",
83612 + [44050].name = "nfs_map_group_to_gid",
83613 + [44050].param3 = 1,
83614 + [44125].file = "fs/ext4/super.c",
83615 + [44125].name = "ext4_kvmalloc",
83616 + [44125].param1 = 1,
83617 + [44266].file = "kernel/cgroup.c",
83618 + [44266].name = "cgroup_write_string",
83619 + [44266].param5 = 1,
83620 + [44290].file = "drivers/net/usb/dm9601.c",
83621 + [44290].name = "dm_read",
83622 + [44290].param3 = 1,
83623 + [44308].file = "crypto/af_alg.c",
83624 + [44308].name = "alg_setkey",
83625 + [44308].param3 = 1,
83626 + [44510].file = "drivers/net/ethernet/broadcom/bnx2.c",
83627 + [44510].name = "bnx2_nvram_write",
83628 + [44510].param2 = 1,
83629 + [44625].file = "net/bluetooth/mgmt.c",
83630 + [44625].name = "set_connectable",
83631 + [44625].param4 = 1,
83632 + [44642].file = "drivers/net/wireless/iwmc3200wifi/commands.c",
83633 + [44642].name = "iwm_umac_set_config_var",
83634 + [44642].param4 = 1,
83635 + [44698].file = "net/sctp/socket.c",
83636 + [44698].name = "sctp_setsockopt_context",
83637 + [44698].param3 = 1,
83638 + [4471].file = "fs/ntfs/malloc.h",
83639 + [4471].name = "__ntfs_malloc",
83640 + [4471].param1 = 1,
83641 + [44773].file = "drivers/staging/vme/devices/vme_user.c",
83642 + [44773].name = "vme_user_write",
83643 + [44773].param3 = 1,
83644 + [44825].file = "drivers/scsi/osd/osd_initiator.c",
83645 + [44825].name = "_osd_realloc_seg",
83646 + [44825].param3 = 1,
83647 + [44852].file = "net/sctp/socket.c",
83648 + [44852].name = "sctp_setsockopt_rtoinfo",
83649 + [44852].param3 = 1,
83650 + [44936].file = "drivers/md/dm-raid.c",
83651 + [44936].name = "context_alloc",
83652 + [44936].param3 = 1,
83653 + [44943].file = "mm/util.c",
83654 + [44943].name = "kmemdup",
83655 + [44943].param2 = 1,
83656 + [44946].file = "net/sctp/socket.c",
83657 + [44946].name = "sctp_setsockopt_auth_chunk",
83658 + [44946].param3 = 1,
83659 + [44990].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
83660 + [44990].name = "pvr2_ioread_set_sync_key",
83661 + [44990].param3 = 1,
83662 + [45000].file = "fs/afs/proc.c",
83663 + [45000].name = "afs_proc_rootcell_write",
83664 + [45000].param3 = 1,
83665 + [45117].file = "drivers/staging/winbond/wb35reg.c",
83666 + [45117].name = "Wb35Reg_BurstWrite",
83667 + [45117].param4 = 1,
83668 + [45200].file = "drivers/scsi/scsi_proc.c",
83669 + [45200].name = "proc_scsi_write_proc",
83670 + [45200].param3 = 1,
83671 + [45217].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
83672 + [45217].name = "iwl_dbgfs_debug_level_write",
83673 + [45217].param3 = 1,
83674 + [45233].file = "net/rds/info.c",
83675 + [45233].name = "rds_info_getsockopt",
83676 + [45233].param3 = 1,
83677 + [45326].file = "drivers/mtd/ubi/cdev.c",
83678 + [45326].name = "vol_cdev_read",
83679 + [45326].param3 = 1,
83680 + [45335].file = "fs/read_write.c",
83681 + [45335].name = "vfs_writev",
83682 + [45335].param3 = 1,
83683 + [45366].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
83684 + [45366].name = "init_tid_tabs",
83685 + [45366].param2 = 1,
83686 + [45366].param3 = 1,
83687 + [45366].param4 = 1,
83688 + [45534].file = "drivers/net/wireless/ath/carl9170/cmd.c",
83689 + [45534].name = "carl9170_cmd_buf",
83690 + [45534].param3 = 1,
83691 + [45576].file = "net/netfilter/xt_recent.c",
83692 + [45576].name = "recent_mt_proc_write",
83693 + [45576].param3 = 1,
83694 + [45583].file = "fs/gfs2/dir.c",
83695 + [45583].name = "leaf_dealloc",
83696 + [45583].param3 = 1,
83697 + [45586].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83698 + [45586].name = "rt2x00debug_write_bbp",
83699 + [45586].param3 = 1,
83700 + [45629].file = "lib/bch.c",
83701 + [45629].name = "bch_alloc",
83702 + [45629].param1 = 1,
83703 + [45633].file = "drivers/input/evdev.c",
83704 + [45633].name = "evdev_do_ioctl",
83705 + [45633].param2 = 1,
83706 + [45743].file = "drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c",
83707 + [45743].name = "qlcnic_alloc_msix_entries",
83708 + [45743].param2 = 1,
83709 + [45864].file = "drivers/atm/ambassador.c",
83710 + [45864].name = "create_queues",
83711 + [45864].param2 = 1,
83712 + [45864].param3 = 1,
83713 + [45930].file = "security/apparmor/apparmorfs.c",
83714 + [45930].name = "profile_remove",
83715 + [45930].param3 = 1,
83716 + [45954].file = "drivers/usb/misc/legousbtower.c",
83717 + [45954].name = "tower_write",
83718 + [45954].param3 = 1,
83719 + [46140].file = "sound/core/memalloc.c",
83720 + [46140].name = "snd_mem_proc_write",
83721 + [46140].param3 = 1,
83722 + [4616].file = "net/sunrpc/cache.c",
83723 + [4616].name = "cache_do_downcall",
83724 + [4616].param3 = 1,
83725 + [46243].file = "fs/binfmt_misc.c",
83726 + [46243].name = "bm_register_write",
83727 + [46243].param3 = 1,
83728 + [46250].file = "fs/xattr.c",
83729 + [46250].name = "sys_getxattr",
83730 + [46250].param4 = 1,
83731 + [46343].file = "fs/compat.c",
83732 + [46343].name = "compat_do_readv_writev",
83733 + [46343].param4 = 1,
83734 + [46400].file = "drivers/staging/sep/sep_driver.c",
83735 + [46400].name = "sep_prepare_input_output_dma_table",
83736 + [46400].param2 = 1,
83737 + [46400].param3 = 1,
83738 + [46400].param4 = 1,
83739 + [4644].file = "drivers/net/usb/mcs7830.c",
83740 + [4644].name = "mcs7830_get_reg",
83741 + [4644].param3 = 1,
83742 + [46605].file = "sound/core/oss/pcm_oss.c",
83743 + [46605].name = "snd_pcm_oss_sync1",
83744 + [46605].param2 = 1,
83745 + [46630].file = "net/decnet/af_decnet.c",
83746 + [46630].name = "__dn_setsockopt",
83747 + [46630].param5 = 1,
83748 + [46655].file = "drivers/media/video/hdpvr/hdpvr-video.c",
83749 + [46655].name = "hdpvr_read",
83750 + [46655].param3 = 1,
83751 + [46685].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
83752 + [46685].name = "ttm_bo_fbdev_io",
83753 + [46685].param4 = 1,
83754 + [46742].file = "drivers/scsi/st.c",
83755 + [46742].name = "sgl_map_user_pages",
83756 + [46742].param2 = 1,
83757 + [46881].file = "drivers/char/lp.c",
83758 + [46881].name = "lp_write",
83759 + [46881].param3 = 1,
83760 + [47130].file = "kernel/kfifo.c",
83761 + [47130].name = "kfifo_copy_to_user",
83762 + [47130].param3 = 1,
83763 + [47265].file = "drivers/scsi/bnx2fc/bnx2fc_io.c",
83764 + [47265].name = "bnx2fc_cmd_mgr_alloc",
83765 + [47265].param2 = 1,
83766 + [47265].param3 = 1,
83767 + [47309].file = "drivers/scsi/aic94xx/aic94xx_init.c",
83768 + [47309].name = "asd_store_update_bios",
83769 + [47309].param4 = 1,
83770 + [47342].file = "fs/proc/base.c",
83771 + [47342].name = "sched_autogroup_write",
83772 + [47342].param3 = 1,
83773 + [47363].file = "drivers/input/evdev.c",
83774 + [47363].name = "evdev_ioctl_handler",
83775 + [47363].param2 = 1,
83776 + [47385].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
83777 + [47385].name = "zd_usb_iowrite16v",
83778 + [47385].param3 = 1,
83779 + [4738].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
83780 + [4738].name = "ath6kl_set_ap_probe_resp_ies",
83781 + [4738].param3 = 1,
83782 + [47393].file = "drivers/net/wireless/ath/main.c",
83783 + [47393].name = "ath_rxbuf_alloc",
83784 + [47393].param2 = 1,
83785 + [47463].file = "fs/xfs/kmem.c",
83786 + [47463].name = "kmem_zalloc",
83787 + [47463].param1 = 1,
83788 + [47474].file = "kernel/trace/trace.c",
83789 + [47474].name = "tracing_buffers_read",
83790 + [47474].param3 = 1,
83791 + [47636].file = "drivers/usb/class/usblp.c",
83792 + [47636].name = "usblp_ioctl",
83793 + [47636].param2 = 1,
83794 + [47637].file = "drivers/block/cciss.c",
83795 + [47637].name = "cciss_proc_write",
83796 + [47637].param3 = 1,
83797 + [47712].file = "net/sctp/socket.c",
83798 + [47712].name = "sctp_setsockopt_maxburst",
83799 + [47712].param3 = 1,
83800 + [47728].file = "drivers/char/agp/isoch.c",
83801 + [47728].name = "agp_3_5_isochronous_node_enable",
83802 + [47728].param3 = 1,
83803 + [4779].file = "fs/pipe.c",
83804 + [4779].name = "pipe_set_size",
83805 + [4779].param2 = 1,
83806 + [47881].file = "security/selinux/selinuxfs.c",
83807 + [47881].name = "sel_write_disable",
83808 + [47881].param3 = 1,
83809 + [48111].file = "net/wireless/sme.c",
83810 + [48111].name = "cfg80211_roamed_bss",
83811 + [48111].param4 = 1,
83812 + [48111].param6 = 1,
83813 + [48124].file = "drivers/net/wireless/iwmc3200wifi/main.c",
83814 + [48124].name = "iwm_notif_send",
83815 + [48124].param6 = 1,
83816 + [48155].file = "net/sctp/sm_make_chunk.c",
83817 + [48155].name = "sctp_make_abort_user",
83818 + [48155].param3 = 1,
83819 + [48182].file = "crypto/cryptd.c",
83820 + [48182].name = "cryptd_alloc_instance",
83821 + [48182].param2 = 1,
83822 + [48182].param3 = 1,
83823 + [48248].file = "security/keys/keyctl.c",
83824 + [48248].name = "keyctl_instantiate_key",
83825 + [48248].param3 = 1,
83826 + [4829].file = "drivers/block/floppy.c",
83827 + [4829].name = "fd_copyout",
83828 + [4829].param3 = 1,
83829 + [48632].file = "net/bluetooth/l2cap_core.c",
83830 + [48632].name = "l2cap_build_cmd",
83831 + [48632].param4 = 1,
83832 + [48642].file = "fs/hugetlbfs/inode.c",
83833 + [48642].name = "hugetlbfs_read",
83834 + [48642].param3 = 1,
83835 + [48720].file = "drivers/gpu/drm/i915/i915_debugfs.c",
83836 + [48720].name = "i915_max_freq_write",
83837 + [48720].param3 = 1,
83838 + [48768].file = "net/irda/irnet/irnet_ppp.c",
83839 + [48768].name = "dev_irnet_write",
83840 + [48768].param3 = 1,
83841 + [48818].file = "net/sunrpc/svc.c",
83842 + [48818].name = "svc_pool_map_alloc_arrays",
83843 + [48818].param2 = 1,
83844 + [48856].file = "drivers/acpi/acpica/utalloc.c",
83845 + [48856].name = "acpi_ut_initialize_buffer",
83846 + [48856].param2 = 1,
83847 + [48862].file = "net/sctp/socket.c",
83848 + [48862].name = "sctp_setsockopt_adaptation_layer",
83849 + [48862].param3 = 1,
83850 + [49126].file = "lib/prio_heap.c",
83851 + [49126].name = "heap_init",
83852 + [49126].param2 = 1,
83853 + [49143].file = "sound/core/oss/pcm_oss.c",
83854 + [49143].name = "snd_pcm_oss_write2",
83855 + [49143].param3 = 1,
83856 + [49216].file = "fs/read_write.c",
83857 + [49216].name = "do_readv_writev",
83858 + [49216].param4 = 1,
83859 + [49426].file = "net/bluetooth/l2cap_sock.c",
83860 + [49426].name = "l2cap_sock_setsockopt_old",
83861 + [49426].param4 = 1,
83862 + [49448].file = "drivers/isdn/gigaset/common.c",
83863 + [49448].name = "gigaset_initdriver",
83864 + [49448].param2 = 1,
83865 + [49494].file = "drivers/virtio/virtio_ring.c",
83866 + [49494].name = "vring_new_virtqueue",
83867 + [49494].param1 = 1,
83868 + [49499].file = "drivers/block/nvme.c",
83869 + [49499].name = "nvme_alloc_iod",
83870 + [49499].param1 = 1,
83871 + [49510].file = "net/sctp/socket.c",
83872 + [49510].name = "sctp_setsockopt_autoclose",
83873 + [49510].param3 = 1,
83874 + [4958].file = "drivers/net/wireless/p54/fwio.c",
83875 + [4958].name = "p54_alloc_skb",
83876 + [4958].param3 = 1,
83877 + [49604].file = "crypto/af_alg.c",
83878 + [49604].name = "alg_setsockopt",
83879 + [49604].param5 = 1,
83880 + [49646].file = "drivers/tty/vt/vt.c",
83881 + [49646].name = "vc_resize",
83882 + [49646].param2 = 1,
83883 + [49646].param3 = 1,
83884 + [49658].file = "drivers/net/wireless/brcm80211/brcmsmac/dma.c",
83885 + [49658].name = "dma_attach",
83886 + [49658].param6 = 1,
83887 + [49658].param7 = 1,
83888 + [49663].file = "drivers/media/video/uvc/uvc_driver.c",
83889 + [49663].name = "uvc_simplify_fraction",
83890 + [49663].param3 = 1,
83891 + [49746].file = "net/ipv4/netfilter/arp_tables.c",
83892 + [49746].name = "compat_do_arpt_set_ctl",
83893 + [49746].param4 = 1,
83894 + [49780].file = "net/mac80211/key.c",
83895 + [49780].name = "ieee80211_key_alloc",
83896 + [49780].param3 = 1,
83897 + [49805].file = "drivers/pci/pci.c",
83898 + [49805].name = "pci_add_cap_save_buffer",
83899 + [49805].param3 = 1,
83900 + [49845].file = "mm/vmalloc.c",
83901 + [49845].name = "__vmalloc_node",
83902 + [49845].param1 = 1,
83903 + [49929].file = "drivers/mtd/ubi/cdev.c",
83904 + [49929].name = "vol_cdev_direct_write",
83905 + [49929].param3 = 1,
83906 + [49935].file = "fs/xfs/kmem.c",
83907 + [49935].name = "kmem_zalloc_greedy",
83908 + [49935].param2 = 1,
83909 + [49935].param3 = 1,
83910 + [49].file = "net/atm/svc.c",
83911 + [49].name = "svc_setsockopt",
83912 + [49].param5 = 1,
83913 + [50518].file = "drivers/gpu/drm/nouveau/nouveau_gem.c",
83914 + [50518].name = "u_memcpya",
83915 + [50518].param2 = 1,
83916 + [50518].param3 = 1,
83917 + [5052].file = "drivers/char/ppdev.c",
83918 + [5052].name = "pp_read",
83919 + [5052].param3 = 1,
83920 + [50562].file = "drivers/media/video/zoran/zoran_procfs.c",
83921 + [50562].name = "zoran_write",
83922 + [50562].param3 = 1,
83923 + [50617].file = "fs/hugetlbfs/inode.c",
83924 + [50617].name = "hugetlbfs_read_actor",
83925 + [50617].param2 = 1,
83926 + [50617].param4 = 1,
83927 + [50617].param5 = 1,
83928 + [50692].file = "lib/ts_bm.c",
83929 + [50692].name = "bm_init",
83930 + [50692].param2 = 1,
83931 + [50813].file = "mm/vmalloc.c",
83932 + [50813].name = "__vmalloc_node_flags",
83933 + [50813].param1 = 1,
83934 + [5087].file = "drivers/atm/solos-pci.c",
83935 + [5087].name = "console_store",
83936 + [5087].param4 = 1,
83937 + [5102].file = "drivers/usb/misc/usbtest.c",
83938 + [5102].name = "usbtest_alloc_urb",
83939 + [5102].param3 = 1,
83940 + [5102].param5 = 1,
83941 + [51061].file = "net/bluetooth/mgmt.c",
83942 + [51061].name = "pin_code_reply",
83943 + [51061].param4 = 1,
83944 + [51139].file = "fs/pipe.c",
83945 + [51139].name = "pipe_iov_copy_to_user",
83946 + [51139].param3 = 1,
83947 + [51177].file = "net/sunrpc/xprtrdma/transport.c",
83948 + [51177].name = "xprt_rdma_allocate",
83949 + [51177].param2 = 1,
83950 + [51182].file = "drivers/misc/sgi-xp/xpc_main.c",
83951 + [51182].name = "xpc_kzalloc_cacheline_aligned",
83952 + [51182].param1 = 1,
83953 + [51250].file = "fs/read_write.c",
83954 + [51250].name = "rw_copy_check_uvector",
83955 + [51250].param3 = 1,
83956 + [51253].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83957 + [51253].name = "rt2x00debug_write_eeprom",
83958 + [51253].param3 = 1,
83959 + [51323].file = "sound/pci/ac97/ac97_pcm.c",
83960 + [51323].name = "snd_ac97_pcm_assign",
83961 + [51323].param2 = 1,
83962 + [51340].file = "drivers/usb/class/usblp.c",
83963 + [51340].name = "usblp_write",
83964 + [51340].param3 = 1,
83965 + [51499].file = "net/802/garp.c",
83966 + [51499].name = "garp_attr_create",
83967 + [51499].param3 = 1,
83968 + [51842].file = "drivers/hid/hid-core.c",
83969 + [51842].name = "hid_register_field",
83970 + [51842].param2 = 1,
83971 + [51842].param3 = 1,
83972 + [5197].file = "net/core/dev.c",
83973 + [5197].name = "dev_set_alias",
83974 + [5197].param3 = 1,
83975 + [5204].file = "drivers/media/video/usbvision/usbvision-video.c",
83976 + [5204].name = "usbvision_v4l2_read",
83977 + [5204].param3 = 1,
83978 + [5206].file = "drivers/media/dvb/ttpci/av7110_v4l.c",
83979 + [5206].name = "av7110_vbi_write",
83980 + [5206].param3 = 1,
83981 + [52086].file = "drivers/usb/image/mdc800.c",
83982 + [52086].name = "mdc800_device_read",
83983 + [52086].param3 = 1,
83984 + [52099].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
83985 + [52099].name = "do_surface_dirty_sou",
83986 + [52099].param7 = 1,
83987 + [52172].file = "drivers/pcmcia/cistpl.c",
83988 + [52172].name = "pccard_store_cis",
83989 + [52172].param6 = 1,
83990 + [52173].file = "drivers/misc/ibmasm/ibmasmfs.c",
83991 + [52173].name = "remote_settings_file_write",
83992 + [52173].param3 = 1,
83993 + [52199].file = "mm/nobootmem.c",
83994 + [52199].name = "__alloc_bootmem",
83995 + [52199].param1 = 1,
83996 + [52343].file = "drivers/usb/misc/adutux.c",
83997 + [52343].name = "adu_read",
83998 + [52343].param3 = 1,
83999 + [52401].file = "drivers/staging/rtl8712/rtl871x_ioctl_linux.c",
84000 + [52401].name = "r871x_set_wpa_ie",
84001 + [52401].param3 = 1,
84002 + [52699].file = "lib/ts_fsm.c",
84003 + [52699].name = "fsm_init",
84004 + [52699].param2 = 1,
84005 + [52721].file = "security/keys/encrypted-keys/encrypted.c",
84006 + [52721].name = "encrypted_instantiate",
84007 + [52721].param3 = 1,
84008 + [52902].file = "fs/xfs/kmem.h",
84009 + [52902].name = "kmem_zalloc_large",
84010 + [52902].param1 = 1,
84011 + [52950].file = "net/bluetooth/mgmt.c",
84012 + [52950].name = "set_discoverable",
84013 + [52950].param4 = 1,
84014 + [53041].file = "fs/libfs.c",
84015 + [53041].name = "simple_transaction_get",
84016 + [53041].param3 = 1,
84017 + [5313].file = "fs/gfs2/quota.c",
84018 + [5313].name = "do_sync",
84019 + [5313].param1 = 1,
84020 + [53209].file = "drivers/usb/host/ehci-sched.c",
84021 + [53209].name = "iso_sched_alloc",
84022 + [53209].param1 = 1,
84023 + [53302].file = "drivers/firewire/core-cdev.c",
84024 + [53302].name = "dispatch_ioctl",
84025 + [53302].param2 = 1,
84026 + [53355].file = "fs/ceph/dir.c",
84027 + [53355].name = "ceph_read_dir",
84028 + [53355].param3 = 1,
84029 + [53405].file = "drivers/media/video/videobuf-core.c",
84030 + [53405].name = "__videobuf_copy_to_user",
84031 + [53405].param4 = 1,
84032 + [53407].file = "net/wireless/sme.c",
84033 + [53407].name = "cfg80211_connect_result",
84034 + [53407].param4 = 1,
84035 + [53407].param6 = 1,
84036 + [53426].file = "fs/libfs.c",
84037 + [53426].name = "simple_transaction_read",
84038 + [53426].param3 = 1,
84039 + [5344].file = "security/selinux/ss/hashtab.c",
84040 + [5344].name = "hashtab_create",
84041 + [5344].param3 = 1,
84042 + [53513].file = "drivers/mmc/core/mmc_ops.c",
84043 + [53513].name = "mmc_send_bus_test",
84044 + [53513].param4 = 1,
84045 + [53626].file = "drivers/block/paride/pg.c",
84046 + [53626].name = "pg_read",
84047 + [53626].param3 = 1,
84048 + [53631].file = "mm/util.c",
84049 + [53631].name = "memdup_user",
84050 + [53631].param2 = 1,
84051 + [53674].file = "drivers/media/dvb/ttpci/av7110_ca.c",
84052 + [53674].name = "ci_ll_write",
84053 + [53674].param4 = 1,
84054 + [5389].file = "drivers/infiniband/core/uverbs_cmd.c",
84055 + [5389].name = "ib_uverbs_unmarshall_recv",
84056 + [5389].param5 = 1,
84057 + [53901].file = "net/rds/message.c",
84058 + [53901].name = "rds_message_alloc",
84059 + [53901].param1 = 1,
84060 + [53902].file = "net/sctp/socket.c",
84061 + [53902].name = "sctp_setsockopt_initmsg",
84062 + [53902].param3 = 1,
84063 + [5410].file = "kernel/kexec.c",
84064 + [5410].name = "sys_kexec_load",
84065 + [5410].param2 = 1,
84066 + [54172].file = "net/nfc/core.c",
84067 + [54172].name = "nfc_alloc_recv_skb",
84068 + [54172].param1 = 1,
84069 + [54182].file = "drivers/block/rbd.c",
84070 + [54182].name = "rbd_snap_add",
84071 + [54182].param4 = 1,
84072 + [54201].file = "drivers/platform/x86/asus_acpi.c",
84073 + [54201].name = "mled_proc_write",
84074 + [54201].param3 = 1,
84075 + [54263].file = "security/keys/trusted.c",
84076 + [54263].name = "trusted_instantiate",
84077 + [54263].param3 = 1,
84078 + [54296].file = "include/linux/mISDNif.h",
84079 + [54296].name = "_alloc_mISDN_skb",
84080 + [54296].param3 = 1,
84081 + [54298].file = "drivers/usb/wusbcore/crypto.c",
84082 + [54298].name = "wusb_ccm_mac",
84083 + [54298].param7 = 1,
84084 + [54318].file = "include/drm/drm_mem_util.h",
84085 + [54318].name = "drm_malloc_ab",
84086 + [54318].param1 = 1,
84087 + [54318].param2 = 1,
84088 + [54335].file = "drivers/md/dm-table.c",
84089 + [54335].name = "dm_vcalloc",
84090 + [54335].param1 = 1,
84091 + [54335].param2 = 1,
84092 + [54338].file = "fs/ntfs/malloc.h",
84093 + [54338].name = "ntfs_malloc_nofs",
84094 + [54338].param1 = 1,
84095 + [54339].file = "security/smack/smackfs.c",
84096 + [54339].name = "smk_write_cipso",
84097 + [54339].param3 = 1,
84098 + [54369].file = "drivers/usb/storage/realtek_cr.c",
84099 + [54369].name = "rts51x_read_mem",
84100 + [54369].param4 = 1,
84101 + [5438].file = "sound/core/memory.c",
84102 + [5438].name = "copy_to_user_fromio",
84103 + [5438].param3 = 1,
84104 + [54401].file = "lib/dynamic_debug.c",
84105 + [54401].name = "ddebug_proc_write",
84106 + [54401].param3 = 1,
84107 + [54467].file = "net/packet/af_packet.c",
84108 + [54467].name = "packet_setsockopt",
84109 + [54467].param5 = 1,
84110 + [54573].file = "ipc/sem.c",
84111 + [54573].name = "sys_semop",
84112 + [54573].param3 = 1,
84113 + [54583].file = "net/sctp/socket.c",
84114 + [54583].name = "sctp_setsockopt_peer_addr_params",
84115 + [54583].param3 = 1,
84116 + [54643].file = "drivers/isdn/hardware/eicon/divasi.c",
84117 + [54643].name = "um_idi_write",
84118 + [54643].param3 = 1,
84119 + [54657].file = "mm/migrate.c",
84120 + [54657].name = "do_pages_stat",
84121 + [54657].param2 = 1,
84122 + [54663].file = "drivers/isdn/hardware/eicon/platform.h",
84123 + [54663].name = "diva_os_malloc",
84124 + [54663].param2 = 1,
84125 + [54701].file = "drivers/misc/altera-stapl/altera-jtag.c",
84126 + [54701].name = "altera_swap_ir",
84127 + [54701].param2 = 1,
84128 + [54751].file = "drivers/infiniband/core/device.c",
84129 + [54751].name = "ib_alloc_device",
84130 + [54751].param1 = 1,
84131 + [54771].file = "drivers/isdn/mISDN/socket.c",
84132 + [54771].name = "_l2_alloc_skb",
84133 + [54771].param1 = 1,
84134 + [54777].file = "drivers/net/wireless/ath/ath6kl/debug.c",
84135 + [54777].name = "ath6kl_debug_roam_tbl_event",
84136 + [54777].param3 = 1,
84137 + [54806].file = "drivers/scsi/lpfc/lpfc_debugfs.c",
84138 + [54806].name = "lpfc_debugfs_dif_err_write",
84139 + [54806].param3 = 1,
84140 + [5494].file = "fs/cifs/cifsacl.c",
84141 + [5494].name = "cifs_idmap_key_instantiate",
84142 + [5494].param3 = 1,
84143 + [55066].file = "net/ipv6/ipv6_sockglue.c",
84144 + [55066].name = "do_ipv6_setsockopt",
84145 + [55066].param5 = 1,
84146 + [55105].file = "drivers/base/devres.c",
84147 + [55105].name = "devres_alloc",
84148 + [55105].param2 = 1,
84149 + [55115].file = "net/sctp/probe.c",
84150 + [55115].name = "sctpprobe_read",
84151 + [55115].param3 = 1,
84152 + [55155].file = "net/bluetooth/rfcomm/sock.c",
84153 + [55155].name = "rfcomm_sock_setsockopt",
84154 + [55155].param5 = 1,
84155 + [55187].file = "security/keys/keyctl.c",
84156 + [55187].name = "keyctl_describe_key",
84157 + [55187].param3 = 1,
84158 + [55253].file = "drivers/net/wireless/ray_cs.c",
84159 + [55253].name = "ray_cs_essid_proc_write",
84160 + [55253].param3 = 1,
84161 + [55341].file = "drivers/staging/sep/sep_driver.c",
84162 + [55341].name = "sep_prepare_input_output_dma_table_in_dcb",
84163 + [55341].param4 = 1,
84164 + [55341].param5 = 1,
84165 + [55417].file = "drivers/hv/channel.c",
84166 + [55417].name = "vmbus_open",
84167 + [55417].param2 = 1,
84168 + [55417].param3 = 1,
84169 + [5548].file = "drivers/media/media-entity.c",
84170 + [5548].name = "media_entity_init",
84171 + [5548].param2 = 1,
84172 + [5548].param4 = 1,
84173 + [55546].file = "drivers/spi/spi.c",
84174 + [55546].name = "spi_alloc_master",
84175 + [55546].param2 = 1,
84176 + [55580].file = "drivers/usb/mon/mon_bin.c",
84177 + [55580].name = "copy_from_buf",
84178 + [55580].param2 = 1,
84179 + [55584].file = "drivers/tty/tty_buffer.c",
84180 + [55584].name = "tty_buffer_alloc",
84181 + [55584].param2 = 1,
84182 + [55712].file = "drivers/char/mem.c",
84183 + [55712].name = "read_zero",
84184 + [55712].param3 = 1,
84185 + [55727].file = "drivers/media/video/stk-webcam.c",
84186 + [55727].name = "stk_prepare_sio_buffers",
84187 + [55727].param2 = 1,
84188 + [55816].file = "drivers/misc/altera-stapl/altera-jtag.c",
84189 + [55816].name = "altera_set_ir_pre",
84190 + [55816].param2 = 1,
84191 + [55826].file = "drivers/infiniband/hw/ipath/ipath_file_ops.c",
84192 + [55826].name = "ipath_get_base_info",
84193 + [55826].param3 = 1,
84194 + [5586].file = "net/atm/common.c",
84195 + [5586].name = "alloc_tx",
84196 + [5586].param2 = 1,
84197 + [55978].file = "drivers/usb/misc/iowarrior.c",
84198 + [55978].name = "iowarrior_write",
84199 + [55978].param3 = 1,
84200 + [56170].file = "drivers/usb/wusbcore/wa-xfer.c",
84201 + [56170].name = "__wa_xfer_setup_segs",
84202 + [56170].param2 = 1,
84203 + [56199].file = "fs/binfmt_misc.c",
84204 + [56199].name = "parse_command",
84205 + [56199].param2 = 1,
84206 + [56218].file = "drivers/mmc/card/mmc_test.c",
84207 + [56218].name = "mtf_test_write",
84208 + [56218].param3 = 1,
84209 + [56239].file = "fs/sysfs/file.c",
84210 + [56239].name = "fill_write_buffer",
84211 + [56239].param3 = 1,
84212 + [5624].file = "drivers/net/wireless/ath/ath9k/wmi.c",
84213 + [5624].name = "ath9k_wmi_cmd",
84214 + [5624].param4 = 1,
84215 + [56416].file = "drivers/misc/lkdtm.c",
84216 + [56416].name = "do_register_entry",
84217 + [56416].param4 = 1,
84218 + [56458].file = "drivers/usb/host/hwa-hc.c",
84219 + [56458].name = "__hwahc_op_set_ptk",
84220 + [56458].param5 = 1,
84221 + [56471].file = "include/linux/slab.h",
84222 + [56471].name = "kcalloc",
84223 + [56471].param1 = 1,
84224 + [56471].param2 = 1,
84225 + [56513].file = "fs/cifs/connect.c",
84226 + [56513].name = "cifs_readv_from_socket",
84227 + [56513].param3 = 1,
84228 + [56531].file = "net/bluetooth/l2cap_core.c",
84229 + [56531].name = "l2cap_send_cmd",
84230 + [56531].param4 = 1,
84231 + [56544].file = "drivers/block/drbd/drbd_receiver.c",
84232 + [56544].name = "receive_DataRequest",
84233 + [56544].param3 = 1,
84234 + [56609].file = "lib/mpi/mpi-internal.h",
84235 + [56609].name = "RESIZE_IF_NEEDED",
84236 + [56609].param2 = 1,
84237 + [56652].file = "drivers/misc/altera-stapl/altera-jtag.c",
84238 + [56652].name = "altera_set_dr_post",
84239 + [56652].param2 = 1,
84240 + [56653].file = "net/irda/af_irda.c",
84241 + [56653].name = "irda_setsockopt",
84242 + [56653].param5 = 1,
84243 + [56672].file = "drivers/char/agp/generic.c",
84244 + [56672].name = "agp_alloc_page_array",
84245 + [56672].param1 = 1,
84246 + [56798].file = "fs/bio.c",
84247 + [56798].name = "bio_alloc_map_data",
84248 + [56798].param2 = 1,
84249 + [56843].file = "drivers/scsi/scsi_transport_iscsi.c",
84250 + [56843].name = "iscsi_recv_pdu",
84251 + [56843].param4 = 1,
84252 + [56903].file = "drivers/mtd/mtdchar.c",
84253 + [56903].name = "mtdchar_readoob",
84254 + [56903].param4 = 1,
84255 + [5699].file = "net/sctp/socket.c",
84256 + [5699].name = "sctp_setsockopt_default_send_param",
84257 + [5699].param3 = 1,
84258 + [5704].file = "drivers/mtd/mtdswap.c",
84259 + [5704].name = "mtdswap_init",
84260 + [5704].param2 = 1,
84261 + [57128].file = "drivers/pnp/pnpbios/proc.c",
84262 + [57128].name = "pnpbios_proc_write",
84263 + [57128].param3 = 1,
84264 + [57190].file = "drivers/char/agp/generic.c",
84265 + [57190].name = "agp_generic_alloc_user",
84266 + [57190].param1 = 1,
84267 + [57252].file = "drivers/media/dvb/dvb-core/dmxdev.c",
84268 + [57252].name = "dvb_dmxdev_set_buffer_size",
84269 + [57252].param2 = 1,
84270 + [57392].file = "drivers/block/aoe/aoecmd.c",
84271 + [57392].name = "new_skb",
84272 + [57392].param1 = 1,
84273 + [57471].file = "drivers/media/video/sn9c102/sn9c102_core.c",
84274 + [57471].name = "sn9c102_read",
84275 + [57471].param3 = 1,
84276 + [57547].file = "security/keys/encrypted-keys/encrypted.c",
84277 + [57547].name = "get_derived_key",
84278 + [57547].param4 = 1,
84279 + [57552].file = "net/sunrpc/cache.c",
84280 + [57552].name = "cache_slow_downcall",
84281 + [57552].param2 = 1,
84282 + [57670].file = "drivers/bluetooth/btmrvl_debugfs.c",
84283 + [57670].name = "btmrvl_pscmd_write",
84284 + [57670].param3 = 1,
84285 + [57710].file = "include/linux/usb/wusb.h",
84286 + [57710].name = "wusb_prf_256",
84287 + [57710].param7 = 1,
84288 + [57724].file = "net/bluetooth/hci_sock.c",
84289 + [57724].name = "hci_sock_setsockopt",
84290 + [57724].param5 = 1,
84291 + [57761].file = "kernel/kexec.c",
84292 + [57761].name = "kimage_crash_alloc",
84293 + [57761].param3 = 1,
84294 + [57786].file = "net/ipv6/netfilter/ip6_tables.c",
84295 + [57786].name = "compat_do_ip6t_set_ctl",
84296 + [57786].param4 = 1,
84297 + [57872].file = "fs/ceph/xattr.c",
84298 + [57872].name = "ceph_setxattr",
84299 + [57872].param4 = 1,
84300 + [57927].file = "fs/read_write.c",
84301 + [57927].name = "sys_preadv",
84302 + [57927].param3 = 1,
84303 + [58012].file = "include/net/bluetooth/bluetooth.h",
84304 + [58012].name = "bt_skb_alloc",
84305 + [58012].param1 = 1,
84306 + [58020].file = "drivers/firewire/core-cdev.c",
84307 + [58020].name = "fw_device_op_ioctl",
84308 + [58020].param2 = 1,
84309 + [58043].file = "kernel/auditfilter.c",
84310 + [58043].name = "audit_unpack_string",
84311 + [58043].param3 = 1,
84312 + [58087].file = "kernel/module.c",
84313 + [58087].name = "module_alloc_update_bounds_rw",
84314 + [58087].param1 = 1,
84315 + [58124].file = "drivers/usb/misc/usbtest.c",
84316 + [58124].name = "ctrl_out",
84317 + [58124].param3 = 1,
84318 + [58124].param5 = 1,
84319 + [58217].file = "net/sctp/socket.c",
84320 + [58217].name = "sctp_setsockopt_peer_primary_addr",
84321 + [58217].param3 = 1,
84322 + [58263].file = "security/keys/keyring.c",
84323 + [58263].name = "keyring_read",
84324 + [58263].param3 = 1,
84325 + [5830].file = "drivers/gpu/vga/vga_switcheroo.c",
84326 + [5830].name = "vga_switcheroo_debugfs_write",
84327 + [5830].param3 = 1,
84328 + [58320].file = "drivers/scsi/scsi_proc.c",
84329 + [58320].name = "proc_scsi_write",
84330 + [58320].param3 = 1,
84331 + [58344].file = "net/sunrpc/cache.c",
84332 + [58344].name = "read_flush",
84333 + [58344].param3 = 1,
84334 + [58379].file = "mm/nobootmem.c",
84335 + [58379].name = "__alloc_bootmem_node",
84336 + [58379].param2 = 1,
84337 + [58597].file = "kernel/kfifo.c",
84338 + [58597].name = "__kfifo_to_user",
84339 + [58597].param3 = 1,
84340 + [58641].file = "drivers/usb/misc/adutux.c",
84341 + [58641].name = "adu_write",
84342 + [58641].param3 = 1,
84343 + [58709].file = "fs/compat.c",
84344 + [58709].name = "compat_sys_pwritev",
84345 + [58709].param3 = 1,
84346 + [58769].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
84347 + [58769].name = "zd_usb_read_fw",
84348 + [58769].param4 = 1,
84349 + [5876].file = "drivers/net/ppp/ppp_generic.c",
84350 + [5876].name = "ppp_write",
84351 + [5876].param3 = 1,
84352 + [58826].file = "net/sunrpc/xprt.c",
84353 + [58826].name = "xprt_alloc",
84354 + [58826].param2 = 1,
84355 + [58865].file = "include/linux/slub_def.h",
84356 + [58865].name = "kmalloc_order_trace",
84357 + [58865].param1 = 1,
84358 + [58867].file = "drivers/platform/x86/asus_acpi.c",
84359 + [58867].name = "wled_proc_write",
84360 + [58867].param3 = 1,
84361 + [58888].file = "fs/xattr.c",
84362 + [58888].name = "listxattr",
84363 + [58888].param3 = 1,
84364 + [58889].file = "kernel/trace/trace_kprobe.c",
84365 + [58889].name = "probes_write",
84366 + [58889].param3 = 1,
84367 + [58912].file = "drivers/lguest/core.c",
84368 + [58912].name = "__lgwrite",
84369 + [58912].param4 = 1,
84370 + [58918].file = "sound/core/pcm_native.c",
84371 + [58918].name = "snd_pcm_aio_write",
84372 + [58918].param3 = 1,
84373 + [58942].file = "drivers/block/aoe/aoedev.c",
84374 + [58942].name = "aoedev_flush",
84375 + [58942].param2 = 1,
84376 + [58958].file = "fs/fuse/control.c",
84377 + [58958].name = "fuse_conn_limit_write",
84378 + [58958].param3 = 1,
84379 + [59005].file = "drivers/staging/sep/sep_driver.c",
84380 + [59005].name = "sep_prepare_input_dma_table",
84381 + [59005].param2 = 1,
84382 + [59005].param3 = 1,
84383 + [59013].file = "fs/xfs/xfs_ioctl.c",
84384 + [59013].name = "xfs_handle_to_dentry",
84385 + [59013].param3 = 1,
84386 + [59034].file = "drivers/acpi/acpica/dsobject.c",
84387 + [59034].name = "acpi_ds_build_internal_package_obj",
84388 + [59034].param3 = 1,
84389 + [59073].file = "drivers/staging/speakup/i18n.c",
84390 + [59073].name = "msg_set",
84391 + [59073].param3 = 1,
84392 + [59074].file = "drivers/scsi/cxgbi/libcxgbi.c",
84393 + [59074].name = "ddp_make_gl",
84394 + [59074].param1 = 1,
84395 + [59297].file = "drivers/media/dvb/ttpci/av7110_av.c",
84396 + [59297].name = "dvb_play",
84397 + [59297].param3 = 1,
84398 + [59472].file = "drivers/misc/ibmasm/ibmasmfs.c",
84399 + [59472].name = "command_file_write",
84400 + [59472].param3 = 1,
84401 + [59504].file = "fs/exofs/super.c",
84402 + [59504].name = "__alloc_dev_table",
84403 + [59504].param2 = 1,
84404 + [59505].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
84405 + [59505].name = "pvr2_ioread_read",
84406 + [59505].param3 = 1,
84407 + [59681].file = "fs/xfs/kmem.c",
84408 + [59681].name = "kmem_alloc",
84409 + [59681].param1 = 1,
84410 + [5968].file = "net/sunrpc/sched.c",
84411 + [5968].name = "rpc_malloc",
84412 + [5968].param2 = 1,
84413 + [59695].file = "net/ipv4/netfilter/ipt_ULOG.c",
84414 + [59695].name = "ulog_alloc_skb",
84415 + [59695].param1 = 1,
84416 + [59838].file = "net/netlink/af_netlink.c",
84417 + [59838].name = "nl_pid_hash_zalloc",
84418 + [59838].param1 = 1,
84419 + [59856].file = "drivers/base/devres.c",
84420 + [59856].name = "devm_kzalloc",
84421 + [59856].param2 = 1,
84422 + [60066].file = "mm/filemap.c",
84423 + [60066].name = "iov_iter_copy_from_user",
84424 + [60066].param4 = 1,
84425 + [60185].file = "kernel/params.c",
84426 + [60185].name = "kmalloc_parameter",
84427 + [60185].param1 = 1,
84428 + [60198].file = "fs/nfs/nfs4proc.c",
84429 + [60198].name = "nfs4_write_cached_acl",
84430 + [60198].param3 = 1,
84431 + [60330].file = "drivers/media/video/w9966.c",
84432 + [60330].name = "w9966_v4l_read",
84433 + [60330].param3 = 1,
84434 + [604].file = "drivers/staging/rtl8712/usb_ops_linux.c",
84435 + [604].name = "r8712_usbctrl_vendorreq",
84436 + [604].param6 = 1,
84437 + [60543].file = "drivers/usb/class/usbtmc.c",
84438 + [60543].name = "usbtmc_read",
84439 + [60543].param3 = 1,
84440 + [60683].file = "sound/drivers/opl4/opl4_proc.c",
84441 + [60683].name = "snd_opl4_mem_proc_write",
84442 + [60683].param5 = 1,
84443 + [60693].file = "drivers/misc/hpilo.c",
84444 + [60693].name = "ilo_read",
84445 + [60693].param3 = 1,
84446 + [60744].file = "sound/pci/emu10k1/emuproc.c",
84447 + [60744].name = "snd_emu10k1_fx8010_read",
84448 + [60744].param5 = 1,
84449 + [60777].file = "fs/ntfs/malloc.h",
84450 + [60777].name = "ntfs_malloc_nofs_nofail",
84451 + [60777].param1 = 1,
84452 + [60833].file = "drivers/block/aoe/aoenet.c",
84453 + [60833].name = "set_aoe_iflist",
84454 + [60833].param2 = 1,
84455 + [60882].file = "drivers/input/joydev.c",
84456 + [60882].name = "joydev_compat_ioctl",
84457 + [60882].param2 = 1,
84458 + [60891].file = "kernel/sched/core.c",
84459 + [60891].name = "sys_sched_setaffinity",
84460 + [60891].param2 = 1,
84461 + [60920].file = "drivers/infiniband/hw/qib/qib_file_ops.c",
84462 + [60920].name = "qib_get_base_info",
84463 + [60920].param3 = 1,
84464 + [60928].file = "drivers/staging/bcm/Bcmchar.c",
84465 + [60928].name = "bcm_char_read",
84466 + [60928].param3 = 1,
84467 + [61122].file = "drivers/base/devres.c",
84468 + [61122].name = "alloc_dr",
84469 + [61122].param2 = 1,
84470 + [61254].file = "drivers/scsi/scsi_devinfo.c",
84471 + [61254].name = "proc_scsi_devinfo_write",
84472 + [61254].param3 = 1,
84473 + [61283].file = "drivers/net/wireless/ath/ath6kl/debug.c",
84474 + [61283].name = "ath6kl_fwlog_read",
84475 + [61283].param3 = 1,
84476 + [61289].file = "security/apparmor/apparmorfs.c",
84477 + [61289].name = "aa_simple_write_to_buffer",
84478 + [61289].param4 = 1,
84479 + [61389].file = "include/linux/slab.h",
84480 + [61389].name = "kzalloc_node",
84481 + [61389].param1 = 1,
84482 + [61441].file = "fs/ntfs/file.c",
84483 + [61441].name = "ntfs_copy_from_user_iovec",
84484 + [61441].param3 = 1,
84485 + [61441].param6 = 1,
84486 + [61552].file = "drivers/input/evdev.c",
84487 + [61552].name = "str_to_user",
84488 + [61552].param2 = 1,
84489 + [61673].file = "security/keys/trusted.c",
84490 + [61673].name = "trusted_update",
84491 + [61673].param3 = 1,
84492 + [61676].file = "kernel/module.c",
84493 + [61676].name = "module_alloc_update_bounds_rx",
84494 + [61676].param1 = 1,
84495 + [61684].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
84496 + [61684].name = "cxgb3_get_cpl_reply_skb",
84497 + [61684].param2 = 1,
84498 + [6173].file = "net/netlink/af_netlink.c",
84499 + [6173].name = "netlink_sendmsg",
84500 + [6173].param4 = 1,
84501 + [61770].file = "drivers/media/video/et61x251/et61x251_core.c",
84502 + [61770].name = "et61x251_read",
84503 + [61770].param3 = 1,
84504 + [61772].file = "fs/exofs/ore_raid.c",
84505 + [61772].name = "_sp2d_alloc",
84506 + [61772].param1 = 1,
84507 + [61772].param2 = 1,
84508 + [61772].param3 = 1,
84509 + [61926].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
84510 + [61926].name = "ddb_input_read",
84511 + [61926].param3 = 1,
84512 + [61932].file = "drivers/message/fusion/mptctl.c",
84513 + [61932].name = "__mptctl_ioctl",
84514 + [61932].param2 = 1,
84515 + [61966].file = "fs/nfs/nfs4proc.c",
84516 + [61966].name = "nfs4_alloc_slots",
84517 + [61966].param1 = 1,
84518 + [62081].file = "drivers/net/irda/vlsi_ir.c",
84519 + [62081].name = "vlsi_alloc_ring",
84520 + [62081].param3 = 1,
84521 + [62081].param4 = 1,
84522 + [62116].file = "fs/libfs.c",
84523 + [62116].name = "simple_attr_read",
84524 + [62116].param3 = 1,
84525 + [6211].file = "drivers/net/ethernet/amd/pcnet32.c",
84526 + [6211].name = "pcnet32_realloc_tx_ring",
84527 + [6211].param3 = 1,
84528 + [62294].file = "sound/core/info.c",
84529 + [62294].name = "resize_info_buffer",
84530 + [62294].param2 = 1,
84531 + [62387].file = "fs/nfs/idmap.c",
84532 + [62387].name = "nfs_idmap_lookup_id",
84533 + [62387].param2 = 1,
84534 + [62465].file = "drivers/misc/altera-stapl/altera-jtag.c",
84535 + [62465].name = "altera_set_dr_pre",
84536 + [62465].param2 = 1,
84537 + [62466].file = "lib/mpi/mpiutil.c",
84538 + [62466].name = "mpi_alloc",
84539 + [62466].param1 = 1,
84540 + [62495].file = "drivers/block/floppy.c",
84541 + [62495].name = "fallback_on_nodma_alloc",
84542 + [62495].param2 = 1,
84543 + [62498].file = "fs/xattr.c",
84544 + [62498].name = "sys_listxattr",
84545 + [62498].param3 = 1,
84546 + [625].file = "fs/read_write.c",
84547 + [625].name = "sys_pwritev",
84548 + [625].param3 = 1,
84549 + [62662].file = "drivers/message/fusion/mptctl.c",
84550 + [62662].name = "mptctl_getiocinfo",
84551 + [62662].param2 = 1,
84552 + [62669].file = "drivers/platform/x86/asus_acpi.c",
84553 + [62669].name = "tled_proc_write",
84554 + [62669].param3 = 1,
84555 + [62714].file = "security/keys/keyctl.c",
84556 + [62714].name = "keyctl_update_key",
84557 + [62714].param3 = 1,
84558 + [62760].file = "drivers/media/dvb/ttpci/av7110_av.c",
84559 + [62760].name = "play_iframe",
84560 + [62760].param3 = 1,
84561 + [62851].file = "fs/proc/vmcore.c",
84562 + [62851].name = "read_vmcore",
84563 + [62851].param3 = 1,
84564 + [62870].file = "fs/nfs/idmap.c",
84565 + [62870].name = "nfs_idmap_get_desc",
84566 + [62870].param2 = 1,
84567 + [62870].param4 = 1,
84568 + [62905].file = "net/caif/cfpkt_skbuff.c",
84569 + [62905].name = "cfpkt_create",
84570 + [62905].param1 = 1,
84571 + [62920].file = "drivers/net/wireless/b43/phy_n.c",
84572 + [62920].name = "b43_nphy_load_samples",
84573 + [62920].param3 = 1,
84574 + [62925].file = "include/rdma/ib_verbs.h",
84575 + [62925].name = "ib_copy_from_udata",
84576 + [62925].param3 = 1,
84577 + [62934].file = "drivers/net/wireless/wl1251/cmd.c",
84578 + [62934].name = "wl1251_cmd_template_set",
84579 + [62934].param4 = 1,
84580 + [62940].file = "drivers/scsi/libsrp.c",
84581 + [62940].name = "srp_ring_alloc",
84582 + [62940].param2 = 1,
84583 + [62967].file = "security/keys/encrypted-keys/encrypted.c",
84584 + [62967].name = "encrypted_update",
84585 + [62967].param3 = 1,
84586 + [62970].file = "net/sched/sch_api.c",
84587 + [62970].name = "qdisc_class_hash_alloc",
84588 + [62970].param1 = 1,
84589 + [62999].file = "net/core/neighbour.c",
84590 + [62999].name = "neigh_hash_alloc",
84591 + [62999].param1 = 1,
84592 + [63007].file = "fs/proc/base.c",
84593 + [63007].name = "proc_coredump_filter_write",
84594 + [63007].param3 = 1,
84595 + [63010].file = "drivers/gpu/drm/ttm/ttm_page_alloc.c",
84596 + [63010].name = "ttm_page_pool_free",
84597 + [63010].param2 = 1,
84598 + [63045].file = "crypto/shash.c",
84599 + [63045].name = "shash_setkey_unaligned",
84600 + [63045].param3 = 1,
84601 + [63075].file = "kernel/relay.c",
84602 + [63075].name = "relay_alloc_page_array",
84603 + [63075].param1 = 1,
84604 + [63076].file = "fs/cifs/xattr.c",
84605 + [63076].name = "cifs_setxattr",
84606 + [63076].param4 = 1,
84607 + [63091].file = "drivers/net/usb/pegasus.c",
84608 + [63091].name = "get_registers",
84609 + [63091].param3 = 1,
84610 + [6331].file = "drivers/atm/solos-pci.c",
84611 + [6331].name = "solos_param_store",
84612 + [6331].param4 = 1,
84613 + [63367].file = "net/netfilter/ipset/ip_set_core.c",
84614 + [63367].name = "ip_set_alloc",
84615 + [63367].param1 = 1,
84616 + [63489].file = "drivers/bluetooth/btmrvl_debugfs.c",
84617 + [63489].name = "btmrvl_hscfgcmd_write",
84618 + [63489].param3 = 1,
84619 + [63490].file = "crypto/shash.c",
84620 + [63490].name = "shash_compat_setkey",
84621 + [63490].param3 = 1,
84622 + [63605].file = "mm/mempool.c",
84623 + [63605].name = "mempool_kmalloc",
84624 + [63605].param2 = 1,
84625 + [63633].file = "drivers/bluetooth/btmrvl_sdio.c",
84626 + [63633].name = "btmrvl_sdio_host_to_card",
84627 + [63633].param3 = 1,
84628 + [63961].file = "fs/xattr.c",
84629 + [63961].name = "sys_flistxattr",
84630 + [63961].param3 = 1,
84631 + [63964].file = "net/sctp/socket.c",
84632 + [63964].name = "sctp_setsockopt_maxseg",
84633 + [63964].param3 = 1,
84634 + [63988].file = "drivers/input/evdev.c",
84635 + [63988].name = "evdev_ioctl_compat",
84636 + [63988].param2 = 1,
84637 + [64055].file = "drivers/media/dvb/ttpci/av7110_av.c",
84638 + [64055].name = "dvb_aplay",
84639 + [64055].param3 = 1,
84640 + [64156].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
84641 + [64156].name = "ath6kl_mgmt_tx",
84642 + [64156].param9 = 1,
84643 + [64226].file = "drivers/md/persistent-data/dm-space-map-checker.c",
84644 + [64226].name = "ca_extend",
84645 + [64226].param2 = 1,
84646 + [64227].file = "mm/nobootmem.c",
84647 + [64227].name = "__alloc_bootmem_node_nopanic",
84648 + [64227].param2 = 1,
84649 + [64351].file = "kernel/kfifo.c",
84650 + [64351].name = "kfifo_copy_from_user",
84651 + [64351].param3 = 1,
84652 + [64392].file = "drivers/mmc/core/mmc_ops.c",
84653 + [64392].name = "mmc_send_cxd_data",
84654 + [64392].param5 = 1,
84655 + [64423].file = "kernel/sched/core.c",
84656 + [64423].name = "get_user_cpu_mask",
84657 + [64423].param2 = 1,
84658 + [64432].file = "security/selinux/selinuxfs.c",
84659 + [64432].name = "sel_write_create",
84660 + [64432].param3 = 1,
84661 + [64471].file = "drivers/bluetooth/btmrvl_debugfs.c",
84662 + [64471].name = "btmrvl_hscmd_write",
84663 + [64471].param3 = 1,
84664 + [64667].file = "sound/core/oss/pcm_oss.c",
84665 + [64667].name = "snd_pcm_oss_read",
84666 + [64667].param3 = 1,
84667 + [64689].file = "sound/isa/gus/gus_dram.c",
84668 + [64689].name = "snd_gus_dram_read",
84669 + [64689].param4 = 1,
84670 + [64692].file = "fs/binfmt_misc.c",
84671 + [64692].name = "bm_entry_write",
84672 + [64692].param3 = 1,
84673 + [64705].file = "drivers/staging/iio/accel/sca3000_ring.c",
84674 + [64705].name = "sca3000_read_first_n_hw_rb",
84675 + [64705].param2 = 1,
84676 + [64713].file = "fs/cifs/connect.c",
84677 + [64713].name = "extract_hostname",
84678 + [64713].param1 = 1,
84679 + [64743].file = "fs/ocfs2/dlmfs/dlmfs.c",
84680 + [64743].name = "dlmfs_file_read",
84681 + [64743].param3 = 1,
84682 + [64771].file = "security/keys/encrypted-keys/encrypted.c",
84683 + [64771].name = "datablob_format",
84684 + [64771].param2 = 1,
84685 + [6477].file = "net/bluetooth/mgmt.c",
84686 + [6477].name = "mgmt_pending_add",
84687 + [6477].param5 = 1,
84688 + [64906].file = "drivers/net/wireless/b43legacy/debugfs.c",
84689 + [64906].name = "b43legacy_debugfs_write",
84690 + [64906].param3 = 1,
84691 + [64913].file = "sound/core/oss/pcm_oss.c",
84692 + [64913].name = "snd_pcm_oss_write1",
84693 + [64913].param3 = 1,
84694 + [64961].file = "drivers/spi/spidev.c",
84695 + [64961].name = "spidev_ioctl",
84696 + [64961].param2 = 1,
84697 + [65033].file = "crypto/shash.c",
84698 + [65033].name = "shash_async_setkey",
84699 + [65033].param3 = 1,
84700 + [65093].file = "security/integrity/evm/evm_secfs.c",
84701 + [65093].name = "evm_write_key",
84702 + [65093].param3 = 1,
84703 + [6514].file = "mm/nobootmem.c",
84704 + [6514].name = "__alloc_bootmem_low",
84705 + [6514].param1 = 1,
84706 + [65169].file = "net/core/skbuff.c",
84707 + [65169].name = "dev_alloc_skb",
84708 + [65169].param1 = 1,
84709 + [6517].file = "drivers/md/dm-table.c",
84710 + [6517].name = "alloc_targets",
84711 + [6517].param2 = 1,
84712 + [65205].file = "drivers/input/evdev.c",
84713 + [65205].name = "handle_eviocgbit",
84714 + [65205].param3 = 1,
84715 + [65237].file = "kernel/profile.c",
84716 + [65237].name = "read_profile",
84717 + [65237].param3 = 1,
84718 + [65343].file = "kernel/trace/trace.c",
84719 + [65343].name = "tracing_clock_write",
84720 + [65343].param3 = 1,
84721 + [65345].file = "lib/xz/xz_dec_lzma2.c",
84722 + [65345].name = "xz_dec_lzma2_create",
84723 + [65345].param2 = 1,
84724 + [65409].file = "net/802/garp.c",
84725 + [65409].name = "garp_request_join",
84726 + [65409].param4 = 1,
84727 + [65432].file = "drivers/hid/hid-roccat-kone.c",
84728 + [65432].name = "kone_receive",
84729 + [65432].param4 = 1,
84730 + [65514].file = "drivers/media/video/gspca/t613.c",
84731 + [65514].name = "reg_w_ixbuf",
84732 + [65514].param4 = 1,
84733 + [6551].file = "drivers/usb/host/xhci-mem.c",
84734 + [6551].name = "xhci_alloc_stream_info",
84735 + [6551].param3 = 1,
84736 + [65535].file = "drivers/media/dvb/dvb-usb/opera1.c",
84737 + [65535].name = "opera1_xilinx_rw",
84738 + [65535].param5 = 1,
84739 + [6672].file = "drivers/net/wireless/b43/debugfs.c",
84740 + [6672].name = "b43_debugfs_write",
84741 + [6672].param3 = 1,
84742 + [6691].file = "drivers/acpi/proc.c",
84743 + [6691].name = "acpi_system_write_wakeup_device",
84744 + [6691].param3 = 1,
84745 + [6865].file = "drivers/staging/iio/ring_sw.c",
84746 + [6865].name = "iio_read_first_n_sw_rb",
84747 + [6865].param2 = 1,
84748 + [6867].file = "fs/coda/psdev.c",
84749 + [6867].name = "coda_psdev_read",
84750 + [6867].param3 = 1,
84751 + [6891].file = "drivers/bluetooth/btmrvl_debugfs.c",
84752 + [6891].name = "btmrvl_gpiogap_write",
84753 + [6891].param3 = 1,
84754 + [6944].file = "drivers/ide/ide-proc.c",
84755 + [6944].name = "ide_settings_proc_write",
84756 + [6944].param3 = 1,
84757 + [6950].file = "drivers/isdn/capi/capi.c",
84758 + [6950].name = "capi_write",
84759 + [6950].param3 = 1,
84760 + [697].file = "sound/isa/gus/gus_dram.c",
84761 + [697].name = "snd_gus_dram_peek",
84762 + [697].param4 = 1,
84763 + [7066].file = "security/keys/keyctl.c",
84764 + [7066].name = "keyctl_instantiate_key_common",
84765 + [7066].param4 = 1,
84766 + [7125].file = "include/net/nfc/nci_core.h",
84767 + [7125].name = "nci_skb_alloc",
84768 + [7125].param2 = 1,
84769 + [7129].file = "mm/maccess.c",
84770 + [7129].name = "__probe_kernel_read",
84771 + [7129].param3 = 1,
84772 + [7158].file = "kernel/trace/trace.c",
84773 + [7158].name = "tracing_read_pipe",
84774 + [7158].param3 = 1,
84775 + [720].file = "sound/pci/rme9652/hdsp.c",
84776 + [720].name = "snd_hdsp_playback_copy",
84777 + [720].param5 = 1,
84778 + [7236].file = "drivers/gpu/drm/drm_crtc.c",
84779 + [7236].name = "drm_plane_init",
84780 + [7236].param6 = 1,
84781 + [7411].file = "drivers/vhost/vhost.c",
84782 + [7411].name = "__vhost_add_used_n",
84783 + [7411].param3 = 1,
84784 + [7432].file = "net/bluetooth/mgmt.c",
84785 + [7432].name = "mgmt_event",
84786 + [7432].param4 = 1,
84787 + [7488].file = "security/keys/user_defined.c",
84788 + [7488].name = "user_read",
84789 + [7488].param3 = 1,
84790 + [7551].file = "drivers/input/touchscreen/ad7879-spi.c",
84791 + [7551].name = "ad7879_spi_xfer",
84792 + [7551].param3 = 1,
84793 + [7671].file = "mm/nobootmem.c",
84794 + [7671].name = "__alloc_bootmem_node_high",
84795 + [7671].param2 = 1,
84796 + [7676].file = "drivers/acpi/custom_method.c",
84797 + [7676].name = "cm_write",
84798 + [7676].param3 = 1,
84799 + [7693].file = "net/sctp/socket.c",
84800 + [7693].name = "sctp_setsockopt_associnfo",
84801 + [7693].param3 = 1,
84802 + [7697].file = "security/selinux/selinuxfs.c",
84803 + [7697].name = "sel_write_access",
84804 + [7697].param3 = 1,
84805 + [7843].file = "fs/compat.c",
84806 + [7843].name = "compat_sys_readv",
84807 + [7843].param3 = 1,
84808 + [7883].file = "net/sched/sch_sfq.c",
84809 + [7883].name = "sfq_alloc",
84810 + [7883].param1 = 1,
84811 + [7924].file = "drivers/media/video/cx18/cx18-fileops.c",
84812 + [7924].name = "cx18_read_pos",
84813 + [7924].param3 = 1,
84814 + [7958].file = "drivers/gpu/vga/vgaarb.c",
84815 + [7958].name = "vga_arb_write",
84816 + [7958].param3 = 1,
84817 + [7976].file = "drivers/usb/gadget/rndis.c",
84818 + [7976].name = "rndis_add_response",
84819 + [7976].param2 = 1,
84820 + [7985].file = "net/mac80211/cfg.c",
84821 + [7985].name = "ieee80211_mgmt_tx",
84822 + [7985].param9 = 1,
84823 + [8014].file = "net/netfilter/ipset/ip_set_list_set.c",
84824 + [8014].name = "init_list_set",
84825 + [8014].param2 = 1,
84826 + [8014].param3 = 1,
84827 + [8126].file = "sound/soc/soc-core.c",
84828 + [8126].name = "codec_reg_read_file",
84829 + [8126].param3 = 1,
84830 + [8317].file = "security/smack/smackfs.c",
84831 + [8317].name = "smk_write_ambient",
84832 + [8317].param3 = 1,
84833 + [8335].file = "drivers/media/dvb/dvb-core/dmxdev.c",
84834 + [8335].name = "dvb_dvr_set_buffer_size",
84835 + [8335].param2 = 1,
84836 + [8383].file = "kernel/module.c",
84837 + [8383].name = "copy_and_check",
84838 + [8383].param3 = 1,
84839 + [8411].file = "net/caif/cfpkt_skbuff.c",
84840 + [8411].name = "cfpkt_append",
84841 + [8411].param3 = 1,
84842 + [8536].file = "fs/cifs/dns_resolve.c",
84843 + [8536].name = "dns_resolve_server_name_to_ip",
84844 + [8536].param1 = 1,
84845 + [857].file = "drivers/virtio/virtio_ring.c",
84846 + [857].name = "virtqueue_add_buf",
84847 + [857].param3 = 1,
84848 + [857].param4 = 1,
84849 + [8650].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
84850 + [8650].name = "vmw_kms_present",
84851 + [8650].param9 = 1,
84852 + [8654].file = "drivers/net/wireless/mwifiex/sdio.c",
84853 + [8654].name = "mwifiex_alloc_sdio_mpa_buffers",
84854 + [8654].param2 = 1,
84855 + [8654].param3 = 1,
84856 + [865].file = "drivers/base/regmap/regmap-debugfs.c",
84857 + [865].name = "regmap_access_read_file",
84858 + [865].param3 = 1,
84859 + [8663].file = "net/bridge/netfilter/ebtables.c",
84860 + [8663].name = "do_update_counters",
84861 + [8663].param4 = 1,
84862 + [8684].file = "fs/read_write.c",
84863 + [8684].name = "sys_writev",
84864 + [8684].param3 = 1,
84865 + [8699].file = "security/selinux/selinuxfs.c",
84866 + [8699].name = "sel_commit_bools_write",
84867 + [8699].param3 = 1,
84868 + [8764].file = "drivers/usb/core/devio.c",
84869 + [8764].name = "usbdev_read",
84870 + [8764].param3 = 1,
84871 + [8802].file = "fs/dlm/user.c",
84872 + [8802].name = "device_write",
84873 + [8802].param3 = 1,
84874 + [8810].file = "net/mac80211/debugfs_sta.c",
84875 + [8810].name = "sta_agg_status_write",
84876 + [8810].param3 = 1,
84877 + [8815].file = "security/tomoyo/securityfs_if.c",
84878 + [8815].name = "tomoyo_write_self",
84879 + [8815].param3 = 1,
84880 + [8821].file = "net/wireless/sme.c",
84881 + [8821].name = "cfg80211_roamed",
84882 + [8821].param5 = 1,
84883 + [8821].param7 = 1,
84884 + [8833].file = "security/selinux/ss/services.c",
84885 + [8833].name = "security_context_to_sid",
84886 + [8833].param2 = 1,
84887 + [8838].file = "lib/mpi/mpi-bit.c",
84888 + [8838].name = "mpi_lshift_limbs",
84889 + [8838].param2 = 1,
84890 + [8851].file = "net/key/af_key.c",
84891 + [8851].name = "pfkey_sendmsg",
84892 + [8851].param4 = 1,
84893 + [8917].file = "net/can/raw.c",
84894 + [8917].name = "raw_setsockopt",
84895 + [8917].param5 = 1,
84896 + [8983].file = "include/linux/skbuff.h",
84897 + [8983].name = "alloc_skb",
84898 + [8983].param1 = 1,
84899 + [9117].file = "drivers/base/regmap/regcache-rbtree.c",
84900 + [9117].name = "regcache_rbtree_insert_to_block",
84901 + [9117].param5 = 1,
84902 + [9226].file = "mm/migrate.c",
84903 + [9226].name = "sys_move_pages",
84904 + [9226].param2 = 1,
84905 + [9304].file = "kernel/auditfilter.c",
84906 + [9304].name = "audit_init_entry",
84907 + [9304].param1 = 1,
84908 + [9317].file = "drivers/usb/wusbcore/wa-nep.c",
84909 + [9317].name = "wa_nep_queue",
84910 + [9317].param2 = 1,
84911 + [9341].file = "drivers/acpi/apei/erst-dbg.c",
84912 + [9341].name = "erst_dbg_write",
84913 + [9341].param3 = 1,
84914 + [9386].file = "fs/exofs/ore.c",
84915 + [9386].name = "_ore_get_io_state",
84916 + [9386].param3 = 1,
84917 + [9386].param4 = 1,
84918 + [9386].param5 = 1,
84919 + [9538].file = "crypto/blkcipher.c",
84920 + [9538].name = "blkcipher_copy_iv",
84921 + [9538].param3 = 1,
84922 + [9546].file = "drivers/video/fbmem.c",
84923 + [9546].name = "fb_write",
84924 + [9546].param3 = 1,
84925 + [9601].file = "kernel/kfifo.c",
84926 + [9601].name = "__kfifo_from_user",
84927 + [9601].param3 = 1,
84928 + [9618].file = "security/selinux/selinuxfs.c",
84929 + [9618].name = "sel_write_bool",
84930 + [9618].param3 = 1,
84931 + [9768].file = "drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c",
84932 + [9768].name = "vmw_execbuf_process",
84933 + [9768].param5 = 1,
84934 + [9828].file = "drivers/media/dvb/dvb-core/dmxdev.c",
84935 + [9828].name = "dvb_demux_do_ioctl",
84936 + [9828].param3 = 1,
84937 + [9870].file = "net/atm/addr.c",
84938 + [9870].name = "atm_get_addr",
84939 + [9870].param3 = 1,
84940 + [9977].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
84941 + [9977].name = "zd_usb_iowrite16v_async",
84942 + [9977].param3 = 1,
84943 + [16344].collision = 1,
84944 + [307].collision = 1,
84945 + [31649].collision = 1,
84946 + [33040].collision = 1,
84947 + [45231].collision = 1,
84948 + [60651].collision = 1,
84949 +};
84950 diff --git a/tools/gcc/size_overflow_hash2.h b/tools/gcc/size_overflow_hash2.h
84951 new file mode 100644
84952 index 0000000..9ec45ae
84953 --- /dev/null
84954 +++ b/tools/gcc/size_overflow_hash2.h
84955 @@ -0,0 +1,35 @@
84956 +struct size_overflow_hash size_overflow_hash2[65536] = {
84957 + [22224].file = "fs/proc/vmcore.c",
84958 + [22224].name = "read_from_oldmem",
84959 + [22224].param2 = 1,
84960 + [2344].file = "fs/ecryptfs/crypto.c",
84961 + [2344].name = "ecryptfs_decode_and_decrypt_filename",
84962 + [2344].param5 = 1,
84963 + [2515].file = "fs/ecryptfs/crypto.c",
84964 + [2515].name = "ecryptfs_copy_filename",
84965 + [2515].param4 = 1,
84966 + [26518].file = "drivers/gpu/vga/vgaarb.c",
84967 + [26518].name = "vga_arb_read",
84968 + [26518].param3 = 1,
84969 + [30632].file = "drivers/ide/ide-proc.c",
84970 + [30632].name = "ide_driver_proc_write",
84971 + [30632].param3 = 1,
84972 + [39024].file = "lib/scatterlist.c",
84973 + [39024].name = "sg_kmalloc",
84974 + [39024].param1 = 1,
84975 + [50359].file = "kernel/sched/core.c",
84976 + [50359].name = "alloc_sched_domains",
84977 + [50359].param1 = 1,
84978 + [53262].file = "drivers/block/aoe/aoechr.c",
84979 + [53262].name = "revalidate",
84980 + [53262].param2 = 1,
84981 + [56432].file = "drivers/base/regmap/regmap-debugfs.c",
84982 + [56432].name = "regmap_map_read_file",
84983 + [56432].param3 = 1,
84984 + [57500].file = "drivers/spi/spidev.c",
84985 + [57500].name = "spidev_write",
84986 + [57500].param3 = 1,
84987 + [8155].file = "drivers/hv/channel.c",
84988 + [8155].name = "vmbus_establish_gpadl",
84989 + [8155].param3 = 1,
84990 +};
84991 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
84992 new file mode 100644
84993 index 0000000..4ec0934
84994 --- /dev/null
84995 +++ b/tools/gcc/size_overflow_plugin.c
84996 @@ -0,0 +1,1150 @@
84997 +/*
84998 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
84999 + * Licensed under the GPL v2, or (at your option) v3
85000 + *
85001 + * Homepage:
85002 + * http://www.grsecurity.net/~ephox/overflow_plugin/
85003 + *
85004 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
85005 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
85006 + * The recomputed argument is checked against INT_MAX and an event is logged on overflow and the triggering process is killed.
85007 + *
85008 + * Usage:
85009 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o size_overflow_plugin.so size_overflow_plugin.c
85010 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
85011 + */
85012 +
85013 +#include "gcc-plugin.h"
85014 +#include "config.h"
85015 +#include "system.h"
85016 +#include "coretypes.h"
85017 +#include "tree.h"
85018 +#include "tree-pass.h"
85019 +#include "intl.h"
85020 +#include "plugin-version.h"
85021 +#include "tm.h"
85022 +#include "toplev.h"
85023 +#include "function.h"
85024 +#include "tree-flow.h"
85025 +#include "plugin.h"
85026 +#include "gimple.h"
85027 +#include "c-common.h"
85028 +#include "diagnostic.h"
85029 +#include "cfgloop.h"
85030 +
85031 +struct size_overflow_hash {
85032 + const char *name;
85033 + const char *file;
85034 + unsigned short collision:1;
85035 + unsigned short param1:1;
85036 + unsigned short param2:1;
85037 + unsigned short param3:1;
85038 + unsigned short param4:1;
85039 + unsigned short param5:1;
85040 + unsigned short param6:1;
85041 + unsigned short param7:1;
85042 + unsigned short param8:1;
85043 + unsigned short param9:1;
85044 +};
85045 +
85046 +#include "size_overflow_hash1.h"
85047 +#include "size_overflow_hash2.h"
85048 +
85049 +#define __unused __attribute__((__unused__))
85050 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
85051 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
85052 +#define BEFORE_STMT true
85053 +#define AFTER_STMT false
85054 +#define CREATE_NEW_VAR NULL_TREE
85055 +
85056 +int plugin_is_GPL_compatible;
85057 +void debug_gimple_stmt(gimple gs);
85058 +
85059 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
85060 +static tree signed_size_overflow_type;
85061 +static tree unsigned_size_overflow_type;
85062 +static tree report_size_overflow_decl;
85063 +static tree const_char_ptr_type_node;
85064 +static unsigned int handle_function(void);
85065 +static bool file_match = true;
85066 +
85067 +static struct plugin_info size_overflow_plugin_info = {
85068 + .version = "20120502beta",
85069 + .help = "no-size_overflow\tturn off size overflow checking\n",
85070 +};
85071 +
85072 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
85073 +{
85074 + unsigned int arg_count = type_num_arguments(*node);
85075 +
85076 + for (; args; args = TREE_CHAIN(args)) {
85077 + tree position = TREE_VALUE(args);
85078 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
85079 + error("handle_size_overflow_attribute: overflow parameter outside range.");
85080 + *no_add_attrs = true;
85081 + }
85082 + }
85083 + return NULL_TREE;
85084 +}
85085 +
85086 +static struct attribute_spec no_size_overflow_attr = {
85087 + .name = "size_overflow",
85088 + .min_length = 1,
85089 + .max_length = -1,
85090 + .decl_required = false,
85091 + .type_required = true,
85092 + .function_type_required = true,
85093 + .handler = handle_size_overflow_attribute
85094 +};
85095 +
85096 +static void register_attributes(void __unused *event_data, void __unused *data)
85097 +{
85098 + register_attribute(&no_size_overflow_attr);
85099 +}
85100 +
85101 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
85102 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
85103 +{
85104 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
85105 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
85106 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
85107 +
85108 + const unsigned int m = 0x57559429;
85109 + const unsigned int n = 0x5052acdb;
85110 + const unsigned int *key4 = (const unsigned int *)key;
85111 + unsigned int h = len;
85112 + unsigned int k = len + seed + n;
85113 + unsigned long long p;
85114 +
85115 + while (len >= 8) {
85116 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
85117 + len -= 8;
85118 + }
85119 + if (len >= 4) {
85120 + cwmixb(key4[0]) key4 += 1;
85121 + len -= 4;
85122 + }
85123 + if (len)
85124 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
85125 + cwmixb(h ^ (k + n));
85126 + return k ^ h;
85127 +
85128 +#undef cwfold
85129 +#undef cwmixa
85130 +#undef cwmixb
85131 +}
85132 +
85133 +static inline unsigned int size_overflow_hash(const char *fndecl, unsigned int seed)
85134 +{
85135 + return CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
85136 +}
85137 +
85138 +static inline tree get_original_function_decl(tree fndecl)
85139 +{
85140 + if (DECL_ABSTRACT_ORIGIN(fndecl))
85141 + return DECL_ABSTRACT_ORIGIN(fndecl);
85142 + return fndecl;
85143 +}
85144 +
85145 +static inline gimple get_def_stmt(tree node)
85146 +{
85147 + gcc_assert(TREE_CODE(node) == SSA_NAME);
85148 + return SSA_NAME_DEF_STMT(node);
85149 +}
85150 +
85151 +static struct size_overflow_hash *get_function_hash(tree fndecl)
85152 +{
85153 + unsigned int hash;
85154 + const char *func = NAME(fndecl);
85155 +
85156 + hash = size_overflow_hash(func, 0);
85157 +
85158 + if (size_overflow_hash1[hash].collision) {
85159 + hash = size_overflow_hash(func, 23432);
85160 + return &size_overflow_hash2[hash];
85161 + }
85162 + return &size_overflow_hash1[hash];
85163 +}
85164 +
85165 +static void check_arg_type(tree var)
85166 +{
85167 + tree type = TREE_TYPE(var);
85168 + enum tree_code code = TREE_CODE(type);
85169 +
85170 + gcc_assert(code == INTEGER_TYPE ||
85171 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
85172 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
85173 +}
85174 +
85175 +static void check_missing_attribute(tree arg)
85176 +{
85177 + tree var, type, func = get_original_function_decl(current_function_decl);
85178 + const char *curfunc = NAME(func);
85179 + unsigned int new_hash, argnum = 1;
85180 + struct size_overflow_hash *hash;
85181 + location_t loc;
85182 + expanded_location xloc;
85183 + bool match = false;
85184 +
85185 + type = TREE_TYPE(arg);
85186 + // skip function pointers
85187 + if (TREE_CODE(type) == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == FUNCTION_TYPE)
85188 + return;
85189 +
85190 + loc = DECL_SOURCE_LOCATION(func);
85191 + xloc = expand_location(loc);
85192 +
85193 + if (lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(func))))
85194 + return;
85195 +
85196 + hash = get_function_hash(func);
85197 + if (hash->name && !strcmp(hash->name, NAME(func)))
85198 + return;
85199 + if (file_match && hash->file && !strcmp(hash->file, xloc.file))
85200 + return;
85201 +
85202 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
85203 +
85204 + if (TREE_CODE(arg) == SSA_NAME)
85205 + arg = SSA_NAME_VAR(arg);
85206 +
85207 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
85208 + if (strcmp(NAME(arg), NAME(var))) {
85209 + argnum++;
85210 + continue;
85211 + }
85212 + check_arg_type(var);
85213 +
85214 + match = true;
85215 + if (!TYPE_UNSIGNED(TREE_TYPE(var)))
85216 + return;
85217 + break;
85218 + }
85219 + if (!match) {
85220 + warning(0, "check_missing_attribute: cannot find the %s argument in %s", NAME(arg), NAME(func));
85221 + return;
85222 + }
85223 +
85224 +#define check_param(num) \
85225 + if (num == argnum && hash->param##num) \
85226 + return;
85227 + check_param(1);
85228 + check_param(2);
85229 + check_param(3);
85230 + check_param(4);
85231 + check_param(5);
85232 + check_param(6);
85233 + check_param(7);
85234 + check_param(8);
85235 + check_param(9);
85236 +#undef check_param
85237 +
85238 + new_hash = size_overflow_hash(curfunc, 0);
85239 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+%s", curfunc, curfunc, argnum, new_hash, xloc.file);
85240 +}
85241 +
85242 +static tree create_new_var(tree type)
85243 +{
85244 + tree new_var = create_tmp_var(type, "cicus");
85245 +
85246 + add_referenced_var(new_var);
85247 + mark_sym_for_renaming(new_var);
85248 + return new_var;
85249 +}
85250 +
85251 +static bool is_bool(tree node)
85252 +{
85253 + tree type;
85254 +
85255 + if (node == NULL_TREE)
85256 + return false;
85257 +
85258 + type = TREE_TYPE(node);
85259 + if (!INTEGRAL_TYPE_P(type))
85260 + return false;
85261 + if (TREE_CODE(type) == BOOLEAN_TYPE)
85262 + return true;
85263 + if (TYPE_PRECISION(type) == 1)
85264 + return true;
85265 + return false;
85266 +}
85267 +
85268 +static tree cast_a_tree(tree type, tree var)
85269 +{
85270 + gcc_assert(fold_convertible_p(type, var));
85271 +
85272 + return fold_convert(type, var);
85273 +}
85274 +
85275 +static gimple build_cast_stmt(tree type, tree var, tree new_var, location_t loc)
85276 +{
85277 + gimple assign;
85278 +
85279 + if (new_var == CREATE_NEW_VAR)
85280 + new_var = create_new_var(type);
85281 +
85282 + assign = gimple_build_assign(new_var, cast_a_tree(type, var));
85283 + gimple_set_location(assign, loc);
85284 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
85285 +
85286 + return assign;
85287 +}
85288 +
85289 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
85290 +{
85291 + tree oldstmt_rhs1;
85292 + enum tree_code code;
85293 + gimple stmt;
85294 + gimple_stmt_iterator gsi;
85295 +
85296 + if (!*potentionally_overflowed)
85297 + return NULL_TREE;
85298 +
85299 + if (rhs1 == NULL_TREE) {
85300 + debug_gimple_stmt(oldstmt);
85301 + error("create_assign: rhs1 is NULL_TREE");
85302 + gcc_unreachable();
85303 + }
85304 +
85305 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
85306 + code = TREE_CODE(oldstmt_rhs1);
85307 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
85308 + check_missing_attribute(oldstmt_rhs1);
85309 +
85310 + stmt = build_cast_stmt(signed_size_overflow_type, rhs1, CREATE_NEW_VAR, gimple_location(oldstmt));
85311 + gsi = gsi_for_stmt(oldstmt);
85312 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
85313 + basic_block next_bb, cur_bb;
85314 + edge e;
85315 +
85316 + gcc_assert(before == false);
85317 + gcc_assert(stmt_can_throw_internal(oldstmt));
85318 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
85319 + gcc_assert(!gsi_end_p(gsi));
85320 +
85321 + cur_bb = gimple_bb(oldstmt);
85322 + next_bb = cur_bb->next_bb;
85323 + e = find_edge(cur_bb, next_bb);
85324 + gcc_assert(e != NULL);
85325 + gcc_assert(e->flags & EDGE_FALLTHRU);
85326 +
85327 + gsi = gsi_after_labels(next_bb);
85328 + gcc_assert(!gsi_end_p(gsi));
85329 + before = true;
85330 + }
85331 + if (before)
85332 + gsi_insert_before(&gsi, stmt, GSI_NEW_STMT);
85333 + else
85334 + gsi_insert_after(&gsi, stmt, GSI_NEW_STMT);
85335 + update_stmt(stmt);
85336 + pointer_set_insert(visited, oldstmt);
85337 + return gimple_get_lhs(stmt);
85338 +}
85339 +
85340 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, tree rhs2, tree __unused rhs3)
85341 +{
85342 + tree new_var, lhs = gimple_get_lhs(oldstmt);
85343 + gimple stmt;
85344 + gimple_stmt_iterator gsi;
85345 +
85346 + if (!*potentionally_overflowed)
85347 + return NULL_TREE;
85348 +
85349 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
85350 + rhs1 = gimple_assign_rhs1(oldstmt);
85351 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
85352 + }
85353 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
85354 + rhs2 = gimple_assign_rhs2(oldstmt);
85355 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
85356 + }
85357 +
85358 + stmt = gimple_copy(oldstmt);
85359 + gimple_set_location(stmt, gimple_location(oldstmt));
85360 +
85361 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
85362 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
85363 +
85364 + if (is_bool(lhs))
85365 + new_var = SSA_NAME_VAR(lhs);
85366 + else
85367 + new_var = create_new_var(signed_size_overflow_type);
85368 + new_var = make_ssa_name(new_var, stmt);
85369 + gimple_set_lhs(stmt, new_var);
85370 +
85371 + if (rhs1 != NULL_TREE) {
85372 + if (!gimple_assign_cast_p(oldstmt))
85373 + rhs1 = cast_a_tree(signed_size_overflow_type, rhs1);
85374 + gimple_assign_set_rhs1(stmt, rhs1);
85375 + }
85376 +
85377 + if (rhs2 != NULL_TREE)
85378 + gimple_assign_set_rhs2(stmt, rhs2);
85379 +#if BUILDING_GCC_VERSION >= 4007
85380 + if (rhs3 != NULL_TREE)
85381 + gimple_assign_set_rhs3(stmt, rhs3);
85382 +#endif
85383 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
85384 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
85385 +
85386 + gsi = gsi_for_stmt(oldstmt);
85387 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
85388 + update_stmt(stmt);
85389 + pointer_set_insert(visited, oldstmt);
85390 + return gimple_get_lhs(stmt);
85391 +}
85392 +
85393 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
85394 +{
85395 + basic_block bb;
85396 + gimple phi;
85397 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
85398 +
85399 + bb = gsi_bb(gsi);
85400 +
85401 + phi = create_phi_node(var, bb);
85402 + gsi = gsi_last(phi_nodes(bb));
85403 + gsi_remove(&gsi, false);
85404 +
85405 + gsi = gsi_for_stmt(oldstmt);
85406 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
85407 + gimple_set_bb(phi, bb);
85408 + return phi;
85409 +}
85410 +
85411 +static tree signed_cast_constant(tree node)
85412 +{
85413 + gcc_assert(is_gimple_constant(node));
85414 +
85415 + return cast_a_tree(signed_size_overflow_type, node);
85416 +}
85417 +
85418 +static gimple cast_old_phi_arg(gimple oldstmt, tree arg, tree new_var, unsigned int i)
85419 +{
85420 + basic_block bb;
85421 + gimple newstmt, def_stmt;
85422 + gimple_stmt_iterator gsi;
85423 +
85424 + newstmt = build_cast_stmt(signed_size_overflow_type, arg, new_var, gimple_location(oldstmt));
85425 + if (TREE_CODE(arg) == SSA_NAME) {
85426 + def_stmt = get_def_stmt(arg);
85427 + if (gimple_code(def_stmt) != GIMPLE_NOP) {
85428 + gsi = gsi_for_stmt(def_stmt);
85429 + gsi_insert_after(&gsi, newstmt, GSI_NEW_STMT);
85430 + return newstmt;
85431 + }
85432 + }
85433 +
85434 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
85435 + gsi = gsi_after_labels(bb);
85436 + gsi_insert_before(&gsi, newstmt, GSI_NEW_STMT);
85437 + return newstmt;
85438 +}
85439 +
85440 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
85441 +{
85442 + gimple newstmt;
85443 + gimple_stmt_iterator gsi;
85444 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
85445 + gimple def_newstmt = get_def_stmt(new_rhs);
85446 +
85447 + gsi_insert = gsi_insert_after;
85448 + gsi = gsi_for_stmt(def_newstmt);
85449 +
85450 + switch (gimple_code(get_def_stmt(arg))) {
85451 + case GIMPLE_PHI:
85452 + newstmt = gimple_build_assign(new_var, new_rhs);
85453 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
85454 + gsi_insert = gsi_insert_before;
85455 + break;
85456 + case GIMPLE_ASM:
85457 + case GIMPLE_CALL:
85458 + newstmt = gimple_build_assign(new_var, new_rhs);
85459 + break;
85460 + case GIMPLE_ASSIGN:
85461 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
85462 + break;
85463 + default:
85464 + /* unknown gimple_code (handle_build_new_phi_arg) */
85465 + gcc_unreachable();
85466 + }
85467 +
85468 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
85469 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
85470 + update_stmt(newstmt);
85471 + return newstmt;
85472 +}
85473 +
85474 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree arg, tree new_var)
85475 +{
85476 + gimple newstmt;
85477 + tree new_rhs;
85478 +
85479 + new_rhs = expand(visited, potentionally_overflowed, arg);
85480 +
85481 + if (new_rhs == NULL_TREE)
85482 + return NULL_TREE;
85483 +
85484 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
85485 + return gimple_get_lhs(newstmt);
85486 +}
85487 +
85488 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt)
85489 +{
85490 + gimple phi;
85491 + tree new_var = create_new_var(signed_size_overflow_type);
85492 + unsigned int i, n = gimple_phi_num_args(oldstmt);
85493 +
85494 + pointer_set_insert(visited, oldstmt);
85495 + phi = overflow_create_phi_node(oldstmt, new_var);
85496 + for (i = 0; i < n; i++) {
85497 + tree arg, lhs;
85498 +
85499 + arg = gimple_phi_arg_def(oldstmt, i);
85500 + if (is_gimple_constant(arg))
85501 + arg = signed_cast_constant(arg);
85502 + lhs = build_new_phi_arg(visited, potentionally_overflowed, arg, new_var);
85503 + if (lhs == NULL_TREE)
85504 + lhs = gimple_get_lhs(cast_old_phi_arg(oldstmt, arg, new_var, i));
85505 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
85506 + }
85507 +
85508 + update_stmt(phi);
85509 + return gimple_phi_result(phi);
85510 +}
85511 +
85512 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85513 +{
85514 + gimple def_stmt = get_def_stmt(var);
85515 + tree new_rhs1, rhs1 = gimple_assign_rhs1(def_stmt);
85516 +
85517 + *potentionally_overflowed = true;
85518 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85519 + if (new_rhs1 == NULL_TREE) {
85520 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
85521 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85522 + else
85523 + return create_assign(visited, potentionally_overflowed, def_stmt, rhs1, AFTER_STMT);
85524 + }
85525 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, NULL_TREE, NULL_TREE);
85526 +}
85527 +
85528 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85529 +{
85530 + gimple def_stmt = get_def_stmt(var);
85531 + tree rhs1 = gimple_assign_rhs1(def_stmt);
85532 +
85533 + if (is_gimple_constant(rhs1))
85534 + return dup_assign(visited, potentionally_overflowed, def_stmt, signed_cast_constant(rhs1), NULL_TREE, NULL_TREE);
85535 +
85536 + switch (TREE_CODE(rhs1)) {
85537 + case SSA_NAME:
85538 + return handle_unary_rhs(visited, potentionally_overflowed, var);
85539 +
85540 + case ARRAY_REF:
85541 + case BIT_FIELD_REF:
85542 + case ADDR_EXPR:
85543 + case COMPONENT_REF:
85544 + case COND_EXPR:
85545 + case INDIRECT_REF:
85546 +#if BUILDING_GCC_VERSION >= 4006
85547 + case MEM_REF:
85548 +#endif
85549 + case PARM_DECL:
85550 + case TARGET_MEM_REF:
85551 + case VAR_DECL:
85552 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85553 +
85554 + default:
85555 + debug_gimple_stmt(def_stmt);
85556 + debug_tree(rhs1);
85557 + gcc_unreachable();
85558 + }
85559 +}
85560 +
85561 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
85562 +{
85563 + gimple cond_stmt;
85564 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
85565 +
85566 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
85567 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
85568 + update_stmt(cond_stmt);
85569 +}
85570 +
85571 +static tree create_string_param(tree string)
85572 +{
85573 + tree i_type, a_type;
85574 + int length = TREE_STRING_LENGTH(string);
85575 +
85576 + gcc_assert(length > 0);
85577 +
85578 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
85579 + a_type = build_array_type(char_type_node, i_type);
85580 +
85581 + TREE_TYPE(string) = a_type;
85582 + TREE_CONSTANT(string) = 1;
85583 + TREE_READONLY(string) = 1;
85584 +
85585 + return build1(ADDR_EXPR, ptr_type_node, string);
85586 +}
85587 +
85588 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg)
85589 +{
85590 + gimple func_stmt, def_stmt;
85591 + tree current_func, loc_file, loc_line;
85592 + expanded_location xloc;
85593 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
85594 +
85595 + def_stmt = get_def_stmt(arg);
85596 + xloc = expand_location(gimple_location(def_stmt));
85597 +
85598 + if (!gimple_has_location(def_stmt)) {
85599 + xloc = expand_location(gimple_location(stmt));
85600 + if (!gimple_has_location(stmt))
85601 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
85602 + }
85603 +
85604 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
85605 +
85606 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
85607 + loc_file = create_string_param(loc_file);
85608 +
85609 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
85610 + current_func = create_string_param(current_func);
85611 +
85612 + // void report_size_overflow(const char *file, unsigned int line, const char *func)
85613 + func_stmt = gimple_build_call(report_size_overflow_decl, 3, loc_file, loc_line, current_func);
85614 +
85615 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
85616 +}
85617 +
85618 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value)
85619 +{
85620 + basic_block cond_bb, join_bb, bb_true;
85621 + edge e;
85622 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85623 +// location_t loc = gimple_location(stmt);
85624 +
85625 + cond_bb = gimple_bb(stmt);
85626 + gsi_prev(&gsi);
85627 + if (gsi_end_p(gsi))
85628 + e = split_block_after_labels(cond_bb);
85629 + else
85630 + e = split_block(cond_bb, gsi_stmt(gsi));
85631 + cond_bb = e->src;
85632 + join_bb = e->dest;
85633 + e->flags = EDGE_FALSE_VALUE;
85634 + e->probability = REG_BR_PROB_BASE;
85635 +
85636 + bb_true = create_empty_bb(cond_bb);
85637 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
85638 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
85639 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
85640 +
85641 + if (dom_info_available_p(CDI_DOMINATORS)) {
85642 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
85643 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
85644 + }
85645 +
85646 + if (current_loops != NULL) {
85647 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
85648 + add_bb_to_loop(bb_true, cond_bb->loop_father);
85649 + }
85650 +
85651 + insert_cond(cond_bb, arg, cond_code, type_value);
85652 + insert_cond_result(bb_true, stmt, arg);
85653 +
85654 +// inform(loc, "Integer size_overflow check applied here.");
85655 +}
85656 +
85657 +static tree get_type_for_check(tree rhs)
85658 +{
85659 + tree def_rhs;
85660 + gimple def_stmt = get_def_stmt(rhs);
85661 +
85662 + if (!gimple_assign_cast_p(def_stmt))
85663 + return TREE_TYPE(rhs);
85664 + def_rhs = gimple_assign_rhs1(def_stmt);
85665 + if (TREE_CODE(TREE_TYPE(def_rhs)) == INTEGER_TYPE)
85666 + return TREE_TYPE(def_rhs);
85667 + return TREE_TYPE(rhs);
85668 +}
85669 +
85670 +static gimple cast_to_unsigned_size_overflow_type(gimple stmt, tree cast_rhs)
85671 +{
85672 + gimple ucast_stmt;
85673 + gimple_stmt_iterator gsi;
85674 + location_t loc = gimple_location(stmt);
85675 +
85676 + ucast_stmt = build_cast_stmt(unsigned_size_overflow_type, cast_rhs, CREATE_NEW_VAR, loc);
85677 + gsi = gsi_for_stmt(stmt);
85678 + gsi_insert_before(&gsi, ucast_stmt, GSI_SAME_STMT);
85679 + return ucast_stmt;
85680 +}
85681 +
85682 +static void check_size_overflow(gimple stmt, tree cast_rhs, tree rhs, bool *potentionally_overflowed)
85683 +{
85684 + tree type_max, type_min, rhs_type;
85685 + gimple ucast_stmt;
85686 +
85687 + if (!*potentionally_overflowed)
85688 + return;
85689 +
85690 + rhs_type = get_type_for_check(rhs);
85691 +
85692 + if (TYPE_UNSIGNED(rhs_type)) {
85693 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, cast_rhs);
85694 + type_max = cast_a_tree(unsigned_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
85695 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
85696 + } else {
85697 + type_max = cast_a_tree(signed_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
85698 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max);
85699 +
85700 + type_min = cast_a_tree(signed_size_overflow_type, TYPE_MIN_VALUE(rhs_type));
85701 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min);
85702 + }
85703 +}
85704 +
85705 +static tree change_assign_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt, tree orig_rhs)
85706 +{
85707 + gimple assign;
85708 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85709 + tree new_rhs, origtype = TREE_TYPE(orig_rhs);
85710 +
85711 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
85712 +
85713 + new_rhs = expand(visited, potentionally_overflowed, orig_rhs);
85714 + if (new_rhs == NULL_TREE)
85715 + return NULL_TREE;
85716 +
85717 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, gimple_location(stmt));
85718 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85719 + update_stmt(assign);
85720 + return gimple_get_lhs(assign);
85721 +}
85722 +
85723 +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))
85724 +{
85725 + tree new_rhs, cast_rhs;
85726 +
85727 + if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
85728 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85729 +
85730 + new_rhs = change_assign_rhs(visited, potentionally_overflowed, def_stmt, rhs);
85731 + if (new_rhs != NULL_TREE) {
85732 + gimple_assign_set_rhs(def_stmt, new_rhs);
85733 + update_stmt(def_stmt);
85734 +
85735 + cast_rhs = gimple_assign_rhs1(get_def_stmt(new_rhs));
85736 +
85737 + check_size_overflow(def_stmt, cast_rhs, rhs, potentionally_overflowed);
85738 + }
85739 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85740 +}
85741 +
85742 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85743 +{
85744 + tree rhs1, rhs2;
85745 + gimple def_stmt = get_def_stmt(var);
85746 + tree new_rhs1 = NULL_TREE;
85747 + tree new_rhs2 = NULL_TREE;
85748 +
85749 + rhs1 = gimple_assign_rhs1(def_stmt);
85750 + rhs2 = gimple_assign_rhs2(def_stmt);
85751 +
85752 + /* no DImode/TImode division in the 32/64 bit kernel */
85753 + switch (gimple_assign_rhs_code(def_stmt)) {
85754 + case RDIV_EXPR:
85755 + case TRUNC_DIV_EXPR:
85756 + case CEIL_DIV_EXPR:
85757 + case FLOOR_DIV_EXPR:
85758 + case ROUND_DIV_EXPR:
85759 + case TRUNC_MOD_EXPR:
85760 + case CEIL_MOD_EXPR:
85761 + case FLOOR_MOD_EXPR:
85762 + case ROUND_MOD_EXPR:
85763 + case EXACT_DIV_EXPR:
85764 + case POINTER_PLUS_EXPR:
85765 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85766 + default:
85767 + break;
85768 + }
85769 +
85770 + *potentionally_overflowed = true;
85771 +
85772 + if (TREE_CODE(rhs1) == SSA_NAME)
85773 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85774 + if (TREE_CODE(rhs2) == SSA_NAME)
85775 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
85776 +
85777 + if (is_gimple_constant(rhs2))
85778 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs1, new_rhs1, signed_cast_constant(rhs2), &gimple_assign_set_rhs1);
85779 +
85780 + if (is_gimple_constant(rhs1))
85781 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs2, signed_cast_constant(rhs1), new_rhs2, &gimple_assign_set_rhs2);
85782 +
85783 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85784 +}
85785 +
85786 +#if BUILDING_GCC_VERSION >= 4007
85787 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree rhs)
85788 +{
85789 + if (is_gimple_constant(rhs))
85790 + return signed_cast_constant(rhs);
85791 + if (TREE_CODE(rhs) != SSA_NAME)
85792 + return NULL_TREE;
85793 + return expand(visited, potentionally_overflowed, rhs);
85794 +}
85795 +
85796 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85797 +{
85798 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3;
85799 + gimple def_stmt = get_def_stmt(var);
85800 +
85801 + *potentionally_overflowed = true;
85802 +
85803 + rhs1 = gimple_assign_rhs1(def_stmt);
85804 + rhs2 = gimple_assign_rhs2(def_stmt);
85805 + rhs3 = gimple_assign_rhs3(def_stmt);
85806 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, rhs1);
85807 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, rhs2);
85808 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, rhs3);
85809 +
85810 + if (new_rhs1 == NULL_TREE && new_rhs2 != NULL_TREE && new_rhs3 != NULL_TREE)
85811 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, new_rhs3);
85812 + error("handle_ternary_ops: unknown rhs");
85813 + gcc_unreachable();
85814 +}
85815 +#endif
85816 +
85817 +static void set_size_overflow_type(tree node)
85818 +{
85819 + switch (TYPE_MODE(TREE_TYPE(node))) {
85820 + case SImode:
85821 + signed_size_overflow_type = intDI_type_node;
85822 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85823 + break;
85824 + case DImode:
85825 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode)) {
85826 + signed_size_overflow_type = intDI_type_node;
85827 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85828 + } else {
85829 + signed_size_overflow_type = intTI_type_node;
85830 + unsigned_size_overflow_type = unsigned_intTI_type_node;
85831 + }
85832 + break;
85833 + default:
85834 + error("set_size_overflow_type: unsupported gcc configuration.");
85835 + gcc_unreachable();
85836 + }
85837 +}
85838 +
85839 +static tree expand_visited(gimple def_stmt)
85840 +{
85841 + gimple tmp;
85842 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
85843 +
85844 + gsi_next(&gsi);
85845 + tmp = gsi_stmt(gsi);
85846 + switch (gimple_code(tmp)) {
85847 + case GIMPLE_ASSIGN:
85848 + return gimple_get_lhs(tmp);
85849 + case GIMPLE_PHI:
85850 + return gimple_phi_result(tmp);
85851 + case GIMPLE_CALL:
85852 + return gimple_call_lhs(tmp);
85853 + default:
85854 + return NULL_TREE;
85855 + }
85856 +}
85857 +
85858 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85859 +{
85860 + gimple def_stmt;
85861 + enum tree_code code = TREE_CODE(TREE_TYPE(var));
85862 +
85863 + if (is_gimple_constant(var))
85864 + return NULL_TREE;
85865 +
85866 + if (TREE_CODE(var) == ADDR_EXPR)
85867 + return NULL_TREE;
85868 +
85869 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE);
85870 + if (code != INTEGER_TYPE)
85871 + return NULL_TREE;
85872 +
85873 + if (SSA_NAME_IS_DEFAULT_DEF(var)) {
85874 + check_missing_attribute(var);
85875 + return NULL_TREE;
85876 + }
85877 +
85878 + def_stmt = get_def_stmt(var);
85879 +
85880 + if (!def_stmt)
85881 + return NULL_TREE;
85882 +
85883 + if (pointer_set_contains(visited, def_stmt))
85884 + return expand_visited(def_stmt);
85885 +
85886 + switch (gimple_code(def_stmt)) {
85887 + case GIMPLE_NOP:
85888 + check_missing_attribute(var);
85889 + return NULL_TREE;
85890 + case GIMPLE_PHI:
85891 + return build_new_phi(visited, potentionally_overflowed, def_stmt);
85892 + case GIMPLE_CALL:
85893 + case GIMPLE_ASM:
85894 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85895 + case GIMPLE_ASSIGN:
85896 + switch (gimple_num_ops(def_stmt)) {
85897 + case 2:
85898 + return handle_unary_ops(visited, potentionally_overflowed, var);
85899 + case 3:
85900 + return handle_binary_ops(visited, potentionally_overflowed, var);
85901 +#if BUILDING_GCC_VERSION >= 4007
85902 + case 4:
85903 + return handle_ternary_ops(visited, potentionally_overflowed, var);
85904 +#endif
85905 + }
85906 + default:
85907 + debug_gimple_stmt(def_stmt);
85908 + error("expand: unknown gimple code");
85909 + gcc_unreachable();
85910 + }
85911 +}
85912 +
85913 +static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
85914 +{
85915 + gimple assign;
85916 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85917 + tree origtype = TREE_TYPE(origarg);
85918 +
85919 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
85920 +
85921 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, gimple_location(stmt));
85922 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85923 + update_stmt(assign);
85924 +
85925 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
85926 + update_stmt(stmt);
85927 +}
85928 +
85929 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
85930 +{
85931 + const char *origid;
85932 + tree arg, origarg;
85933 +
85934 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
85935 + gcc_assert(gimple_call_num_args(stmt) > argnum);
85936 + return gimple_call_arg(stmt, argnum);
85937 + }
85938 +
85939 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
85940 + while (origarg && argnum) {
85941 + argnum--;
85942 + origarg = TREE_CHAIN(origarg);
85943 + }
85944 +
85945 + gcc_assert(argnum == 0);
85946 +
85947 + gcc_assert(origarg != NULL_TREE);
85948 + origid = NAME(origarg);
85949 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
85950 + if (!strcmp(origid, NAME(arg)))
85951 + return arg;
85952 + }
85953 + return NULL_TREE;
85954 +}
85955 +
85956 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
85957 +{
85958 + struct pointer_set_t *visited;
85959 + tree arg, newarg, type_max;
85960 + gimple ucast_stmt;
85961 + bool potentionally_overflowed;
85962 +
85963 + arg = get_function_arg(argnum, stmt, fndecl);
85964 + if (arg == NULL_TREE)
85965 + return;
85966 +
85967 + if (is_gimple_constant(arg))
85968 + return;
85969 + if (TREE_CODE(arg) != SSA_NAME)
85970 + return;
85971 +
85972 + check_arg_type(arg);
85973 +
85974 + set_size_overflow_type(arg);
85975 +
85976 + visited = pointer_set_create();
85977 + potentionally_overflowed = false;
85978 + newarg = expand(visited, &potentionally_overflowed, arg);
85979 + pointer_set_destroy(visited);
85980 +
85981 + if (newarg == NULL_TREE || !potentionally_overflowed)
85982 + return;
85983 +
85984 + change_function_arg(stmt, arg, argnum, newarg);
85985 +
85986 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, newarg);
85987 +
85988 + type_max = build_int_cstu(unsigned_size_overflow_type, 0x7fffffff);
85989 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
85990 +}
85991 +
85992 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
85993 +{
85994 + tree p = TREE_VALUE(attr);
85995 + do {
85996 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
85997 + p = TREE_CHAIN(p);
85998 + } while (p);
85999 +}
86000 +
86001 +static void handle_function_by_hash(gimple stmt, tree fndecl)
86002 +{
86003 + struct size_overflow_hash *hash;
86004 + expanded_location xloc;
86005 +
86006 + hash = get_function_hash(fndecl);
86007 + xloc = expand_location(DECL_SOURCE_LOCATION(fndecl));
86008 +
86009 + fndecl = get_original_function_decl(fndecl);
86010 + if (!hash->name)
86011 + return;
86012 + if (file_match && !hash->file)
86013 + return;
86014 + if (strcmp(hash->name, NAME(fndecl)))
86015 + return;
86016 + if (file_match && strcmp(hash->file, xloc.file))
86017 + return;
86018 +
86019 +#define search_param(argnum) \
86020 + if (hash->param##argnum) \
86021 + handle_function_arg(stmt, fndecl, argnum - 1);
86022 +
86023 + search_param(1);
86024 + search_param(2);
86025 + search_param(3);
86026 + search_param(4);
86027 + search_param(5);
86028 + search_param(6);
86029 + search_param(7);
86030 + search_param(8);
86031 + search_param(9);
86032 +#undef search_param
86033 +}
86034 +
86035 +static unsigned int handle_function(void)
86036 +{
86037 + basic_block bb = ENTRY_BLOCK_PTR->next_bb;
86038 + int saved_last_basic_block = last_basic_block;
86039 +
86040 + do {
86041 + gimple_stmt_iterator gsi;
86042 + basic_block next = bb->next_bb;
86043 +
86044 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86045 + tree fndecl, attr;
86046 + gimple stmt = gsi_stmt(gsi);
86047 +
86048 + if (!(is_gimple_call(stmt)))
86049 + continue;
86050 + fndecl = gimple_call_fndecl(stmt);
86051 + if (fndecl == NULL_TREE)
86052 + continue;
86053 + if (gimple_call_num_args(stmt) == 0)
86054 + continue;
86055 + attr = lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(fndecl)));
86056 + if (!attr || !TREE_VALUE(attr))
86057 + handle_function_by_hash(stmt, fndecl);
86058 + else
86059 + handle_function_by_attribute(stmt, attr, fndecl);
86060 + gsi = gsi_for_stmt(stmt);
86061 + }
86062 + bb = next;
86063 + } while (bb && bb->index <= saved_last_basic_block);
86064 + return 0;
86065 +}
86066 +
86067 +static struct gimple_opt_pass size_overflow_pass = {
86068 + .pass = {
86069 + .type = GIMPLE_PASS,
86070 + .name = "size_overflow",
86071 + .gate = NULL,
86072 + .execute = handle_function,
86073 + .sub = NULL,
86074 + .next = NULL,
86075 + .static_pass_number = 0,
86076 + .tv_id = TV_NONE,
86077 + .properties_required = PROP_cfg | PROP_referenced_vars,
86078 + .properties_provided = 0,
86079 + .properties_destroyed = 0,
86080 + .todo_flags_start = 0,
86081 + .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
86082 + }
86083 +};
86084 +
86085 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
86086 +{
86087 + tree fntype;
86088 +
86089 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
86090 +
86091 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func)
86092 + fntype = build_function_type_list(void_type_node,
86093 + const_char_ptr_type_node,
86094 + unsigned_type_node,
86095 + const_char_ptr_type_node,
86096 + NULL_TREE);
86097 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
86098 +
86099 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
86100 + TREE_PUBLIC(report_size_overflow_decl) = 1;
86101 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
86102 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
86103 +}
86104 +
86105 +extern struct gimple_opt_pass pass_dce;
86106 +
86107 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86108 +{
86109 + int i;
86110 + const char * const plugin_name = plugin_info->base_name;
86111 + const int argc = plugin_info->argc;
86112 + const struct plugin_argument * const argv = plugin_info->argv;
86113 + bool enable = true;
86114 +
86115 + struct register_pass_info size_overflow_pass_info = {
86116 + .pass = &size_overflow_pass.pass,
86117 + .reference_pass_name = "ssa",
86118 + .ref_pass_instance_number = 1,
86119 + .pos_op = PASS_POS_INSERT_AFTER
86120 + };
86121 +
86122 + if (!plugin_default_version_check(version, &gcc_version)) {
86123 + error(G_("incompatible gcc/plugin versions"));
86124 + return 1;
86125 + }
86126 +
86127 + for (i = 0; i < argc; ++i) {
86128 + if (!strcmp(argv[i].key, "no-size-overflow")) {
86129 + enable = false;
86130 + continue;
86131 + } else if (!(strcmp(argv[i].key, "no-file-match"))) {
86132 + file_match = false;
86133 + continue;
86134 + }
86135 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86136 + }
86137 +
86138 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
86139 + if (enable) {
86140 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
86141 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
86142 + }
86143 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
86144 +
86145 + return 0;
86146 +}
86147 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
86148 new file mode 100644
86149 index 0000000..b87ec9d
86150 --- /dev/null
86151 +++ b/tools/gcc/stackleak_plugin.c
86152 @@ -0,0 +1,313 @@
86153 +/*
86154 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
86155 + * Licensed under the GPL v2
86156 + *
86157 + * Note: the choice of the license means that the compilation process is
86158 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86159 + * but for the kernel it doesn't matter since it doesn't link against
86160 + * any of the gcc libraries
86161 + *
86162 + * gcc plugin to help implement various PaX features
86163 + *
86164 + * - track lowest stack pointer
86165 + *
86166 + * TODO:
86167 + * - initialize all local variables
86168 + *
86169 + * BUGS:
86170 + * - none known
86171 + */
86172 +#include "gcc-plugin.h"
86173 +#include "config.h"
86174 +#include "system.h"
86175 +#include "coretypes.h"
86176 +#include "tree.h"
86177 +#include "tree-pass.h"
86178 +#include "flags.h"
86179 +#include "intl.h"
86180 +#include "toplev.h"
86181 +#include "plugin.h"
86182 +//#include "expr.h" where are you...
86183 +#include "diagnostic.h"
86184 +#include "plugin-version.h"
86185 +#include "tm.h"
86186 +#include "function.h"
86187 +#include "basic-block.h"
86188 +#include "gimple.h"
86189 +#include "rtl.h"
86190 +#include "emit-rtl.h"
86191 +
86192 +extern void print_gimple_stmt(FILE *, gimple, int, int);
86193 +
86194 +int plugin_is_GPL_compatible;
86195 +
86196 +static int track_frame_size = -1;
86197 +static const char track_function[] = "pax_track_stack";
86198 +static const char check_function[] = "pax_check_alloca";
86199 +static bool init_locals;
86200 +
86201 +static struct plugin_info stackleak_plugin_info = {
86202 + .version = "201203140940",
86203 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
86204 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
86205 +};
86206 +
86207 +static bool gate_stackleak_track_stack(void);
86208 +static unsigned int execute_stackleak_tree_instrument(void);
86209 +static unsigned int execute_stackleak_final(void);
86210 +
86211 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
86212 + .pass = {
86213 + .type = GIMPLE_PASS,
86214 + .name = "stackleak_tree_instrument",
86215 + .gate = gate_stackleak_track_stack,
86216 + .execute = execute_stackleak_tree_instrument,
86217 + .sub = NULL,
86218 + .next = NULL,
86219 + .static_pass_number = 0,
86220 + .tv_id = TV_NONE,
86221 + .properties_required = PROP_gimple_leh | PROP_cfg,
86222 + .properties_provided = 0,
86223 + .properties_destroyed = 0,
86224 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
86225 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
86226 + }
86227 +};
86228 +
86229 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
86230 + .pass = {
86231 + .type = RTL_PASS,
86232 + .name = "stackleak_final",
86233 + .gate = gate_stackleak_track_stack,
86234 + .execute = execute_stackleak_final,
86235 + .sub = NULL,
86236 + .next = NULL,
86237 + .static_pass_number = 0,
86238 + .tv_id = TV_NONE,
86239 + .properties_required = 0,
86240 + .properties_provided = 0,
86241 + .properties_destroyed = 0,
86242 + .todo_flags_start = 0,
86243 + .todo_flags_finish = TODO_dump_func
86244 + }
86245 +};
86246 +
86247 +static bool gate_stackleak_track_stack(void)
86248 +{
86249 + return track_frame_size >= 0;
86250 +}
86251 +
86252 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
86253 +{
86254 + gimple check_alloca;
86255 + tree fntype, fndecl, alloca_size;
86256 +
86257 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
86258 + fndecl = build_fn_decl(check_function, fntype);
86259 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
86260 +
86261 + // insert call to void pax_check_alloca(unsigned long size)
86262 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
86263 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
86264 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
86265 +}
86266 +
86267 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
86268 +{
86269 + gimple track_stack;
86270 + tree fntype, fndecl;
86271 +
86272 + fntype = build_function_type_list(void_type_node, NULL_TREE);
86273 + fndecl = build_fn_decl(track_function, fntype);
86274 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
86275 +
86276 + // insert call to void pax_track_stack(void)
86277 + track_stack = gimple_build_call(fndecl, 0);
86278 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
86279 +}
86280 +
86281 +#if BUILDING_GCC_VERSION == 4005
86282 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
86283 +{
86284 + tree fndecl;
86285 +
86286 + if (!is_gimple_call(stmt))
86287 + return false;
86288 + fndecl = gimple_call_fndecl(stmt);
86289 + if (!fndecl)
86290 + return false;
86291 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
86292 + return false;
86293 +// print_node(stderr, "pax", fndecl, 4);
86294 + return DECL_FUNCTION_CODE(fndecl) == code;
86295 +}
86296 +#endif
86297 +
86298 +static bool is_alloca(gimple stmt)
86299 +{
86300 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
86301 + return true;
86302 +
86303 +#if BUILDING_GCC_VERSION >= 4007
86304 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
86305 + return true;
86306 +#endif
86307 +
86308 + return false;
86309 +}
86310 +
86311 +static unsigned int execute_stackleak_tree_instrument(void)
86312 +{
86313 + basic_block bb, entry_bb;
86314 + bool prologue_instrumented = false, is_leaf = true;
86315 +
86316 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
86317 +
86318 + // 1. loop through BBs and GIMPLE statements
86319 + FOR_EACH_BB(bb) {
86320 + gimple_stmt_iterator gsi;
86321 +
86322 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86323 + gimple stmt;
86324 +
86325 + stmt = gsi_stmt(gsi);
86326 +
86327 + if (is_gimple_call(stmt))
86328 + is_leaf = false;
86329 +
86330 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
86331 + if (!is_alloca(stmt))
86332 + continue;
86333 +
86334 + // 2. insert stack overflow check before each __builtin_alloca call
86335 + stackleak_check_alloca(&gsi);
86336 +
86337 + // 3. insert track call after each __builtin_alloca call
86338 + stackleak_add_instrumentation(&gsi);
86339 + if (bb == entry_bb)
86340 + prologue_instrumented = true;
86341 + }
86342 + }
86343 +
86344 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
86345 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
86346 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
86347 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
86348 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
86349 + return 0;
86350 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
86351 + return 0;
86352 +
86353 + // 4. insert track call at the beginning
86354 + if (!prologue_instrumented) {
86355 + gimple_stmt_iterator gsi;
86356 +
86357 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
86358 + if (dom_info_available_p(CDI_DOMINATORS))
86359 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
86360 + gsi = gsi_start_bb(bb);
86361 + stackleak_add_instrumentation(&gsi);
86362 + }
86363 +
86364 + return 0;
86365 +}
86366 +
86367 +static unsigned int execute_stackleak_final(void)
86368 +{
86369 + rtx insn;
86370 +
86371 + if (cfun->calls_alloca)
86372 + return 0;
86373 +
86374 + // keep calls only if function frame is big enough
86375 + if (get_frame_size() >= track_frame_size)
86376 + return 0;
86377 +
86378 + // 1. find pax_track_stack calls
86379 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
86380 + // 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))
86381 + rtx body;
86382 +
86383 + if (!CALL_P(insn))
86384 + continue;
86385 + body = PATTERN(insn);
86386 + if (GET_CODE(body) != CALL)
86387 + continue;
86388 + body = XEXP(body, 0);
86389 + if (GET_CODE(body) != MEM)
86390 + continue;
86391 + body = XEXP(body, 0);
86392 + if (GET_CODE(body) != SYMBOL_REF)
86393 + continue;
86394 + if (strcmp(XSTR(body, 0), track_function))
86395 + continue;
86396 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
86397 + // 2. delete call
86398 + insn = delete_insn_and_edges(insn);
86399 +#if BUILDING_GCC_VERSION >= 4007
86400 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
86401 + insn = delete_insn_and_edges(insn);
86402 +#endif
86403 + }
86404 +
86405 +// print_simple_rtl(stderr, get_insns());
86406 +// print_rtl(stderr, get_insns());
86407 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
86408 +
86409 + return 0;
86410 +}
86411 +
86412 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86413 +{
86414 + const char * const plugin_name = plugin_info->base_name;
86415 + const int argc = plugin_info->argc;
86416 + const struct plugin_argument * const argv = plugin_info->argv;
86417 + int i;
86418 + struct register_pass_info stackleak_tree_instrument_pass_info = {
86419 + .pass = &stackleak_tree_instrument_pass.pass,
86420 +// .reference_pass_name = "tree_profile",
86421 + .reference_pass_name = "optimized",
86422 + .ref_pass_instance_number = 0,
86423 + .pos_op = PASS_POS_INSERT_BEFORE
86424 + };
86425 + struct register_pass_info stackleak_final_pass_info = {
86426 + .pass = &stackleak_final_rtl_opt_pass.pass,
86427 + .reference_pass_name = "final",
86428 + .ref_pass_instance_number = 0,
86429 + .pos_op = PASS_POS_INSERT_BEFORE
86430 + };
86431 +
86432 + if (!plugin_default_version_check(version, &gcc_version)) {
86433 + error(G_("incompatible gcc/plugin versions"));
86434 + return 1;
86435 + }
86436 +
86437 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
86438 +
86439 + for (i = 0; i < argc; ++i) {
86440 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
86441 + if (!argv[i].value) {
86442 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86443 + continue;
86444 + }
86445 + track_frame_size = atoi(argv[i].value);
86446 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
86447 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86448 + continue;
86449 + }
86450 + if (!strcmp(argv[i].key, "initialize-locals")) {
86451 + if (argv[i].value) {
86452 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86453 + continue;
86454 + }
86455 + init_locals = true;
86456 + continue;
86457 + }
86458 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86459 + }
86460 +
86461 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
86462 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
86463 +
86464 + return 0;
86465 +}
86466 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
86467 index 6789d78..4afd019 100644
86468 --- a/tools/perf/util/include/asm/alternative-asm.h
86469 +++ b/tools/perf/util/include/asm/alternative-asm.h
86470 @@ -5,4 +5,7 @@
86471
86472 #define altinstruction_entry #
86473
86474 + .macro pax_force_retaddr rip=0, reload=0
86475 + .endm
86476 +
86477 #endif
86478 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
86479 index af0f22f..9a7d479 100644
86480 --- a/usr/gen_init_cpio.c
86481 +++ b/usr/gen_init_cpio.c
86482 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
86483 int retval;
86484 int rc = -1;
86485 int namesize;
86486 - int i;
86487 + unsigned int i;
86488
86489 mode |= S_IFREG;
86490
86491 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
86492 *env_var = *expanded = '\0';
86493 strncat(env_var, start + 2, end - start - 2);
86494 strncat(expanded, new_location, start - new_location);
86495 - strncat(expanded, getenv(env_var), PATH_MAX);
86496 - strncat(expanded, end + 1, PATH_MAX);
86497 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
86498 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
86499 strncpy(new_location, expanded, PATH_MAX);
86500 + new_location[PATH_MAX] = 0;
86501 } else
86502 break;
86503 }
86504 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
86505 index c4ac57e..527711d 100644
86506 --- a/virt/kvm/kvm_main.c
86507 +++ b/virt/kvm/kvm_main.c
86508 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
86509
86510 static cpumask_var_t cpus_hardware_enabled;
86511 static int kvm_usage_count = 0;
86512 -static atomic_t hardware_enable_failed;
86513 +static atomic_unchecked_t hardware_enable_failed;
86514
86515 struct kmem_cache *kvm_vcpu_cache;
86516 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
86517 @@ -2313,7 +2313,7 @@ static void hardware_enable_nolock(void *junk)
86518
86519 if (r) {
86520 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
86521 - atomic_inc(&hardware_enable_failed);
86522 + atomic_inc_unchecked(&hardware_enable_failed);
86523 printk(KERN_INFO "kvm: enabling virtualization on "
86524 "CPU%d failed\n", cpu);
86525 }
86526 @@ -2367,10 +2367,10 @@ static int hardware_enable_all(void)
86527
86528 kvm_usage_count++;
86529 if (kvm_usage_count == 1) {
86530 - atomic_set(&hardware_enable_failed, 0);
86531 + atomic_set_unchecked(&hardware_enable_failed, 0);
86532 on_each_cpu(hardware_enable_nolock, NULL, 1);
86533
86534 - if (atomic_read(&hardware_enable_failed)) {
86535 + if (atomic_read_unchecked(&hardware_enable_failed)) {
86536 hardware_disable_all_nolock();
86537 r = -EBUSY;
86538 }
86539 @@ -2733,7 +2733,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
86540 kvm_arch_vcpu_put(vcpu);
86541 }
86542
86543 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86544 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86545 struct module *module)
86546 {
86547 int r;
86548 @@ -2796,7 +2796,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86549 if (!vcpu_align)
86550 vcpu_align = __alignof__(struct kvm_vcpu);
86551 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
86552 - 0, NULL);
86553 + SLAB_USERCOPY, NULL);
86554 if (!kvm_vcpu_cache) {
86555 r = -ENOMEM;
86556 goto out_free_3;
86557 @@ -2806,9 +2806,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86558 if (r)
86559 goto out_free;
86560
86561 - kvm_chardev_ops.owner = module;
86562 - kvm_vm_fops.owner = module;
86563 - kvm_vcpu_fops.owner = module;
86564 + pax_open_kernel();
86565 + *(void **)&kvm_chardev_ops.owner = module;
86566 + *(void **)&kvm_vm_fops.owner = module;
86567 + *(void **)&kvm_vcpu_fops.owner = module;
86568 + pax_close_kernel();
86569
86570 r = misc_register(&kvm_dev);
86571 if (r) {